Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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>packaging.buildtimestamp</groupId>
<artifactId>packaging.buildtimestamp.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<groupId>packaging.buildtimestamp</groupId>
<artifactId>packaging.buildtimestamp.mavenplugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<theBuildTimestamp>${maven.build.timestamp}</theBuildTimestamp>
</properties>


<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${theBuildTimestamp}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bundle-ManifestVersion: 2
Bundle-SymbolicName: packaging.buildtimestamp.plugin01;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: .
Bundle-Name: packaging.buildtimestamp.plugin01
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = META-INF/,\
.
17 changes: 17 additions & 0 deletions tycho-its/projects/packaging.buildsimplequalifier/plugin01/pom.xml
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>packaging.buildtimestamp</groupId>
<artifactId>packaging.buildtimestamp.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<groupId>packaging.buildtimestamp</groupId>
<artifactId>packaging.buildtimestamp.plugin01</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bundle-ManifestVersion: 2
Bundle-SymbolicName: packaging.buildtimestamp.plugin02;singleton:=true
Bundle-Version: 1.0.1.qualifier
Bundle-ClassPath: .
Bundle-Name: packaging.buildtimestamp.plugin02
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin.includes = META-INF/,\
.
17 changes: 17 additions & 0 deletions tycho-its/projects/packaging.buildsimplequalifier/plugin02/pom.xml
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>packaging.buildtimestamp</groupId>
<artifactId>packaging.buildtimestamp.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<groupId>packaging.buildtimestamp</groupId>
<artifactId>packaging.buildtimestamp.plugin02</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

</project>
41 changes: 41 additions & 0 deletions tycho-its/projects/packaging.buildsimplequalifier/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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>packaging.buildtimestamp</groupId>
<artifactId>packaging.buildtimestamp.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<maven.build.timestamp.format>yyyyMMddHHmmssSSS</maven.build.timestamp.format>
</properties>

<modules>
<module>plugin01</module>
<module>plugin02</module>
<module>mavenPlugin</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<stripQualifierMatchingMicro>false</stripQualifierMatchingMicro>
<forceContextQualifier>1</forceContextQualifier>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2016, 2021 Bachmann electronic GmbH. and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Bachmann electronic GmbH. - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.test.packaging;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.apache.maven.it.Verifier;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.junit.Assert;
import org.junit.Test;

/**
* This test uses a project that contains 3 plugins (2 eclipse-plugins and one
* maven plugin). The maven plugin contains a text file where the
* maven.build.buildtimestamp is written to. It compares the content of that
* file with the qualifier of the Bundle-Version in the eclipse plugins manifest
* files.
*
* The test is ensuring qualifier to be presented
*/
public class DefaultBuildSimpleQualifierTest extends AbstractTychoIntegrationTest {

@Test
public void testDefaulBuildTimestampIsTheMavenBuildTimestamp() throws Exception {
Verifier verifier = getVerifier("/packaging.buildsimplequalifier", false);
verifier.executeGoal("verify");
verifier.verifyErrorFreeLog();
File baseDir = new File(verifier.getBasedir());

String plugin1Manifest = Files.readString(Paths.get(baseDir.getAbsolutePath(), "plugin01/target/MANIFEST.MF"));
String plugin2Manifest = Files.readString(Paths.get(baseDir.getAbsolutePath(), "plugin02/target/MANIFEST.MF"));
String expectedBundle1Version = "Bundle-Version: 1.0.0.1";
String expectedBundle2Version = "Bundle-Version: 1.0.1.1";
Assert.assertTrue(
"Expected Bundle-Version in MANIFEST: '" + expectedBundle1Version + "'\nbut was\n" + plugin1Manifest,
plugin1Manifest.contains(expectedBundle1Version));

Assert.assertTrue(
"Expected Bundle-Version in MANIFEST: '" + expectedBundle2Version + "'\nbut was\n" + plugin2Manifest,
plugin2Manifest.contains(expectedBundle2Version));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,27 @@
* </ol>
* </p>
* <p>
* The generated qualifier is assigned to <code>buildQualifier</code> project property. The
* unqualified project version is assigned to <code>unqualifiedVersion</code> project property. The
* unqualified version is calculated based on <code>${project.version}</code> and can be used for
* any Tycho project and regular Maven project. Different projects can use different formats to
* expand the timestamp (not recommended). The concatenation of <code>${unqualifiedVersion}</code>
* and <code>${buildQualifier}</code>, if not empty, is assigned to the project property
* <code>qualifiedVersion</code>.
* The generated qualifier is assigned to <code>buildQualifier</code> project
* property. The unqualified project version is assigned to
* <code>unqualifiedVersion</code> project property. The unqualified version is
* calculated based on <code>${project.version}</code> and can be used for any
* Tycho project and regular Maven project. Different projects can use different
* formats to expand the timestamp (not recommended). The concatenation of
* <code>${unqualifiedVersion}</code> and <code>${buildQualifier}</code>, if not
* empty, is assigned to the project property <code>qualifiedVersion</code>.
* </p>
* <p>
* The timestamp generation logic is extensible. The primary use case is to generate build version
* qualifier based on the timestamp of the last project commit. Here is example pom.xml snippet that
* enables custom timestamp generation logic
* The timestamp generation logic is extensible. The primary use case is to
* generate build version qualifier based on the timestamp of the last project
* commit. Here is example pom.xml snippet that enables custom timestamp
* generation logic
* </p>
* <p>
* If configured build qualifier will strip repeated qualifier if matching to
* micro version. If <code>stripQualifierIfDuplicates</code> property is
* enabled, it will generate for version 1.0.0.qualifier and qualifier equal 0
* version 1.0.0. If disabled, it will generate for same version 1.0.0.0 so the
* last part is not stripped off.
*
* <pre>
* ...
Expand All @@ -81,6 +90,7 @@
* &lt;/dependencies&gt;
* &lt;configuration&gt;
* &lt;timestampProvider&gt;custom&lt;/timestampProvider&gt;
* &lt;stripQualifierIfDuplicates&gt;false&lt;/stripQualifierIfDuplicates&gt;
* &lt;/configuration&gt;
* &lt;/plugin&gt;
* ...
Expand Down Expand Up @@ -124,6 +134,9 @@ public class BuildQualifierMojo extends AbstractVersionMojo {
@Parameter(property = "mojoExecution", readonly = true)
protected MojoExecution execution;

@Parameter(name = "stripQualifierMatchingMicro", defaultValue = "true", property = "tycho.buildqualifier.stripqualifiermatchingmicro")
protected boolean stripQualifierMatchingMicro;

@Inject
protected Map<String, BuildTimestampProvider> timestampProviders;

Expand Down Expand Up @@ -181,10 +194,13 @@ private TychoProjectVersion calculateQualifiedVersion(Date timestamp)
validateQualifier(forceContextQualifier, qualifier);

String pomOSGiVersion = getUnqualifiedVersion();
String suffix = "." + qualifier;
if (pomOSGiVersion.endsWith(suffix)) {
return new TychoProjectVersion(pomOSGiVersion.substring(0, pomOSGiVersion.length() - suffix.length()),
qualifier);
if (stripQualifierMatchingMicro) {
// Equal qualifier should be stripped only if enabled.
String suffix = "." + qualifier;
if (pomOSGiVersion.endsWith(suffix)) {
return new TychoProjectVersion(pomOSGiVersion.substring(0, pomOSGiVersion.length() - suffix.length()),
qualifier);
}
}
return new TychoProjectVersion(pomOSGiVersion, qualifier);
}
Expand Down
Loading