From dd0468bcb3df24557fd250ea6c3c7a80ffc25421 Mon Sep 17 00:00:00 2001 From: Laurent Almeras Date: Fri, 1 Jan 2021 16:52:38 +0100 Subject: [PATCH 1/2] update versions in one run: test-case --- src/it/hotfix-finish-it-3/child1/pom.xml | 12 ++++++ src/it/hotfix-finish-it-3/child2/pom.xml | 24 +++++++++++ .../expected-production-pom.xml | 16 +++++++ src/it/hotfix-finish-it-3/gitignorefile | 7 ++++ src/it/hotfix-finish-it-3/init.bsh | 42 +++++++++++++++++++ src/it/hotfix-finish-it-3/invoker.properties | 3 ++ src/it/hotfix-finish-it-3/pom.xml | 16 +++++++ src/it/hotfix-finish-it-3/verify.bsh | 37 ++++++++++++++++ 8 files changed, 157 insertions(+) create mode 100644 src/it/hotfix-finish-it-3/child1/pom.xml create mode 100644 src/it/hotfix-finish-it-3/child2/pom.xml create mode 100644 src/it/hotfix-finish-it-3/expected-production-pom.xml create mode 100644 src/it/hotfix-finish-it-3/gitignorefile create mode 100644 src/it/hotfix-finish-it-3/init.bsh create mode 100644 src/it/hotfix-finish-it-3/invoker.properties create mode 100644 src/it/hotfix-finish-it-3/pom.xml create mode 100644 src/it/hotfix-finish-it-3/verify.bsh diff --git a/src/it/hotfix-finish-it-3/child1/pom.xml b/src/it/hotfix-finish-it-3/child1/pom.xml new file mode 100644 index 00000000..6062963d --- /dev/null +++ b/src/it/hotfix-finish-it-3/child1/pom.xml @@ -0,0 +1,12 @@ + + 4.0.0 + + + com.amashchenko.maven.plugin + gitflow-maven-test + 1.0 + + + gitflow-maven-test-child1 + pom + diff --git a/src/it/hotfix-finish-it-3/child2/pom.xml b/src/it/hotfix-finish-it-3/child2/pom.xml new file mode 100644 index 00000000..52bb4f31 --- /dev/null +++ b/src/it/hotfix-finish-it-3/child2/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + + com.amashchenko.maven.plugin + gitflow-maven-test + 1.0 + + + gitflow-maven-test-child2 + pom + + + + + com.amashchenko.maven.plugin + gitflow-maven-test-child1 + ${test.project.version} + pom + import + + + + diff --git a/src/it/hotfix-finish-it-3/expected-production-pom.xml b/src/it/hotfix-finish-it-3/expected-production-pom.xml new file mode 100644 index 00000000..ab90d24e --- /dev/null +++ b/src/it/hotfix-finish-it-3/expected-production-pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + com.amashchenko.maven.plugin + gitflow-maven-test + pom + 1.0.1 + + + child1 + child2 + + + + 1.0.1 + + diff --git a/src/it/hotfix-finish-it-3/gitignorefile b/src/it/hotfix-finish-it-3/gitignorefile new file mode 100644 index 00000000..bb34bc27 --- /dev/null +++ b/src/it/hotfix-finish-it-3/gitignorefile @@ -0,0 +1,7 @@ +build.log +expected-development-pom.xml +expected-production-pom.xml +expected-release-pom.xml +invoker.properties +init.bsh +verify.bsh diff --git a/src/it/hotfix-finish-it-3/init.bsh b/src/it/hotfix-finish-it-3/init.bsh new file mode 100644 index 00000000..3ea3cfe6 --- /dev/null +++ b/src/it/hotfix-finish-it-3/init.bsh @@ -0,0 +1,42 @@ +import org.codehaus.plexus.util.FileUtils; + +try { + new File(basedir, "gitignorefile").renameTo(new File(basedir, ".gitignore")); + + Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " init"); + p.waitFor(); + + Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.email 'a@a.aa'"); + p.waitFor(); + Process p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " config user.name 'a'"); + p.waitFor(); + + p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add ."); + p.waitFor(); + + p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m init"); + p.waitFor(); + + p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " branch hotfix/1.0.1"); + p.waitFor(); + + p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout hotfix/1.0.1"); + p.waitFor(); + + for (String fileName : new String[] {"pom.xml", "child1/pom.xml", "child2/pom.xml"}) { + File pomfile = new File(basedir, fileName); + String pomfilestr = FileUtils.fileRead(pomfile, "UTF-8"); + pomfilestr = pomfilestr.replaceAll("1.0", "1.0.1-SNAPSHOT"); + FileUtils.fileWrite(basedir + "/" + fileName, "UTF-8", pomfilestr); + } + + p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " add ."); + p.waitFor(); + p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " commit -m next"); + p.waitFor(); + +} catch (Exception e) { + e.printStackTrace(); + return false; +} +return true; diff --git a/src/it/hotfix-finish-it-3/invoker.properties b/src/it/hotfix-finish-it-3/invoker.properties new file mode 100644 index 00000000..e6dc19fe --- /dev/null +++ b/src/it/hotfix-finish-it-3/invoker.properties @@ -0,0 +1,3 @@ +invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:hotfix-finish -DpushRemote=false -DfetchRemote=false -B -DhotfixVersion=1.0.1 -DuseSnapshotInHotfix=true -DskipMergeDevBranch=true -DversionProperty=test.project.version + +invoker.description=Check that versions:set and versions:set-property are applied in the same run. Otherwise, hotfix-finish fails on versions:set-property as pom version is inconsistent (mixed 1.0.1-SNAPSHOT and 1.0.1). diff --git a/src/it/hotfix-finish-it-3/pom.xml b/src/it/hotfix-finish-it-3/pom.xml new file mode 100644 index 00000000..4e1b6b10 --- /dev/null +++ b/src/it/hotfix-finish-it-3/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + com.amashchenko.maven.plugin + gitflow-maven-test + pom + 1.0 + + + child1 + child2 + + + + 1.0 + + diff --git a/src/it/hotfix-finish-it-3/verify.bsh b/src/it/hotfix-finish-it-3/verify.bsh new file mode 100644 index 00000000..52260292 --- /dev/null +++ b/src/it/hotfix-finish-it-3/verify.bsh @@ -0,0 +1,37 @@ +import org.codehaus.plexus.util.FileUtils; + +try { + + File gitTag = new File(basedir, ".git/refs/tags/1.0.1"); + if (!gitTag.exists()) { + System.out.println("hotfix-finish .git/refs/tags/1.0.1 does not exist"); + return false; + } + File gitMasterRef = new File(basedir, ".git/refs/heads/master"); + if (!gitMasterRef.exists()) { + System.out.println("hotfix-finish .git/refs/heads/master doesn't exist"); + return false; + } + + p = Runtime.getRuntime().exec("git --git-dir=" + basedir + "/.git --work-tree=" + basedir + " checkout master"); + p.waitFor(); + + file = new File(basedir, "pom.xml"); + expectedFile = new File(basedir, "expected-production-pom.xml"); + + actual = FileUtils.fileRead(file, "UTF-8"); + expected = FileUtils.fileRead(expectedFile, "UTF-8"); + + actual = actual.replaceAll("\\r?\\n", ""); + expected = expected.replaceAll("\\r?\\n", ""); + + if (!expected.equals(actual)) { + System.out.println("hotfix-finish: " + expected + " actual was:" + actual); + return false; + } + +} catch (Exception e) { + e.printStackTrace(); + return false; +} +return true; From 68909ddb37bc1214c08c8706ead0f354a546b923 Mon Sep 17 00:00:00 2001 From: Laurent Almeras Date: Fri, 1 Jan 2021 11:01:54 +0100 Subject: [PATCH 2/2] udpate versions (pom and property) in the same run If versions:set and versions:set-property are launched in separate maven commands, versions:set-property can fail as poms are in an inconsistent state. Attached test case shows a practical use-case where a property is used in dependencyManagement declaration in a multi-module project. If project is not installed, versions:set-property 1.0.1-SNAPSHOT -> 1.0.1 fails as maven tries to resolve dependency 1.0.1-SNAPSHOT in a project already versionned in 1.0.1. --- .../plugin/gitflow/AbstractGitFlowMojo.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java index 32803926..cbb8bda5 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -1017,15 +1017,26 @@ protected void mvnSetVersions(final String version) throws MojoFailureException, executeMvnCommand(TYCHO_VERSIONS_PLUGIN_SET_GOAL, prop, newVersion, "-Dtycho.mode=maven"); } else { + boolean runCommand = false; + List args = new ArrayList<>(); + args.add("-DgenerateBackupPoms=false"); + args.add(newVersion); if (!skipUpdateVersion) { - executeMvnCommand(VERSIONS_MAVEN_PLUGIN_SET_GOAL, grp, art, newVersion, "-DgenerateBackupPoms=false"); + runCommand = true; + args.add(VERSIONS_MAVEN_PLUGIN_SET_GOAL); + args.add(grp); + args.add(art); } if (StringUtils.isNotBlank(versionProperty)) { + runCommand = true; getLog().info("Updating property '" + versionProperty + "' to '" + version + "'."); - executeMvnCommand(VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL, newVersion, "-Dproperty=" + versionProperty, - "-DgenerateBackupPoms=false"); + args.add(VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL); + args.add("-Dproperty=" + versionProperty); + } + if (runCommand) { + executeMvnCommand(args.toArray(new String[0])); } } }