Skip to content

Commit

Permalink
feat: simplify property replacement configuration
Browse files Browse the repository at this point in the history
BREAKING CHANGE: simplify property replacement configuration
  • Loading branch information
qoomon committed Feb 11, 2020
1 parent 4518809 commit 8618f8b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 50 deletions.
52 changes: 43 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ gitVersioning.apply(closureOf<GitVersioningPluginConfig> {
- `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 <BRANCH>`<br>
* Or branch name is provided by environment variable or command line parameter
Expand All @@ -127,9 +126,8 @@ gitVersioning.apply(closureOf<GitVersioningPluginConfig> {
- `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 <TAG>`<br>
* Or tag name is provided by environment variable or command line parameter
Expand All @@ -138,9 +136,8 @@ gitVersioning.apply(closureOf<GitVersioningPluginConfig> {
- `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 <COMMIT>` and no matching version tag is pointing to HEAD<br>

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,6 @@ public void apply(Closure<?> closure) {
apply(config);
}

private String resolveOriginVersion(Project project, Map<String, Object> 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<String, String> getProjectStringProperties(Project project) {
Map<String, String> result = new HashMap<>();
for (Map.Entry<String, ?> entry : project.getProperties().entrySet()) {
Expand All @@ -120,15 +106,11 @@ private Map<String, String> getProjectStringProperties(Project project) {
return result;
}

private List<me.qoomon.gitversioning.PropertyDescription> mapPropertyDescription(List<GitVersioningPluginConfig.PropertyDescription> properties) {
private List<PropertyDescription> mapPropertyDescription(List<GitVersioningPluginConfig.PropertyDescription> 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) {
Expand Down

0 comments on commit 8618f8b

Please sign in to comment.