Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes update of outputTimestamp property optional #310

Merged
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ To configure your Maven build to support reproducible builds follow [official gu

If your project has `project.build.outputTimestamp` property this plugin will update its value whenever the versions are updated.

This can be disabled by setting the configuration parameter `updateOutputTimestamp` to `false`.


# Plugin Common Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo {
@Parameter(defaultValue = "${session}", readonly = true)
protected MavenSession mavenSession;

/**
* Whether to update the <code>project.build.outputTimestamp</code> property automatically or not.
*
* @since 1.16.1
*/
@Parameter(property = "updateOutputTimestamp", defaultValue = "true")
private boolean updateOutputTimestamp = true;

@Component
protected ProjectBuilder projectBuilder;

Expand Down Expand Up @@ -1056,22 +1064,24 @@ protected void mvnSetVersions(final String version) throws MojoFailureException,
if (runCommand) {
executeMvnCommand(args.toArray(new String[0]));

String timestamp = getCurrentProjectOutputTimestamp();
if (timestamp != null && timestamp.length() > 1) {
if (StringUtils.isNumeric(timestamp)) {
// int representing seconds since the epoch
timestamp = String.valueOf(System.currentTimeMillis() / 1000l);
} else {
// ISO-8601
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
timestamp = df.format(new Date());
if (updateOutputTimestamp) {
String timestamp = getCurrentProjectOutputTimestamp();
if (timestamp != null && timestamp.length() > 1) {
if (StringUtils.isNumeric(timestamp)) {
// int representing seconds since the epoch
timestamp = String.valueOf(System.currentTimeMillis() / 1000l);
} else {
// ISO-8601
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
timestamp = df.format(new Date());
}

getLog().info("Updating property '" + REPRODUCIBLE_BUILDS_PROPERTY + "' to '" + timestamp + "'.");

executeMvnCommand(VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL, "-DgenerateBackupPoms=false",
"-Dproperty=" + REPRODUCIBLE_BUILDS_PROPERTY, "-DnewVersion=" + timestamp);
}

getLog().info("Updating property '" + REPRODUCIBLE_BUILDS_PROPERTY + "' to '" + timestamp + "'.");

executeMvnCommand(VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL, "-DgenerateBackupPoms=false",
"-Dproperty=" + REPRODUCIBLE_BUILDS_PROPERTY, "-DnewVersion=" + timestamp);
}
}
}
Expand Down