Added check for required version properties.

Removed savedAfterProjectEvaluate option (no longer needed)
This commit is contained in:
Erik C. Thauvin 2018-12-20 13:05:51 -08:00
parent a0ddcae5f0
commit 2baf69cd32
2 changed files with 7 additions and 4 deletions

View file

@ -43,7 +43,6 @@ open class SemverConfig {
const val DEFAULT_BUILDMETA_KEY = "buildmeta"
const val DEFAULT_BUILDMETA_PREFIX_KEY = "buildmeta.prefix"
const val DEFAULT_SEPARATOR = "separator"
const val DEFAULT_SAVE_AFTER_PROJECT_EVALUATE = true
}
var properties = DEFAULT_PROPERTIES
@ -64,5 +63,4 @@ open class SemverConfig {
var separatorKey = DEFAULT_SEPARATOR
get() = "$keysPrefix$field"
var keysPrefix = DEFAULT_KEYS_PREFIX
var saveAfterProjectEvaluate = DEFAULT_SAVE_AFTER_PROJECT_EVALUATE
}

View file

@ -110,11 +110,15 @@ class SemverPlugin : Plugin<Project> {
propsFile.apply {
project.logger.info(
"[$simpleName] Attempting to read properties from: `$absoluteFile`. [exists: ${exists()}, isFile: $isFile, canRead: ${canRead()}]")
var hasReqProps = false
if (canRead() && isFile) {
FileInputStream(this).reader().use { reader ->
Properties().apply {
load(reader)
hasReqProps = stringPropertyNames().containsAll(setOf(config.majorKey, config.minorKey,
config.patchKey, config.preReleaseKey, config.buildMetaKey))
version.major = getProperty(config.majorKey, Version.DEFAULT_MAJOR)
version.minor = getProperty(config.minorKey, Version.DEFAULT_MINOR)
version.patch = getProperty(config.patchKey, Version.DEFAULT_PATCH)
@ -136,8 +140,9 @@ class SemverPlugin : Plugin<Project> {
}
project.version = version.semver
project.logger.info("[$simpleName] Project version set to: ${project.version}")
// If first time running and there is no props file, and saveAfterEvaluate is false, then version props would never have been saved before
if (config.saveAfterProjectEvaluate || !isFile) {
if (!hasReqProps || !isFile) {
// If first time running and there is no props file, and the required version properties are missing,
// then version props would never have been saved before
saveProperties(config, version)
}
}