Skip to content

Commit

Permalink
set-version: Fix regression overwriting mismatching versions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sratz authored and laeubi committed May 8, 2024
1 parent 2c575a9 commit 8cb0cc7
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test Bundle
Bundle-SymbolicName: m1
Bundle-Version: 1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.tycho.its</groupId>
<artifactId>p</artifactId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>

<groupId>org.tycho.its</groupId>
<artifactId>m1</artifactId>
<version>1.0.0</version>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.tycho.its</groupId>
<artifactId>root</artifactId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>

<groupId>org.tycho.its</groupId>
<artifactId>p</artifactId>
<version>1.0.0</version><!-- This is the SAME version as the root -->
<packaging>pom</packaging>

<modules>
<module>m1</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.tycho.its</groupId>
<artifactId>root</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<modules>
<module>p</module>
<module>q</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test Bundle
Bundle-SymbolicName: m2
Bundle-Version: 2.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.tycho.its</groupId>
<artifactId>q</artifactId>
<version>2.0.0</version>
<relativePath>..</relativePath>
</parent>

<groupId>org.tycho.its</groupId>
<artifactId>m2</artifactId>
<version>2.0.0</version>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.tycho.its</groupId>
<artifactId>root</artifactId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>

<groupId>org.tycho.its</groupId>
<artifactId>q</artifactId>
<version>2.0.0</version><!-- This is DIFFERENT than the version of the root -->
<packaging>pom</packaging>

<modules>
<module>m2</module>
</modules>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<Expectation> 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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8cb0cc7

Please sign in to comment.