Skip to content

Commit 8618f8b

Browse files
committed
feat: simplify property replacement configuration
BREAKING CHANGE: simplify property replacement configuration
1 parent 4518809 commit 8618f8b

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

README.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@ gitVersioning.apply(closureOf<GitVersioningPluginConfig> {
115115
- `versionFormat` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders)
116116
- `property` A property definition to update the value of a property
117117
- `pattern` An arbitrary regex to match property names
118-
- `value` The definition of the new property value
119-
- `pattern` An arbitrary regex to match property values
120-
- `format` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders)
118+
- `valueFormat` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders)
119+
- *optional* `valuePattern` An arbitrary regex to match and use capture group values of property value
121120
-**considered if...**
122121
* HEAD attached to a branch `git checkout <BRANCH>`<br>
123122
* Or branch name is provided by environment variable or command line parameter
@@ -127,9 +126,8 @@ gitVersioning.apply(closureOf<GitVersioningPluginConfig> {
127126
- `versionFormat` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders)
128127
- `property` A property definition to update the value of a property
129128
- `pattern` An arbitrary regex to match property names
130-
- `value` The definition of the new property value
131-
- `pattern` An arbitrary regex to match property values
132-
- `format` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders)
129+
- `valueFormat` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders)
130+
- *optional* `valuePattern` An arbitrary regex to match and use capture group values of property value
133131
-**considered if...**
134132
* HEAD is detached `git checkout <TAG>`<br>
135133
* Or tag name is provided by environment variable or command line parameter
@@ -138,9 +136,8 @@ gitVersioning.apply(closureOf<GitVersioningPluginConfig> {
138136
- `versionFormat` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders)
139137
- `property` A property definition to update the value of a property
140138
- `pattern` An arbitrary regex to match property names
141-
- `value` The definition of the new property value
142-
- `pattern` An arbitrary regex to match property values
143-
- `format` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders)
139+
- `valueFormat` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders)
140+
- *optional* `valuePattern` An arbitrary regex to match and use capture group values of property value
144141
-**considered if...**
145142
* HEAD is detached `git checkout <COMMIT>` and no matching version tag is pointing to HEAD<br>
146143

@@ -272,6 +269,43 @@ fi
272269
```
273270

274271
# Changelog
272+
273+
## 3.0.0
274+
#### Features
275+
* simplify `property` replacement configuration
276+
277+
#### Breaking Changes
278+
* simplify `property` replacement configuration
279+
280+
new config
281+
```groovy
282+
gitVersioning.apply {
283+
branch {
284+
pattern = 'master'
285+
versionFormat = '${version}'
286+
property {
287+
pattern = 'revision'
288+
valueFormat = '${branch-SNAPSHOT}'
289+
}
290+
}
291+
}
292+
```
293+
old config
294+
```groovy
295+
gitVersioning.apply {
296+
branch {
297+
pattern = 'master'
298+
versionFormat = '${version}'
299+
property {
300+
pattern ='revision'
301+
value {
302+
format = '${branch-SNAPSHOT}'
303+
}
304+
}
305+
}
306+
}
307+
```
308+
275309
### 2.1.0
276310
* add `${dirty}` flag version format placeholder
277311
* add `git.dirty` property

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group 'me.qoomon'
15-
version '2.1.1'
15+
version '3.0.0'
1616

1717
sourceCompatibility = JavaVersion.VERSION_1_8
1818
targetCompatibility = JavaVersion.VERSION_1_8

src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginConfig.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,7 @@ public void property(Closure<?> closure) {
7777
public static class PropertyDescription {
7878

7979
public String pattern;
80-
public ValueDescription value;
81-
82-
public void value(ValueDescription valueDescription) {
83-
this.value = valueDescription;
84-
}
85-
86-
public void value(Closure<?> closure) {
87-
ValueDescription valueDescription = new ValueDescription();
88-
configure(closure, valueDescription);
89-
value(valueDescription);
90-
}
91-
}
92-
93-
public static class ValueDescription {
94-
95-
public String pattern;
96-
public String format;
97-
80+
public String valueFormat;
81+
public String valuePattern;
9882
}
9983
}

src/main/java/me/qoomon/gradle/gitversioning/GitVersioningPluginExtension.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,6 @@ public void apply(Closure<?> closure) {
9696
apply(config);
9797
}
9898

99-
private String resolveOriginVersion(Project project, Map<String, Object> originVersionMap) {
100-
String projectVersion = originVersionMap.get(project.getPath()).toString();
101-
if (!projectVersion.equals("unspecified")) {
102-
return projectVersion;
103-
}
104-
105-
if (project.getParent() == null) {
106-
return "unspecified";
107-
}
108-
109-
return resolveOriginVersion(project.getParent(), originVersionMap);
110-
111-
}
112-
11399
private Map<String, String> getProjectStringProperties(Project project) {
114100
Map<String, String> result = new HashMap<>();
115101
for (Map.Entry<String, ?> entry : project.getProperties().entrySet()) {
@@ -120,15 +106,11 @@ private Map<String, String> getProjectStringProperties(Project project) {
120106
return result;
121107
}
122108

123-
private List<me.qoomon.gitversioning.PropertyDescription> mapPropertyDescription(List<GitVersioningPluginConfig.PropertyDescription> properties) {
109+
private List<PropertyDescription> mapPropertyDescription(List<GitVersioningPluginConfig.PropertyDescription> properties) {
124110
return properties.stream()
125-
.map(it -> new me.qoomon.gitversioning.PropertyDescription(it.pattern, mapPropertyValueDescription(it.value))
126-
).collect(toList());
127-
}
128-
129-
private PropertyValueDescription mapPropertyValueDescription(GitVersioningPluginConfig.ValueDescription value) {
130-
return Optional.of(value)
131-
.map(it -> new PropertyValueDescription(it.pattern, it.format)).get();
111+
.map(prop -> new PropertyDescription(
112+
prop.pattern, new PropertyValueDescription(prop.valuePattern, prop.valueFormat)))
113+
.collect(toList());
132114
}
133115

134116
private static String getCommandOption(final Project project, final String name) {

0 commit comments

Comments
 (0)