Added the ability to specify the version via the command line.

This commit is contained in:
Erik C. Thauvin 2019-04-10 10:42:39 -07:00
parent 8d423a506a
commit 16d1a06571
2 changed files with 21 additions and 19 deletions

View file

@ -116,16 +116,17 @@ class SemverPlugin : Plugin<Project> {
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<Project> {
}
}
}
private fun hasEnv(keys: Set<String>): 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))
}
}