Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Zlika authored and laeubi committed Dec 30, 2024
1 parent 39ed051 commit b45f8d8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
import static org.eclipse.tycho.TychoProperties.UNQUALIFIED_VERSION;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.TimeZone;

import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
Expand Down Expand Up @@ -123,18 +120,6 @@ public class BuildQualifierMojo extends AbstractVersionMojo {
@Parameter(property = "tycho.buildqualifier.provider")
protected String timestampProvider;

/**
* Timestamp for reproducible build qualifier, either formatted as ISO 8601
* extended offset date-time (e.g. in UTC such as '2011-12-03T10:15:30Z' or with
* an offset '2019-10-05T20:37:42+06:00'), or as an int representing seconds
* since the epoch (like <a href=
* "https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
* This timestamp is only used if there is not custom build timestamp provider
* set.
*/
@Parameter(defaultValue = "${project.build.outputTimestamp}")
private String outputTimestamp;

@Parameter(property = "mojoExecution", readonly = true)
protected MojoExecution execution;

Expand Down Expand Up @@ -281,10 +266,6 @@ private String getUnqualifiedVersion() {
}

protected Date getBuildTimestamp() throws MojoExecutionException {
Optional<Instant> reproducibleTimestamp = MavenArchiver.parseBuildOutputTimestamp(outputTimestamp);
if (reproducibleTimestamp.isPresent() && (timestampProvider == null)) {
return Date.from(reproducibleTimestamp.get());
}
String hint = (timestampProvider != null) ? timestampProvider : DefaultBuildTimestampProvider.ROLE_HINT;
BuildTimestampProvider provider = timestampProviders.get(hint);
if (provider == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@
*******************************************************************************/
package org.eclipse.tycho.buildversion;

import java.time.Instant;
import java.util.Date;
import java.util.Optional;

import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.tycho.build.BuildTimestampProvider;

/**
* Build timestamp provider that returns the same timestamp for all projects, the
* ${maven.build.timestamp}.
* Build timestamp provider that returns the same timestamp for all projects. If
* the standard Maven property ${project.build.outputTimestamp} exists, its
* value is used for the timestamp. If it does not exist (or cannot be parsed),
* the ${maven.build.timestamp} timestamp is used instead.
*/
@Component(role = BuildTimestampProvider.class, hint = DefaultBuildTimestampProvider.ROLE_HINT)
public class DefaultBuildTimestampProvider implements BuildTimestampProvider {
Expand All @@ -31,7 +36,14 @@ public class DefaultBuildTimestampProvider implements BuildTimestampProvider {

@Override
public Date getTimestamp(MavenSession session, MavenProject project, MojoExecution execution) {
return session.getStartTime();
// Use the outputTimestamp property value if available for reproducible builds
final String outputTimestamp = (String) project.getProperties().get("project.build.outputTimestamp");
Optional<Instant> reproducibleTimestamp = MavenArchiver.parseBuildOutputTimestamp(outputTimestamp);
if (reproducibleTimestamp.isPresent()) {
return Date.from(reproducibleTimestamp.get());
} else {
return session.getStartTime();
}
}

@Override
Expand Down

0 comments on commit b45f8d8

Please sign in to comment.