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
Bengt Brodersen committed Feb 9, 2020
1 parent 778177f commit 2e8be22
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 59 deletions.
50 changes: 41 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ Create `${basedir}/.mvn/maven-git-versioning-extension.xml`.
- `<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
- *optional* `<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
- *optional* `<updatePom>` Enable(`true`) or disable(`false`) version update in original pom fill (will override global `<updatePom>` value)
-**considered if...**
* HEAD attached to a branch `git checkout <BRANCH>`<br>
Expand All @@ -91,9 +90,8 @@ Create `${basedir}/.mvn/maven-git-versioning-extension.xml`.
- `<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
- *optional* `<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
- *optional* `<updatePom>` Enable(`true`) or disable(`false`) version update in original pom fill (will override global `<updatePom>` value)
-**considered if...**
* HEAD is detached `git checkout <TAG>`<br>
Expand All @@ -103,9 +101,8 @@ Create `${basedir}/.mvn/maven-git-versioning-extension.xml`.
- `<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
- *optional* `<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 @@ -254,6 +251,41 @@ fi

# Changelog

## 5.0.0
*

### Breaking Changes
* simplify <property> replacement configuration

new config
```xml
<gitVersioning>
<branch>
<pattern>master</pattern>
<versionFormat>${version}</versionFormat>
<property>
<pattern>revision</pattern>
<valueFormat>${branch-SNAPSHOT}</valueFormat>
</property>
</branch>
</gitVersioning>
```
old config
```xml
<gitVersioning>
<branch>
<pattern>master</pattern>
<versionFormat>${version}</versionFormat>
<property>
<pattern>revision</pattern>
<value>
<format>${branch-SNAPSHOT}</format>
</value>
</property>
</branch>
</gitVersioning>
```

## 4.10.2
* fix verbose logging when disabling extension by flag
* restrict project versioning to root- and sub-projects
Expand Down
10 changes: 2 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>me.qoomon</groupId>
<artifactId>maven-git-versioning-extension</artifactId>
<version>4.10.2</version>
<version>5.0.0</version>

<packaging>maven-plugin</packaging>

Expand Down Expand Up @@ -75,16 +75,10 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.6.2</version>
<version>3.6.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.2</version>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public static class CommitVersionDescription {
public static class PropertyDescription {

public String pattern;
public PropertyValueDescription value;
}

public static class PropertyValueDescription {

public String pattern;
public String format;
public String valueFormat;
public String valuePattern;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ private Model processModel(Model projectModel) throws IOException {
}
}
}

// TODO
// update version within dependencies, dependency management, plugins, plugin management

logger.info("");

virtualProjectModel.addProperty("git.commit", gitVersionDetails.getCommit());
Expand Down Expand Up @@ -261,7 +265,7 @@ private List<PropertyDescription> convertPropertyDescription(
List<Configuration.PropertyDescription> confPropertyDescription) {
return confPropertyDescription.stream()
.map(prop -> new PropertyDescription(
prop.pattern, new PropertyValueDescription(prop.value.pattern, prop.value.format)))
prop.pattern, new PropertyValueDescription(prop.valuePattern, prop.valueFormat)))
.collect(toList());
}

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/me/qoomon/maven/gitversioning/VersioningMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,22 @@ public synchronized void execute() throws MojoExecutionException {
versionElement.setText(project.getVersion());
}

Element parentElement = projectElement.getChild("parent");
if (parentElement != null) {
Element parentVersionElement = parentElement.getChild("version");
parentVersionElement.setText(project.getParent().getVersion());
}

Element propertiesElement = projectElement.getChild("properties");
if(propertiesElement != null){
for (final Element propertyElement : propertiesElement.getChildren()) {
propertyElement.setText(project.getOriginalModel().getProperties().getProperty(propertyElement.getName()));
}
}

// TODO
// update version within dependencies, dependency management, plugins, plugin management

Element parentElement = projectElement.getChild("parent");
if (parentElement != null) {
Element parentVersionElement = parentElement.getChild("version");
parentVersionElement.setText(project.getParent().getVersion());
}

File gitVersionedPomFile = new File(project.getBuild().getDirectory(), GIT_VERSIONING_POM_NAME);
Files.createDirectories(gitVersionedPomFile.getParentFile().toPath());
writeXml(gitVersionedPomFile, gitVersionedPomDocument);
Expand Down
30 changes: 12 additions & 18 deletions src/test/java/me/qoomon/maven/gitversioning/ConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,28 +100,22 @@ void xmlUnmarshaller_branchConfigsOnlyWithProperties() throws IOException {
" <versionFormat>branch1-format</versionFormat>\n" +
" <property>\n" +
" <pattern>my.property</pattern>\n" +
" <value>\n" +
" <pattern>my.property.pattern</pattern>\n" +
" <format>my.property.format</format>\n" +
" </value>\n" +
" <valuePattern>my.property.pattern</valuePattern>\n" +
" <valueFormat>my.property.format</valueFormat>\n" +
" </property>\n" +
" </branch>\n" +
" <branch>\n" +
" <pattern>branch2-pattern</pattern>\n" +
" <versionFormat>branch2-format</versionFormat>\n" +
" <property>\n" +
" <pattern>my.first.property</pattern>\n" +
" <value>\n" +
" <pattern>my.first.property.pattern</pattern>\n" +
" <format>my.first.property.format</format>\n" +
" </value>\n" +
" <valuePattern>my.first.property.pattern</valuePattern>\n" +
" <valueFormat>my.first.property.format</valueFormat>\n" +
" </property>\n" +
" <property>\n" +
" <pattern>my.second.property</pattern>\n" +
" <value>\n" +
" <pattern>my.second.property.pattern</pattern>\n" +
" <format>my.second.property.format</format>\n" +
" </value>\n" +
" <valuePattern>my.second.property.pattern</valuePattern>\n" +
" <valueFormat>my.second.property.format</valueFormat>\n" +
" </property>\n" +
" </branch>\n" +
"</gitVersioning>\n";
Expand All @@ -142,8 +136,8 @@ void xmlUnmarshaller_branchConfigsOnlyWithProperties() throws IOException {
() -> assertThat(branchConfig.property).hasSize(1),
() -> assertThat(branchConfig.property.get(0)).satisfies(branchPropertyConfig -> assertAll(
() -> assertThat(branchPropertyConfig.pattern).isEqualTo("my.property"),
() -> assertThat(branchPropertyConfig.value.pattern).isEqualTo("my.property.pattern"),
() -> assertThat(branchPropertyConfig.value.format).isEqualTo("my.property.format")
() -> assertThat(branchPropertyConfig.valuePattern).isEqualTo("my.property.pattern"),
() -> assertThat(branchPropertyConfig.valueFormat).isEqualTo("my.property.format")
))
)),
() -> assertThat(branchConfigs.get(1)).satisfies(branchConfig -> assertAll(
Expand All @@ -152,13 +146,13 @@ void xmlUnmarshaller_branchConfigsOnlyWithProperties() throws IOException {
() -> assertThat(branchConfig.property).hasSize(2),
() -> assertThat(branchConfig.property.get(0)).satisfies(branchPropertyConfig -> assertAll(
() -> assertThat(branchPropertyConfig.pattern).isEqualTo("my.first.property"),
() -> assertThat(branchPropertyConfig.value.pattern).isEqualTo("my.first.property.pattern"),
() -> assertThat(branchPropertyConfig.value.format).isEqualTo("my.first.property.format")
() -> assertThat(branchPropertyConfig.valuePattern).isEqualTo("my.first.property.pattern"),
() -> assertThat(branchPropertyConfig.valueFormat).isEqualTo("my.first.property.format")
)),
() -> assertThat(branchConfig.property.get(1)).satisfies(branchPropertyConfig -> assertAll(
() -> assertThat(branchPropertyConfig.pattern).isEqualTo("my.second.property"),
() -> assertThat(branchPropertyConfig.value.pattern).isEqualTo("my.second.property.pattern"),
() -> assertThat(branchPropertyConfig.value.format).isEqualTo("my.second.property.format")
() -> assertThat(branchPropertyConfig.valuePattern).isEqualTo("my.second.property.pattern"),
() -> assertThat(branchPropertyConfig.valueFormat).isEqualTo("my.second.property.format")
))
))
)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
<versionFormat>${version.release}-master</versionFormat>
<property>
<pattern>foo</pattern>
<value>
<pattern>.*</pattern>
<format>new_new_new</format>
</value>
<valueFormat>new_new_new</valueFormat>
<valuePattern>.*</valuePattern>
</property>
</branch>
<branch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
<pattern>master</pattern>
<versionFormat>${version.release}</versionFormat>
<property>
<pattern>foo</pattern>
<value>
<pattern>.*</pattern>
<format>new_new_new</format>
</value>
</property>
<pattern>foo</pattern>
<valueFormat>new_new_new</valueFormat>
<valuePattern>.*</valuePattern>
</property>
</branch>
<branch>
<pattern>feature/(.*)</pattern>
Expand Down

0 comments on commit 2e8be22

Please sign in to comment.