Skip to content

Commit

Permalink
Unify the buildTimestamp parameter across mojos
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 7, 2024
1 parent ad55442 commit d72a866
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions tycho-api/src/main/java/org/eclipse/tycho/TychoConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {

Expand All @@ -162,7 +167,7 @@ private TychoProjectVersion calculateQualifiedVersion() throws MojoFailureExcept
return new TychoProjectVersion(unqualifiedVersion, osgiVersion.getQualifier());
}
}
String qualifier = getDesiredQualifier();
String qualifier = getDesiredQualifier(timestamp);

validateQualifier(qualifier);

Expand All @@ -175,15 +180,14 @@ 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) {
qualifier = buildPropertiesParser.parse(DefaultReactorProject.adapt(project)).getForceContextQualifier();
}

if (qualifier == null) {
Date timestamp = getBuildTimestamp();
qualifier = getQualifier(timestamp);
}
return qualifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

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

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

/**
Expand Down Expand Up @@ -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");
}
}

Expand Down

0 comments on commit d72a866

Please sign in to comment.