Skip to content

Commit

Permalink
Update versions if the project references another pom as module
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 10, 2024
1 parent 86db29d commit 027c79e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
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: bundle
Bundle-Version: 1.0.0.qualifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?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>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../parent</relativePath>
</parent>
<artifactId>bundle</artifactId>
</project>
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>

<groupId>org.tycho.its</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<tycho-version>4.0.0-SNAPSHOT</tycho-version>
</properties>
<modules>
<module>../bundle</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<tycho-version>4.0.0-SNAPSHOT</tycho-version>
</properties>
<modules>
<module>parent</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
Expand Up @@ -17,17 +17,22 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Properties;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

import org.apache.maven.it.Verifier;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.eclipse.tycho.version.TychoVersion;
import org.junit.Test;
import org.osgi.framework.Constants;

public class TychoVersionsPluginTest extends AbstractTychoIntegrationTest {

Expand Down Expand Up @@ -99,6 +104,28 @@ public void updateProjectVersionBndTest() throws Exception {
assertEquals("Bundle-Version is not as expected!", expectedNewVersion, versionProperty);
}

@Test
public void updateProjectVersionWithNestedPom() throws Exception {
String expectedNewVersion = "1.1.0";

Verifier verifier = getVerifier("tycho-version-plugin/nested_modules", true);

verifier.addCliOption("-DnewVersion=" + expectedNewVersion);
verifier.executeGoal("org.eclipse.tycho:tycho-versions-plugin:" + VERSION + ":set-version");

verifier.verifyErrorFreeLog();
List<String> poms = List.of("pom.xml", "parent/pom.xml", "bundle/pom.xml");
for (String pom : poms) {
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model pomModel = pomReader.read(new FileReader(new File(verifier.getBasedir(), pom)));
assertEquals("<version> in " + pom + " has not been changed!", expectedNewVersion, pomModel.getVersion());
}
Manifest manifest = new Manifest(
new FileInputStream(new File(verifier.getBasedir(), "bundle/" + JarFile.MANIFEST_NAME)));
assertEquals("version in manifest was not updated!", expectedNewVersion,
manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION));
}

@Test
public void updateProjectMetadataVersionBndTest() throws Exception {
String expectedNewVersion = "2.0.0.qualifier";
Expand Down

0 comments on commit 027c79e

Please sign in to comment.