Fix properties loading on store.
This commit is contained in:
parent
d5dd895e47
commit
1bf7b7c86e
1 changed files with 21 additions and 5 deletions
|
@ -47,20 +47,36 @@ class SemverPlugin : Plugin<Project> {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun saveProperties(config: SemverConfig, version: Version) {
|
fun saveProperties(config: SemverConfig, version: Version) {
|
||||||
|
val propsFile = File(config.properties)
|
||||||
SortedProperties().apply {
|
SortedProperties().apply {
|
||||||
|
propsFile.apply {
|
||||||
|
if (canRead() && isFile) {
|
||||||
|
FileInputStream(this).reader().use { load(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
put(config.majorKey, version.major)
|
put(config.majorKey, version.major)
|
||||||
put(config.minorKey, version.minor)
|
put(config.minorKey, version.minor)
|
||||||
put(config.patchKey, version.patch)
|
put(config.patchKey, version.patch)
|
||||||
put(config.preReleaseKey, version.preRelease)
|
put(config.preReleaseKey, version.preRelease)
|
||||||
put(config.buildMetaKey, version.buildMeta)
|
put(config.buildMetaKey, version.buildMeta)
|
||||||
if (version.buildMetaPrefix != Version.DEFAULT_BUILDMETA_PREFIX)
|
if (version.buildMetaPrefix != Version.DEFAULT_BUILDMETA_PREFIX
|
||||||
|
|| containsKey(config.buildMetaPrefixKey))
|
||||||
put(config.buildMetaPrefixKey, version.buildMetaPrefix)
|
put(config.buildMetaPrefixKey, version.buildMetaPrefix)
|
||||||
if (version.preReleasePrefix != Version.DEFAULT_PRERELEASE_PREFIX)
|
if (version.preReleasePrefix != Version.DEFAULT_PRERELEASE_PREFIX
|
||||||
|
|| containsKey(config.preReleasePrefixKey))
|
||||||
put(config.preReleasePrefixKey, version.preReleasePrefix)
|
put(config.preReleasePrefixKey, version.preReleasePrefix)
|
||||||
if (version.separator != Version.DEFAULT_SEPARATOR)
|
if (version.separator != Version.DEFAULT_SEPARATOR || containsKey(config.separatorKey))
|
||||||
put(config.separatorKey, version.separator)
|
put(config.separatorKey, version.separator)
|
||||||
FileOutputStream(config.properties).writer().use { writer ->
|
|
||||||
store(writer, "Generated by the Semver Plugin for Gradle")
|
propsFile.apply {
|
||||||
|
if (canWrite()) {
|
||||||
|
FileOutputStream(this).writer().use {
|
||||||
|
store(it, "Generated by the Semver Plugin for Gradle")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw GradleException("Unable to write version to: `$absoluteFile`")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue