Update to account for credentials and more constants.

This commit is contained in:
Pat Garrity 2024-03-17 10:21:17 -05:00
parent 4326a41117
commit 862405422d
Signed by: pfm
GPG key ID: 5CA5D21BAB7F3A76
4 changed files with 85 additions and 4 deletions

View file

@ -1 +1 @@
sbt.version=1.9.8
sbt.version=1.9.9

View file

@ -1 +1,24 @@
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
def selectCredentials(): Credentials =
if ((Path.userHome / ".sbt" / ".credentials").exists())
Credentials(Path.userHome / ".sbt" / ".credentials")
else
Credentials.apply(
realm = "Reposilite",
host = "maven.garrity.co",
userName = sys.env
.get("GS_MAVEN_USER")
.getOrElse(
throw new RuntimeException(
"You must either provide ~/.sbt/.credentials or specify the GS_MAVEN_USER environment variable."
)
),
passwd = sys.env
.get("GS_MAVEN_TOKEN")
.getOrElse(
throw new RuntimeException(
"You must either provide ~/.sbt/.credentials or specify the GS_MAVEN_TOKEN environment variable."
)
)
)
credentials += selectCredentials()

View file

@ -34,11 +34,31 @@ object Gs {
*/
val GitHost: String = "git.garrity.co"
/**
* Host of the Maven server.
*/
val MavenHost: String = "maven.garrity.co"
/**
* Realm of the Maven server.
*/
val MavenRealm: String = "Reposilite"
/**
* Organization name used to organize projects in Git.
*/
val GitOrganization: String = "garrity-software"
/**
* Human readable organization name.
*/
val OrganizationName: String = "Garrity Software"
/**
* Maven Group ID for GS projects.
*/
val GroupId: String = "gs"
/**
* Calculate the Git repository for a project.
*
@ -56,4 +76,9 @@ object Gs {
*/
def gitSsh(projectName: String): String =
s"git@$GitHost:$GitOrganization/${projectName}.git"
object Environment {
val MavenUser: String = "GS_MAVEN_USER"
val MavenToken: String = "GS_MAVEN_TOKEN"
}
}

View file

@ -10,7 +10,40 @@ object GsPlugin extends AutoPlugin {
import autoImport._
/**
* Prefers to load credentials from file, if a file is available. Otherwise
* mandates that the following environment variables exist:
*
* - `GS_MAVEN_USER`
* - `GS_MAVEN_TOKEN`
*
* @return The selected credentials for GS Maven.
*/
def selectCredentials(): Credentials =
if ((Path.userHome / ".sbt" / ".credentials").exists())
Credentials(Path.userHome / ".sbt" / ".credentials")
else
Credentials.apply(
realm =Gs.MavenRealm,
host = Gs.MavenHost,
userName = sys.env
.get(Gs.Environment.MavenUser)
.getOrElse(
throw new RuntimeException(
s"You must either provide ~/.sbt/.credentials or specify the ${Gs.Environment.MavenUser} environment variable."
)
),
passwd = sys.env
.get(Gs.Environment.MavenToken)
.getOrElse(
throw new RuntimeException(
s"You must either provide ~/.sbt/.credentials or specify the ${Gs.Environment.MavenToken} environment variable."
)
)
)
override def projectSettings: Seq[Setting[_]] = Seq(
credentials += selectCredentials(),
publishMavenStyle := true,
Test / Keys.publishArtifact := false,
pomIncludeRepository := Function.const(false),
@ -22,8 +55,8 @@ object GsPlugin extends AutoPlugin {
),
licenses := List(Gs.Apache2),
homepage := Some(url(Gs.gitRepo(gsProjectName.value))),
organizationName := "garrity software",
organization := "gs",
organizationName := Gs.OrganizationName,
organization := Gs.GroupId,
organizationHomepage := Some(url("https://garrity.co/")),
publishTo := {
val repo = "https://maven.garrity.co/"