From d72a866416e4d4a7bfb6cf00f614c679b9f6c666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 6 Jan 2024 18:21:28 +0100 Subject: [PATCH] Unify the buildTimestamp parameter across mojos --- .../java/org/eclipse/tycho/TychoConstants.java | 2 ++ .../eclipse/tycho/core/maven/AbstractP2Mojo.java | 3 ++- .../tycho/buildversion/BuildQualifierMojo.java | 14 +++++++++----- .../packaging/AbstractTychoPackagingMojo.java | 3 ++- .../buildversion/TestBuildTimestampProvider.java | 10 +++++----- .../org/eclipse/tycho/source/OsgiSourceMojo.java | 6 +++--- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java b/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java index fc43b3d49c..2a1a5c793f 100644 --- a/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java +++ b/tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java @@ -58,6 +58,8 @@ public interface TychoConstants { static final String PDE_BND = "pde.bnd"; + public static final String BUILD_TIMESTAMP = CTX_BASENAME + "/buildTimestamp"; + public String JAR_EXTENSION = "jar"; String PROP_GROUP_ID = "maven-groupId"; diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/AbstractP2Mojo.java b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/AbstractP2Mojo.java index e7ff710d06..46f774b247 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/AbstractP2Mojo.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/AbstractP2Mojo.java @@ -23,6 +23,7 @@ import org.eclipse.tycho.ReactorProject; import org.eclipse.tycho.ReactorProjectIdentities; import org.eclipse.tycho.TargetEnvironment; +import org.eclipse.tycho.TychoProperties; import org.eclipse.tycho.core.TychoProjectManager; import org.eclipse.tycho.core.osgitools.DefaultReactorProject; import org.eclipse.tycho.osgi.adapters.MavenReactorProjectIdentities; @@ -36,7 +37,7 @@ public abstract class AbstractP2Mojo extends AbstractMojo { @Parameter(property = "project", readonly = true) private MavenProject project; - @Parameter(property = "buildQualifier") + @Parameter(property = TychoProperties.BUILD_QUALIFIER) private String qualifier; @Component diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/BuildQualifierMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/BuildQualifierMojo.java index 599da61e4a..5c76d1df3f 100644 --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/BuildQualifierMojo.java +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/buildversion/BuildQualifierMojo.java @@ -34,6 +34,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.eclipse.tycho.BuildPropertiesParser; +import org.eclipse.tycho.TychoConstants; import org.eclipse.tycho.build.BuildTimestampProvider; import org.eclipse.tycho.core.VersioningHelper; import org.eclipse.tycho.core.osgitools.DefaultReactorProject; @@ -144,14 +145,18 @@ public void setFormat(String formatString) { @Override public void execute() throws MojoExecutionException, MojoFailureException { - TychoProjectVersion projectVersion = calculateQualifiedVersion(); + Date timestamp = getBuildTimestamp(); + TychoProjectVersion projectVersion = calculateQualifiedVersion(timestamp); project.getProperties().put(BUILD_QUALIFIER, projectVersion.qualifier); project.getProperties().put(UNQUALIFIED_VERSION, projectVersion.unqualifiedVersion); project.getProperties().put(QUALIFIED_VERSION, projectVersion.getOSGiVersion()); getLog().info("The project's OSGi version is " + projectVersion.getOSGiVersion()); + DefaultReactorProject.adapt(project).setContextValue(TychoConstants.BUILD_TIMESTAMP, projectVersion); } - private TychoProjectVersion calculateQualifiedVersion() throws MojoFailureException, MojoExecutionException { + private TychoProjectVersion calculateQualifiedVersion(Date timestamp) + throws MojoFailureException, MojoExecutionException { + Version osgiVersion = getParsedOSGiVersion(); if (osgiVersion != null) { @@ -162,7 +167,7 @@ private TychoProjectVersion calculateQualifiedVersion() throws MojoFailureExcept return new TychoProjectVersion(unqualifiedVersion, osgiVersion.getQualifier()); } } - String qualifier = getDesiredQualifier(); + String qualifier = getDesiredQualifier(timestamp); validateQualifier(qualifier); @@ -175,7 +180,7 @@ private TychoProjectVersion calculateQualifiedVersion() throws MojoFailureExcept return new TychoProjectVersion(pomOSGiVersion, qualifier); } - protected String getDesiredQualifier() throws MojoExecutionException { + protected String getDesiredQualifier(Date timestamp) throws MojoExecutionException { String qualifier = forceContextQualifier; if (qualifier == null) { @@ -183,7 +188,6 @@ protected String getDesiredQualifier() throws MojoExecutionException { } if (qualifier == null) { - Date timestamp = getBuildTimestamp(); qualifier = getQualifier(timestamp); } return qualifier; diff --git a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/AbstractTychoPackagingMojo.java b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/AbstractTychoPackagingMojo.java index 2dd726fda8..4f8e3d840c 100644 --- a/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/AbstractTychoPackagingMojo.java +++ b/tycho-packaging-plugin/src/main/java/org/eclipse/tycho/packaging/AbstractTychoPackagingMojo.java @@ -33,6 +33,7 @@ import org.codehaus.plexus.util.AbstractScanner; import org.eclipse.tycho.BuildProperties; import org.eclipse.tycho.DependencyArtifacts; +import org.eclipse.tycho.TychoProperties; import org.eclipse.tycho.core.TychoProject; import org.eclipse.tycho.core.osgitools.DefaultReactorProject; @@ -58,7 +59,7 @@ public abstract class AbstractTychoPackagingMojo extends AbstractMojo { /** * Build qualifier. Recommended way to set this parameter is using build-qualifier goal. */ - @Parameter(property = "buildQualifier") + @Parameter(property = TychoProperties.BUILD_QUALIFIER) protected String qualifier; /** diff --git a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildversion/TestBuildTimestampProvider.java b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildversion/TestBuildTimestampProvider.java index 169a706728..fab590809d 100644 --- a/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildversion/TestBuildTimestampProvider.java +++ b/tycho-packaging-plugin/src/test/java/org/eclipse/tycho/buildversion/TestBuildTimestampProvider.java @@ -27,7 +27,7 @@ @Component(role = BuildTimestampProvider.class, hint = "test") public class TestBuildTimestampProvider implements BuildTimestampProvider { - public static final String PROP_TESTBUILDTIMESTAMPE = "testbuildtimestamp"; + public static final String PROP_TESTBUILDTIMESTAMPE = "testbuildtimestamp"; private final SimpleDateFormat format; @@ -39,11 +39,11 @@ public TestBuildTimestampProvider() { @Override public Date getTimestamp(MavenSession session, MavenProject project, MojoExecution execution) throws MojoExecutionException { - String prop = session.getCurrentProject().getProperties().getProperty(PROP_TESTBUILDTIMESTAMPE); + String prop = session.getCurrentProject().getProperties().getProperty(PROP_TESTBUILDTIMESTAMPE); - if (prop == null) { - throw new IllegalArgumentException("Build timestamp property is not set."); - } + if (prop == null) { + return new Date(); + } try { return format.parse(prop); diff --git a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java index c4c9d42cfb..3d8bc644ef 100644 --- a/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java +++ b/tycho-source-plugin/src/main/java/org/eclipse/tycho/source/OsgiSourceMojo.java @@ -57,6 +57,7 @@ import org.eclipse.tycho.BuildPropertiesParser; import org.eclipse.tycho.PackagingType; import org.eclipse.tycho.ReactorProject; +import org.eclipse.tycho.TychoProperties; import org.eclipse.tycho.core.TychoProject; import org.eclipse.tycho.core.osgitools.BundleReader; import org.eclipse.tycho.core.osgitools.DefaultReactorProject; @@ -109,7 +110,7 @@ public class OsgiSourceMojo extends AbstractSourceJarMojo { * Build qualifier. Recommended way to set this parameter is using build-qualifier goal. Only * used when creating a source bundle. */ - @Parameter(property = "buildQualifier") + @Parameter(property = TychoProperties.BUILD_QUALIFIER) private String qualifier; /** @@ -362,8 +363,7 @@ private void addSourceBundleManifestEntries(MavenArchiveConfiguration mavenArchi addLocalicationHeaders(mavenArchiveConfiguration::addManifestEntry); } else { - getLog().info( - "NOT adding source bundle MANIFEST.MF entries. Incomplete or absent bundle information"); + getLog().info("NOT adding source bundle MANIFEST.MF entries. Incomplete or absent bundle information"); } }