From 862405422d5df6b3851d715078f60dec726828a1 Mon Sep 17 00:00:00 2001 From: Pat Garrity Date: Sun, 17 Mar 2024 10:21:17 -0500 Subject: [PATCH] Update to account for credentials and more constants. --- project/build.properties | 2 +- project/plugins.sbt | 25 ++++++++++++++++++++- src/main/scala/gs/Gs.scala | 25 +++++++++++++++++++++ src/main/scala/gs/GsPlugin.scala | 37 ++++++++++++++++++++++++++++++-- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/project/build.properties b/project/build.properties index abbbce5..04267b1 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.8 +sbt.version=1.9.9 diff --git a/project/plugins.sbt b/project/plugins.sbt index 291bb34..01221f6 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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() diff --git a/src/main/scala/gs/Gs.scala b/src/main/scala/gs/Gs.scala index c17c553..d292f0f 100644 --- a/src/main/scala/gs/Gs.scala +++ b/src/main/scala/gs/Gs.scala @@ -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" + } } diff --git a/src/main/scala/gs/GsPlugin.scala b/src/main/scala/gs/GsPlugin.scala index 80c2195..73a0014 100644 --- a/src/main/scala/gs/GsPlugin.scala +++ b/src/main/scala/gs/GsPlugin.scala @@ -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/"