From 2e8be22b9632da763ff106f30c1347ca6f2d2349 Mon Sep 17 00:00:00 2001 From: Bengt Brodersen Date: Sun, 9 Feb 2020 20:16:24 +0100 Subject: [PATCH] feat: simplify property replacement configuration BREAKING CHANGE: simplify property replacement configuration --- README.md | 50 +++++++++++++++---- pom.xml | 10 +--- .../maven/gitversioning/Configuration.java | 9 +--- .../GitVersioningModelProcessor.java | 6 ++- .../maven/gitversioning/VersioningMojo.java | 15 +++--- .../gitversioning/ConfigurationTest.java | 30 +++++------ .../.mvn/maven-git-versioning-extension.xml | 6 +-- .../.mvn/maven-git-versioning-extension.xml | 10 ++-- 8 files changed, 77 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 3968dd00..688e50da 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,8 @@ Create `${basedir}/.mvn/maven-git-versioning-extension.xml`. - `` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders) - `` A property definition to update the value of a property - `` An arbitrary regex to match property names - - `` The definition of the new property value - - *optional* `` An arbitrary regex to match property values - - `` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - `` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - *optional* `` An arbitrary regex to match and use capture group values of property value - *optional* `` Enable(`true`) or disable(`false`) version update in original pom fill (will override global `` value) - ⚠ **considered if...** * HEAD attached to a branch `git checkout `
@@ -91,9 +90,8 @@ Create `${basedir}/.mvn/maven-git-versioning-extension.xml`. - `` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders) - `` A property definition to update the value of a property - `` An arbitrary regex to match property names - - `` The definition of the new property value - - *optional* `` An arbitrary regex to match property values - - `` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - `` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - *optional* `` An arbitrary regex to match and use capture group values of property value - *optional* `` Enable(`true`) or disable(`false`) version update in original pom fill (will override global `` value) - ⚠ **considered if...** * HEAD is detached `git checkout `
@@ -103,9 +101,8 @@ Create `${basedir}/.mvn/maven-git-versioning-extension.xml`. - `` An arbitrary string, see [Version Format & Placeholders](#version-format--placeholders) - `` A property definition to update the value of a property - `` An arbitrary regex to match property names - - `` The definition of the new property value - - *optional* `` An arbitrary regex to match property values - - `` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - `` The new value format of the property, see [Version Format & Placeholders](#version-format--placeholders) + - *optional* `` 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
@@ -254,6 +251,41 @@ fi # Changelog +## 5.0.0 +* + +### Breaking Changes +* simplify replacement configuration + +new config +```xml + + + master + ${version} + + revision + ${branch-SNAPSHOT} + + + +``` +old config +```xml + + + master + ${version} + + revision + + ${branch-SNAPSHOT} + + + + +``` + ## 4.10.2 * fix verbose logging when disabling extension by flag * restrict project versioning to root- and sub-projects diff --git a/pom.xml b/pom.xml index ebd4ab7a..7abfdbfb 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ me.qoomon maven-git-versioning-extension - 4.10.2 + 5.0.0 maven-plugin @@ -75,16 +75,10 @@ org.apache.maven maven-core - 3.6.2 + 3.6.3 provided - - org.apache.maven - maven-plugin-api - 3.6.2 - - org.apache.maven.plugin-tools maven-plugin-annotations diff --git a/src/main/java/me/qoomon/maven/gitversioning/Configuration.java b/src/main/java/me/qoomon/maven/gitversioning/Configuration.java index 644151ed..e34d04d5 100644 --- a/src/main/java/me/qoomon/maven/gitversioning/Configuration.java +++ b/src/main/java/me/qoomon/maven/gitversioning/Configuration.java @@ -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; } } diff --git a/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java b/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java index bd8fb89a..6ff6fd02 100644 --- a/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java +++ b/src/main/java/me/qoomon/maven/gitversioning/GitVersioningModelProcessor.java @@ -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()); @@ -261,7 +265,7 @@ private List convertPropertyDescription( List 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()); } diff --git a/src/main/java/me/qoomon/maven/gitversioning/VersioningMojo.java b/src/main/java/me/qoomon/maven/gitversioning/VersioningMojo.java index 8f186625..0dd12f45 100644 --- a/src/main/java/me/qoomon/maven/gitversioning/VersioningMojo.java +++ b/src/main/java/me/qoomon/maven/gitversioning/VersioningMojo.java @@ -67,12 +67,6 @@ 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()) { @@ -80,6 +74,15 @@ public synchronized void execute() throws MojoExecutionException { } } + // 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); diff --git a/src/test/java/me/qoomon/maven/gitversioning/ConfigurationTest.java b/src/test/java/me/qoomon/maven/gitversioning/ConfigurationTest.java index 55b9970f..965d2d32 100644 --- a/src/test/java/me/qoomon/maven/gitversioning/ConfigurationTest.java +++ b/src/test/java/me/qoomon/maven/gitversioning/ConfigurationTest.java @@ -100,10 +100,8 @@ void xmlUnmarshaller_branchConfigsOnlyWithProperties() throws IOException { " branch1-format\n" + " \n" + " my.property\n" + - " \n" + - " my.property.pattern\n" + - " my.property.format\n" + - " \n" + + " my.property.pattern\n" + + " my.property.format\n" + " \n" + "
\n" + " \n" + @@ -111,17 +109,13 @@ void xmlUnmarshaller_branchConfigsOnlyWithProperties() throws IOException { " branch2-format\n" + " \n" + " my.first.property\n" + - " \n" + - " my.first.property.pattern\n" + - " my.first.property.format\n" + - " \n" + + " my.first.property.pattern\n" + + " my.first.property.format\n" + " \n" + " \n" + " my.second.property\n" + - " \n" + - " my.second.property.pattern\n" + - " my.second.property.format\n" + - " \n" + + " my.second.property.pattern\n" + + " my.second.property.format\n" + " \n" + " \n" + "\n"; @@ -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( @@ -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") )) )) )), diff --git a/src/test/resources/testProjects/multiModuleProject/.mvn/maven-git-versioning-extension.xml b/src/test/resources/testProjects/multiModuleProject/.mvn/maven-git-versioning-extension.xml index c89b5b5c..1d383775 100644 --- a/src/test/resources/testProjects/multiModuleProject/.mvn/maven-git-versioning-extension.xml +++ b/src/test/resources/testProjects/multiModuleProject/.mvn/maven-git-versioning-extension.xml @@ -5,10 +5,8 @@ ${version.release}-master foo - - .* - new_new_new - + new_new_new + .* diff --git a/src/test/resources/testProjects/standardProject/.mvn/maven-git-versioning-extension.xml b/src/test/resources/testProjects/standardProject/.mvn/maven-git-versioning-extension.xml index 795ff007..9b78eb02 100644 --- a/src/test/resources/testProjects/standardProject/.mvn/maven-git-versioning-extension.xml +++ b/src/test/resources/testProjects/standardProject/.mvn/maven-git-versioning-extension.xml @@ -3,12 +3,10 @@ master ${version.release} - foo - - .* - new_new_new - - + foo + new_new_new + .* +
feature/(.*)