diff --git a/.idea/modules/semver_main.iml b/.idea/modules/semver_main.iml
index e6ba4e2..627a0ff 100644
--- a/.idea/modules/semver_main.iml
+++ b/.idea/modules/semver_main.iml
@@ -39,7 +39,7 @@
-
+
@@ -48,81 +48,28 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -134,23 +81,10 @@
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -159,7 +93,7 @@
-
+
@@ -168,17 +102,75 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -187,7 +179,7 @@
-
+
@@ -196,7 +188,7 @@
-
+
@@ -205,7 +197,7 @@
-
+
@@ -214,96 +206,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/.idea/modules/semver_test.iml b/.idea/modules/semver_test.iml
index 4269407..e8d6f19 100644
--- a/.idea/modules/semver_test.iml
+++ b/.idea/modules/semver_test.iml
@@ -36,6 +36,15 @@
+
+
+
+
+
+
+
+
+
@@ -116,16 +125,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -144,8 +143,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
@@ -155,144 +226,20 @@
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 4e74f31..e5ed78b 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,8 @@
A [Semantic Version](https://semver.org) Plugin for [Gradle](https://gradle.org) that manages a project version via a properties file, and provide tasks to __automatically increment__ major, minor and patch build numbers.
+The plugin can be used in conjunction with the [Semantic Version Annotation Processor](https://github.com/ethauvin/semver).
+
## Using the plugin
The plugin is published to the Plugin Portal; see instructions there: [net.thauvin.erik.gradle.semver](https://plugins.gradle.org/plugin/net.thauvin.erik.gradle.semver)
@@ -27,7 +29,7 @@ If you need to change some of the property file or name of the properties key to
## Increment Version Tasks
-The `incrementMajor`, `incrementMinor` and `incrementPatch` are available to automatically increment their respective and reset lower counterpart version numbers.
+The `incrementMajor`, `incrementMinor` and `incrementPatch` tasks are available to automatically increment their respective and reset lower counterpart version numbers.
- `incrementMajor` will increment the `major` and set the `minor` and `patch` versions to `0`.
- `incrementMinor` will increment the `minor` and set the path version to `0`.
@@ -49,7 +51,7 @@ someTask {
## Configuration
-### Version Properties
+### Version File Properties
The following default properties are recognized:
@@ -83,9 +85,9 @@ version.buildMeta=exp.sha.5114f85
`projet.version` will be `1.0.0-beta+exp.sha.5114f85` in Gradle.
-### Semver Task
+### Semver
-The `semver` task is used to configure how the plugin will read/write the version properties file. It most cases it is not needed.
+In a Gradle build file, the `semver` block is used to configure how the plugin will read/write the version properties file. In most cases it is not needed.
But, for example, if you wanted to save the version properties in a different file:
@@ -99,10 +101,11 @@ or using different property keys for the version data:
```gradle
semver {
- majorKey = "major" // instead of the default version.major
+ keysPrefix = "" // no prefix
+ majorKey = "major"
minorKey = "minor"
patchKey = "patch"
- preReleaseKey = "release"
+ preReleaseKey = "prerelease"
buildMetaKey = "metadata"
}
```
@@ -113,24 +116,43 @@ which would match the data in `my.version`:
major=1
minor=0
patch=0
-release=beta
+prerelease=beta
metadata=
```
-The following task properties are available:
+The following `semver` properties are available:
-Properties | Description | Default
-:---------------------|:----------------------------------------|:-------------------------
+Property | Description | Default
+:---------------------|:----------------------------------------|:------------------------
`properties` | The properties file. | `version.properties`
-`majorKey` | The major property key. | `version.major`
-`minorKey` | The minor property key. | `version.minor`
-`patchKey` | The patch property key. | `version.patch`
-`preReleaseKey` | The pre-release property key. | `version.preRelease`
-`preReleasePrefixKey` | The build pre-release prefix key. | `version.preReleasePrefix`
-`buildMetaKey` | The build metadata property key. | `version.buildMeta`
-`buildMetaPrefixKey` | The build metadata prefix property key. | `version.buildMetaPrefix`
-`separatorKey` | The separator property key. | `version.separator`
+`majorKey` | The major property key. | `major`
+`minorKey` | The minor property key. | `minor`
+`patchKey` | The patch property key. | `patch`
+`preReleaseKey` | The pre-release property key. | `preRelease`
+`preReleasePrefixKey` | The build pre-release prefix key. | `preReleasePrefix`
+`buildMetaKey` | The build metadata property key. | `buildMeta`
+`buildMetaPrefixKey` | The build metadata prefix property key. | `buildMetaPrefix`
+`separatorKey` | The separator property key. | `separator`
+`keysPrefix` | The prefix for all property keys. | `version.`
+
+In order to quickly support multiple projects. The `keysPrefix` property is available to set all properties keys prefixes at once:
+
+```gradle
+semver {
+ properties = "test.properties"
+ keysPrefix = "test."
+}
+```
+
+```ini
+#test.properties
+test.major=1
+test.minor=0
+test.patch=0
+test.preRelease=
+test.buildMeta=
+```
## Source Code Generation
-If you'd like to incorporate the version number data into your source code, please have a look at my [Semantic Version Annotation Processor](https://github.com/ethauvin/semver).
\ No newline at end of file
+If you'd like to incorporate the version number data into your source code, please have a look at the [Semantic Version Annotation Processor](https://github.com/ethauvin/semver).
\ No newline at end of file
diff --git a/examples/test/build.gradle b/examples/test/build.gradle
index 1f838e8..0b19545 100644
--- a/examples/test/build.gradle
+++ b/examples/test/build.gradle
@@ -3,7 +3,7 @@ buildscript {
mavenLocal()
}
dependencies {
- classpath "net.thauvin.erik.gradle:semver:0.9.1"
+ classpath "net.thauvin.erik.gradle:semver:0.9.1-beta"
}
}
@@ -32,6 +32,6 @@ run {
semver {
properties = "test.properties"
- setKeysPrefix("test.")
- buildMetaKey = "another"
+ keysPrefix = "test."
+ buildMetaKey = "meta"
}
\ No newline at end of file
diff --git a/examples/test/test.properties b/examples/test/test.properties
index 49ccd0f..0a6f335 100644
--- a/examples/test/test.properties
+++ b/examples/test/test.properties
@@ -1,7 +1,7 @@
#Generated by the Semver Plugin for Gradle
-#Fri Jun 29 20:53:42 PDT 2018
+#Sat Jun 30 15:54:02 PDT 2018
test.major=1
-test.prerelease=
-test.patch=2
-another=
+test.prerelease=beta
+test.meta=007
+test.patch=3
test.minor=0
diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt
index 2b37e8b..6da6279 100644
--- a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt
+++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt
@@ -33,39 +33,34 @@ package net.thauvin.erik.gradle.semver
open class SemverConfig {
companion object {
- const val DEFAULT_KEY_PREFIX = "version."
- const val DEFAULT_PROPERTIES = "${DEFAULT_KEY_PREFIX}properties"
- const val DEFAULT_MAJOR_KEY = "${DEFAULT_KEY_PREFIX}major"
- const val DEFAULT_MINOR_KEY = "${DEFAULT_KEY_PREFIX}minor"
- const val DEFAULT_PATCH_KEY = "${DEFAULT_KEY_PREFIX}patch"
- const val DEFAULT_PRERELEASE_KEY = "${DEFAULT_KEY_PREFIX}prerelease"
- const val DEFAULT_PRERELEASE_PREFIX_KEY = "${DEFAULT_KEY_PREFIX}prerelease.prefix"
- const val DEFAULT_BUILDMETA_KEY = "${DEFAULT_KEY_PREFIX}buildmeta"
- const val DEFAULT_BUILDMETA_PREFIX_KEY = "${DEFAULT_KEY_PREFIX}buildmeta.prefix"
- const val DEFAULT_SEPARATOR = "${DEFAULT_KEY_PREFIX}separator"
+ const val DEFAULT_KEYS_PREFIX = "version."
+ const val DEFAULT_PROPERTIES = "properties"
+ const val DEFAULT_MAJOR_KEY = "major"
+ const val DEFAULT_MINOR_KEY = "minor"
+ const val DEFAULT_PATCH_KEY = "patch"
+ const val DEFAULT_PRERELEASE_KEY = "prerelease"
+ const val DEFAULT_PRERELEASE_PREFIX_KEY = "prerelease.prefix"
+ const val DEFAULT_BUILDMETA_KEY = "buildmeta"
+ const val DEFAULT_BUILDMETA_PREFIX_KEY = "buildmeta.prefix"
+ const val DEFAULT_SEPARATOR = "separator"
}
var properties = DEFAULT_PROPERTIES
var majorKey = DEFAULT_MAJOR_KEY
+ get() = "$keysPrefix$field"
var minorKey = DEFAULT_MINOR_KEY
+ get() = "$keysPrefix$field"
var patchKey = DEFAULT_PATCH_KEY
+ get() = "$keysPrefix$field"
var preReleaseKey = DEFAULT_PRERELEASE_KEY
+ get() = "$keysPrefix$field"
var preReleasePrefixKey = DEFAULT_PRERELEASE_PREFIX_KEY
+ get() = "$keysPrefix$field"
var buildMetaKey = DEFAULT_BUILDMETA_KEY
+ get() = "$keysPrefix$field"
var buildMetaPrefixKey = DEFAULT_BUILDMETA_PREFIX_KEY
+ get() = "$keysPrefix$field"
var separatorKey = DEFAULT_SEPARATOR
-
- @Suppress("unused")
- fun setKeysPrefix(keyPrefix: String) {
- if (keyPrefix.isNotBlank()) {
- majorKey = keyPrefix + majorKey.removePrefix(DEFAULT_KEY_PREFIX)
- minorKey = keyPrefix + minorKey.removePrefix(DEFAULT_KEY_PREFIX)
- patchKey = keyPrefix + patchKey.removePrefix(DEFAULT_KEY_PREFIX)
- preReleaseKey = keyPrefix + preReleaseKey.removePrefix(DEFAULT_KEY_PREFIX)
- preReleasePrefixKey = keyPrefix + preReleasePrefixKey.removePrefix(DEFAULT_KEY_PREFIX)
- buildMetaKey = keyPrefix + buildMetaKey.removePrefix(DEFAULT_KEY_PREFIX)
- buildMetaPrefixKey = keyPrefix + buildMetaPrefixKey.removePrefix(DEFAULT_KEY_PREFIX)
- separatorKey = keyPrefix + separatorKey.removePrefix(DEFAULT_KEY_PREFIX)
- }
- }
+ get() = "$keysPrefix$field"
+ var keysPrefix = DEFAULT_KEYS_PREFIX
}
\ No newline at end of file
diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt
index 4ea077c..c862f9b 100644
--- a/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt
+++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt
@@ -59,12 +59,12 @@ class Version {
fun increment(isMajor: Boolean = false, isMinor: Boolean = false, isPatch: Boolean = false) {
if (isMajor) {
major = (major.toInt() + 1).toString()
- minor = "0"
- patch = "0"
+ minor = DEFAULT_MINOR
+ patch = DEFAULT_PATCH
}
if (isMinor) {
minor = (minor.toInt() + 1).toString()
- patch = "0"
+ patch = DEFAULT_PATCH
}
if (isPatch) patch = (patch.toInt() + 1).toString()
}
diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt
index 7fa5cee..ef3210c 100644
--- a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt
+++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt
@@ -44,7 +44,6 @@ object SemverConfigSpec : Spek({
given("a config") {
val config = SemverConfig()
val vars = listOf(
- config.properties,
config.majorKey,
config.minorKey,
config.patchKey,
@@ -55,7 +54,6 @@ object SemverConfigSpec : Spek({
config.separatorKey
)
val defaults = listOf(
- SemverConfig.DEFAULT_PROPERTIES,
SemverConfig.DEFAULT_MAJOR_KEY,
SemverConfig.DEFAULT_MINOR_KEY,
SemverConfig.DEFAULT_PATCH_KEY,
@@ -67,13 +65,13 @@ object SemverConfigSpec : Spek({
)
on("defaults") {
defaults.forEachIndexed { i, d ->
- it("should be the same: ${vars[i]}, $d") {
- assertTrue(vars[i] == d)
+ it("should be the same: ${vars[i]}, ${config.keysPrefix}$d") {
+ assertTrue(vars[i] == "${config.keysPrefix}$d")
}
}
}
on("set keys to test.xxx") {
- config.setKeysPrefix("test.")
+ config.keysPrefix = "test."
val keys = listOf(
config.majorKey,
config.minorKey,