From 8618f8bae79f921c7431c58a1882c6a11873a565 Mon Sep 17 00:00:00 2001 From: Bengt Brodersen Date: Tue, 11 Feb 2020 22:56:19 +0100 Subject: [PATCH] feat: simplify property replacement configuration BREAKING CHANGE: simplify property replacement configuration --- README.md | 52 +++++++++++++++---- build.gradle | 2 +- .../GitVersioningPluginConfig.java | 20 +------ .../GitVersioningPluginExtension.java | 26 ++-------- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 8a62c58..a8b0aa5 100644 --- a/README.md +++ b/README.md @@ -115,9 +115,8 @@ gitVersioning.apply(closureOf { - `versionFormat` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders) - `property` A property definition to update the value of a property - `pattern` An arbitrary regex to match property names - - `value` The definition of the new property value - - `pattern` An arbitrary regex to match property values - - `format` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - `valueFormat` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - *optional* `valuePattern` An arbitrary regex to match and use capture group values of property value - ⚠ **considered if...** * HEAD attached to a branch `git checkout `
* Or branch name is provided by environment variable or command line parameter @@ -127,9 +126,8 @@ gitVersioning.apply(closureOf { - `versionFormat` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders) - `property` A property definition to update the value of a property - `pattern` An arbitrary regex to match property names - - `value` The definition of the new property value - - `pattern` An arbitrary regex to match property values - - `format` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - `valueFormat` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - *optional* `valuePattern` An arbitrary regex to match and use capture group values of property value - ⚠ **considered if...** * HEAD is detached `git checkout `
* Or tag name is provided by environment variable or command line parameter @@ -138,9 +136,8 @@ gitVersioning.apply(closureOf { - `versionFormat` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders) - `property` A property definition to update the value of a property - `pattern` An arbitrary regex to match property names - - `value` The definition of the new property value - - `pattern` An arbitrary regex to match property values - - `format` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - `valueFormat` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - *optional* `valuePattern` An arbitrary regex to match and use capture group values of property value - ⚠ **considered if...** * HEAD is detached `git checkout ` and no matching version tag is pointing to HEAD
@@ -272,6 +269,43 @@ fi ``` # Changelog + +## 3.0.0 +#### Features +* simplify `property` replacement configuration + +#### Breaking Changes +* simplify `property` replacement configuration + + new config + ```groovy + gitVersioning.apply { + branch { + pattern = 'master' + versionFormat = '${version}' + property { + pattern = 'revision' + valueFormat = '${branch-SNAPSHOT}' + } + } + } + ``` + old config + ```groovy + gitVersioning.apply { + branch { + pattern = 'master' + versionFormat = '${version}' + property { + pattern ='revision' + value { + format = '${branch-SNAPSHOT}' + } + } + } + } + ``` + ### 2.1.0 * add `${dirty}` flag version format placeholder * add `git.dirty` property diff --git a/build.gradle b/build.gradle index 81aa5e2..1d67100 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ plugins { } group 'me.qoomon' -version '2.1.1' +version '3.0.0' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java b/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java index 405cf76..64c4ef0 100644 --- a/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java +++ b/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java @@ -77,23 +77,7 @@ public void property(Closure closure) { public static class PropertyDescription { public String pattern; - public ValueDescription value; - - public void value(ValueDescription valueDescription) { - this.value = valueDescription; - } - - public void value(Closure closure) { - ValueDescription valueDescription = new ValueDescription(); - configure(closure, valueDescription); - value(valueDescription); - } - } - - public static class ValueDescription { - - public String pattern; - public String format; - + public String valueFormat; + public String valuePattern; } } diff --git a/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java b/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java index 355beb4..a2c8876 100644 --- a/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java +++ b/src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java @@ -96,20 +96,6 @@ public void apply(Closure closure) { apply(config); } - private String resolveOriginVersion(Project project, Map originVersionMap) { - String projectVersion = originVersionMap.get(project.getPath()).toString(); - if (!projectVersion.equals("unspecified")) { - return projectVersion; - } - - if (project.getParent() == null) { - return "unspecified"; - } - - return resolveOriginVersion(project.getParent(), originVersionMap); - - } - private Map getProjectStringProperties(Project project) { Map result = new HashMap<>(); for (Map.Entry entry : project.getProperties().entrySet()) { @@ -120,15 +106,11 @@ private Map getProjectStringProperties(Project project) { return result; } - private List mapPropertyDescription(List properties) { + private List mapPropertyDescription(List properties) { return properties.stream() - .map(it -> new me.qoomon.gitversioning.PropertyDescription(it.pattern, mapPropertyValueDescription(it.value)) - ).collect(toList()); - } - - private PropertyValueDescription mapPropertyValueDescription(GitVersioningPluginConfig.ValueDescription value) { - return Optional.of(value) - .map(it -> new PropertyValueDescription(it.pattern, it.format)).get(); + .map(prop -> new PropertyDescription( + prop.pattern, new PropertyValueDescription(prop.valuePattern, prop.valueFormat))) + .collect(toList()); } private static String getCommandOption(final Project project, final String name) {