From ebcb491761d0f030ee4f6349b75d3437f6f03b31 Mon Sep 17 00:00:00 2001 From: Sebastian Ratz Date: Wed, 8 May 2024 11:02:58 +0100 Subject: [PATCH] set-version: Fix regression overwriting mismatching versions Fix regression introduced in #3343. Also for the child modules the version of the change must match, so that it does not blindly overwrite the versions of the submodules. Fixes #3808. --- .../p/m1/META-INF/MANIFEST.MF | 5 +++ .../only_same_version/p/m1/pom.xml | 17 ++++++++ .../set-version/only_same_version/p/pom.xml | 21 ++++++++++ .../set-version/only_same_version/pom.xml | 26 +++++++++++++ .../q/m2/META-INF/MANIFEST.MF | 5 +++ .../only_same_version/q/m2/pom.xml | 17 ++++++++ .../set-version/only_same_version/q/pom.xml | 21 ++++++++++ .../TychoVersionsPluginTest.java | 39 +++++++++++++++++++ .../versions/manipulation/PomManipulator.java | 3 +- 9 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/m1/META-INF/MANIFEST.MF create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/m1/pom.xml create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/pom.xml create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/only_same_version/pom.xml create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/m2/META-INF/MANIFEST.MF create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/m2/pom.xml create mode 100644 tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/pom.xml diff --git a/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/m1/META-INF/MANIFEST.MF b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/m1/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ed2ed7f0ca --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/m1/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Test Bundle +Bundle-SymbolicName: m1 +Bundle-Version: 1.0.0 diff --git a/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/m1/pom.xml b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/m1/pom.xml new file mode 100644 index 0000000000..5f5a744a69 --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/m1/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + org.tycho.its + p + 1.0.0 + .. + + + org.tycho.its + m1 + 1.0.0 + eclipse-plugin + + diff --git a/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/pom.xml b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/pom.xml new file mode 100644 index 0000000000..7ca2a9df6d --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/p/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + + org.tycho.its + root + 1.0.0 + .. + + + org.tycho.its + p + 1.0.0 + pom + + + m1 + + + diff --git a/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/pom.xml b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/pom.xml new file mode 100644 index 0000000000..b1645650ad --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + org.tycho.its + root + 1.0.0 + pom + + + p + q + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + + + diff --git a/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/m2/META-INF/MANIFEST.MF b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/m2/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ee4270d409 --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/m2/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Test Bundle +Bundle-SymbolicName: m2 +Bundle-Version: 2.0.0 diff --git a/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/m2/pom.xml b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/m2/pom.xml new file mode 100644 index 0000000000..691d8ad683 --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/m2/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + org.tycho.its + q + 2.0.0 + .. + + + org.tycho.its + m2 + 2.0.0 + eclipse-plugin + + diff --git a/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/pom.xml b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/pom.xml new file mode 100644 index 0000000000..9bd20eb193 --- /dev/null +++ b/tycho-its/projects/tycho-version-plugin/set-version/only_same_version/q/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + + org.tycho.its + root + 1.0.0 + .. + + + org.tycho.its + q + 2.0.0 + pom + + + m2 + + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/versionsplugin/TychoVersionsPluginTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/versionsplugin/TychoVersionsPluginTest.java index 4d992bb387..a29635d0b6 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/versionsplugin/TychoVersionsPluginTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/versionsplugin/TychoVersionsPluginTest.java @@ -145,6 +145,45 @@ public void updateProjectVersionWithNestedPom() throws Exception { manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION)); } + @Test + public void updateProjectVersionOnlyChangesVersionOfNestedProjectsIfSameVersionAsRoot() throws Exception { + Verifier verifier = getVerifier("tycho-version-plugin/set-version/only_same_version", false); + + verifier.addCliOption("-DnewVersion=1.0.1"); + verifier.executeGoal("org.eclipse.tycho:tycho-versions-plugin:" + VERSION + ":set-version"); + + verifier.verifyErrorFreeLog(); + + record Expectation(String pom, String expectedVersion, String expectedParentVersion) { + } + List expectations = List.of( // + new Expectation("pom.xml", "1.0.1", null), // + new Expectation("p/pom.xml", "1.0.1", "1.0.1"), // + new Expectation("p/m1/pom.xml", "1.0.1", "1.0.1"), // + new Expectation("q/pom.xml", "2.0.0", "1.0.1"), // only parent shall be changed + new Expectation("q/m2/pom.xml", "2.0.0", "2.0.0") // nothing shall be changed + ); + for (Expectation expectation : expectations) { + MavenXpp3Reader pomReader = new MavenXpp3Reader(); + String pom = expectation.pom(); + Model pomModel = pomReader.read(new FileReader(new File(verifier.getBasedir(), pom))); + Parent parent = pomModel.getParent(); + + assertEquals("project > version in " + pom + " is not as expected!", expectation.expectedVersion(), + pomModel.getVersion()); + if (expectation.expectedParentVersion() == null) { + assertNull("project > parent in " + pom + " should be null", parent); + } else { + assertEquals("project > parent > version in " + pom + " is not as expected!", + expectation.expectedParentVersion(), parent.getVersion()); + } + } + assertEquals("version in manifest p/m1 is not as expected!", "1.0.1", + getManifest(verifier, "p/m1").getMainAttributes().getValue(Constants.BUNDLE_VERSION)); + assertEquals("version in manifest q/m2 is not as expected!", "2.0.0", + getManifest(verifier, "q/m2").getMainAttributes().getValue(Constants.BUNDLE_VERSION)); + } + @Test public void updateVersionRanges() throws Exception { String expectedNewMavenVersion = "1.1.0-SNAPSHOT"; diff --git a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/manipulation/PomManipulator.java b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/manipulation/PomManipulator.java index 699c17086b..b77449b4f7 100644 --- a/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/manipulation/PomManipulator.java +++ b/tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/manipulation/PomManipulator.java @@ -86,7 +86,8 @@ public boolean addMoreChanges(ProjectMetadata project, VersionChangesDescriptor .ifPresent(moduleMeta -> { PomFile modulePom = moduleMeta.getMetadata(PomFile.class); if (modulePom != null && modulePom.isMutable() - && POM.equals(modulePom.getPackaging())) { + && POM.equals(modulePom.getPackaging()) + && isVersionEquals(modulePom.getVersion(), change.getVersion())) { if (versionChangeContext.addVersionChange( new PomVersionChange(modulePom, change.getNewVersion()))) { moreChanges.set(true);