Skip to content

Commit 0a15435

Browse files
committed
misc: clean up and system properties
1 parent 01cd410 commit 0a15435

File tree

1 file changed

+36
-38
lines changed
  • build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl

1 file changed

+36
-38
lines changed

build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ import org.gradle.plugins.signing.SigningExtension
1616
import org.jreleaser.gradle.plugin.JReleaserExtension
1717
import org.jreleaser.model.Active
1818

19-
// Props
20-
private const val SKIP_PUBLISH_PROP = "skipPublish"
21-
22-
// Env vars
23-
private const val J_RELEASER_STAGE_ENV_VAR = "JRELEASER_MAVENCENTRAL_STAGE"
24-
private const val J_RELEASER_GROUP_ENV_VAR = "JRELEASER_PROJECT_JAVA_GROUP_ID"
25-
private const val J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR = "JRELEASER_MAVENCENTRAL_USERNAME"
26-
private const val J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR = "JRELEASER_MAVENCENTRAL_TOKEN"
27-
private const val J_RELEASER_GPG_PASSPHRASE_ENV_VAR = "JRELEASER_GPG_PASSPHRASE"
28-
private const val J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR = "JRELEASER_GPG_PUBLIC_KEY"
29-
private const val J_RELEASER_GPG_SECRET_KEY_ENV_VAR = "JRELEASER_GPG_SECRET_KEY"
30-
31-
// Names of publications that are allowed to be published
32-
private val ALLOWED_PUBLICATIONS = listOf(
19+
private object SystemProperties {
20+
const val SKIP_PUBLISHING = "skipPublish"
21+
22+
object JReleaser {
23+
const val STAGE = "jreleaser.mavencentral.stage"
24+
const val GROUP_ID = "jreleaser.project.java.group.id"
25+
const val MAVEN_CENTRAL_USERNAME = "jreleaser.mavencentral.username"
26+
const val MAVEN_CENTRAL_TOKEN = "jreleaser.mavencentral.token"
27+
const val GPG_PASSPHRASE = "jreleaser.gpg.passphrase"
28+
const val GPG_PUBLIC_KEY = "jreleaser.gpg.public.key"
29+
const val GPG_SECRET_KEY = "jreleaser.gpg.secret.key"
30+
}
31+
}
32+
33+
private val ALLOWED_PUBLICATION_NAMES = setOf(
3334
"common",
3435
"jvm",
3536
"metadata",
@@ -52,7 +53,7 @@ private val ALLOWED_PUBLICATIONS = listOf(
5253
* Mark this project as excluded from publishing
5354
*/
5455
fun Project.skipPublishing() {
55-
extra.set(SKIP_PUBLISH_PROP, true)
56+
extra.set(SystemProperties.SKIP_PUBLISHING, true)
5657
}
5758

5859
/**
@@ -111,15 +112,12 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
111112
}
112113
}
113114

114-
val gpgSecretKey = System.getenv(J_RELEASER_GPG_SECRET_KEY_ENV_VAR)
115-
val gpgPassphrase = System.getenv(J_RELEASER_GPG_PASSPHRASE_ENV_VAR)
116-
117-
if (!gpgPassphrase.isNullOrBlank() && !gpgSecretKey.isNullOrBlank()) {
115+
if (project.hasProperty(SystemProperties.JReleaser.GPG_SECRET_KEY) && project.hasProperty(SystemProperties.JReleaser.GPG_PASSPHRASE)) {
118116
apply(plugin = "signing")
119117
extensions.configure<SigningExtension> {
120118
useInMemoryPgpKeys(
121-
gpgSecretKey,
122-
gpgPassphrase,
119+
project.property(SystemProperties.JReleaser.GPG_SECRET_KEY) as String,
120+
project.property(SystemProperties.JReleaser.GPG_PASSPHRASE) as String,
123121
)
124122
sign(publications)
125123
}
@@ -143,16 +141,16 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
143141
}
144142

145143
/*
146-
Creates a dummy JAR for version catalog publishing
147-
The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar to be present in the version catalog component
144+
Creates a dummy JAR for the version catalog
145+
The `version-catalog` plugin doesn't generate one because it isn't needed but JReleaser requires a jar for publishing
148146
https://docs.gradle.org/current/userguide/version_catalogs.html#sec:version-catalog-plugin
149147
150148
Consuming published version catalogs with the dummy JAR still work
151149
https://docs.gradle.org/current/userguide/version_catalogs.html#sec:importing-published-catalog
152150
*/
153151
tasks.register<Jar>("versionCatalogJar") {
154152
archiveBaseName.set("version-catalog")
155-
from("gradle/libs.versions.toml")
153+
from("gradle/libs.versions.toml") // Could be anything
156154
}
157155
}
158156

@@ -162,22 +160,22 @@ fun Project.configurePublishing(repoName: String, githubOrganization: String = "
162160
fun Project.configureJReleaser() {
163161
verifyRootProject { "JReleaser configuration must be applied to the root project only" }
164162

165-
var missingEnvVars = false
163+
var missingSystemProperties = false
166164
listOf(
167-
J_RELEASER_STAGE_ENV_VAR,
168-
J_RELEASER_GROUP_ENV_VAR,
169-
J_RELEASER_MAVEN_CENTRAL_USERNAME_ENV_VAR,
170-
J_RELEASER_MAVEN_CENTRAL_TOKEN_ENV_VAR,
171-
J_RELEASER_GPG_PASSPHRASE_ENV_VAR,
172-
J_RELEASER_GPG_PUBLIC_KEY_ENV_VAR,
173-
J_RELEASER_GPG_SECRET_KEY_ENV_VAR,
165+
SystemProperties.JReleaser.STAGE,
166+
SystemProperties.JReleaser.GROUP_ID,
167+
SystemProperties.JReleaser.MAVEN_CENTRAL_USERNAME,
168+
SystemProperties.JReleaser.MAVEN_CENTRAL_TOKEN,
169+
SystemProperties.JReleaser.GPG_PASSPHRASE,
170+
SystemProperties.JReleaser.GPG_PUBLIC_KEY,
171+
SystemProperties.JReleaser.GPG_SECRET_KEY,
174172
).forEach {
175-
if (System.getenv(it).isNullOrBlank()) {
176-
missingEnvVars = true
173+
if (!project.hasProperty(it)) {
174+
missingSystemProperties = true
177175
logger.warn("Skipping JReleaser configuration, missing or blank required env var: $it")
178176
}
179177
}
180-
if (missingEnvVars) return
178+
if (missingSystemProperties) return
181179

182180
// Get SDK version from gradle.properties
183181
val sdkVersion: String by project
@@ -209,14 +207,14 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic
209207
var shouldPublish = true
210208

211209
// Check SKIP_PUBLISH_PROP
212-
if (project.extra.has(SKIP_PUBLISH_PROP)) shouldPublish = false
210+
if (project.extra.has(SystemProperties.SKIP_PUBLISHING)) shouldPublish = false
213211

214212
// Validate publishGroupName
215-
val publishGroupName = System.getenv(J_RELEASER_GROUP_ENV_VAR)
213+
val publishGroupName = System.getenv(SystemProperties.JReleaser.GROUP_ID)
216214
shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))
217215

218216
// Validate publication name is allowed to be published
219-
shouldPublish = shouldPublish && ALLOWED_PUBLICATIONS.any { publication.name.equals(it, ignoreCase = true) }
217+
shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) }
220218

221219
return shouldPublish
222220
}

0 commit comments

Comments
 (0)