From 16d1a06571b11f51d60c2f148ba293a6ba3edbdc Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 10 Apr 2019 10:42:39 -0700 Subject: [PATCH] Added the ability to specify the version via the command line. --- examples/test/build.gradle | 14 ++-------- .../erik/gradle/semver/SemverPlugin.kt | 26 ++++++++++++++----- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/test/build.gradle b/examples/test/build.gradle index 02d7779..b982333 100644 --- a/examples/test/build.gradle +++ b/examples/test/build.gradle @@ -8,7 +8,7 @@ buildscript { mavenLocal() } dependencies { - classpath "net.thauvin.erik.gradle:semver:0.9.9-beta" + classpath "net.thauvin.erik.gradle:semver:1.0.0" } } @@ -20,7 +20,7 @@ mainClassName = 'App' version = 1.0 -def f = new File("test.properties") +def f = new File("version.properties") dependencies { @@ -30,15 +30,6 @@ repositories { jcenter() } -clean { - delete fileTree(dir: "$projectDir", include: "*.properties") -} - -incrementPatch { - doFirst { - println("[Gradle] exists: " + f.exists() + ", canRead: " + f.canRead()) - } -} incrementBuildMeta { doFirst { @@ -48,7 +39,6 @@ incrementBuildMeta { } run { - //dependsOn("incrementPatch") doFirst { println("Version: $version") args = [f.name] diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt index 9798018..0adb8dc 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverPlugin.kt @@ -116,16 +116,17 @@ class SemverPlugin : Plugin { Properties().apply { load(reader) - hasReqProps = stringPropertyNames().containsAll(setOf(config.majorKey, config.minorKey, - config.patchKey, config.preReleaseKey, config.buildMetaKey)) + val requiredProps = setOf(config.majorKey, config.minorKey, config.patchKey, + config.preReleaseKey, config.buildMetaKey) + hasReqProps = stringPropertyNames().containsAll(requiredProps) && !hasEnv(requiredProps) - version.major = getProperty(config.majorKey, Version.DEFAULT_MAJOR) - version.minor = getProperty(config.minorKey, Version.DEFAULT_MINOR) - version.patch = getProperty(config.patchKey, Version.DEFAULT_PATCH) - version.preRelease = getProperty(config.preReleaseKey, Version.DEFAULT_EMPTY) + version.major = loadProperty(this, config.majorKey, Version.DEFAULT_MAJOR) + version.minor = loadProperty(this, config.minorKey, Version.DEFAULT_MINOR) + version.patch = loadProperty(this, config.patchKey, Version.DEFAULT_PATCH) + version.preRelease = loadProperty(this, config.preReleaseKey, Version.DEFAULT_EMPTY) version.preReleasePrefix = getProperty(config.preReleasePrefixKey, Version.DEFAULT_PRERELEASE_PREFIX) - version.buildMeta = getProperty(config.buildMetaKey, Version.DEFAULT_EMPTY) + version.buildMeta = loadProperty(this, config.buildMetaKey, Version.DEFAULT_EMPTY) version.buildMetaPrefix = getProperty(config.buildMetaPrefixKey, Version.DEFAULT_BUILDMETA_PREFIX) version.separator = getProperty(config.separatorKey, Version.DEFAULT_SEPARATOR) @@ -147,4 +148,15 @@ class SemverPlugin : Plugin { } } } + + private fun hasEnv(keys: Set): Boolean { + keys.forEach { + if (System.getProperties().containsKey(it)) return true + } + return false + } + + private fun loadProperty(props: Properties, key: String, default: String): String { + return System.getProperty(key, props.getProperty(key, default)) + } }