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

Set snapshot timestamp #798

Merged
merged 2 commits into from
Jan 4, 2025
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
17 changes: 10 additions & 7 deletions src/main/java/org/vafer/jdeb/maven/DebMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -398,13 +399,13 @@ protected void setData( Data[] dataSet ) {
}

@SuppressWarnings("unchecked,rawtypes")
protected VariableResolver initializeVariableResolver( Map<String, String> variables ) {
protected VariableResolver initializeVariableResolver( Map<String, String> variables, Long outputTimestampMs ) {
variables.putAll((Map) getProject().getProperties());
variables.putAll((Map) System.getProperties());
variables.put("name", name != null ? name : getProject().getName());
variables.put("artifactId", getProject().getArtifactId());
variables.put("groupId", getProject().getGroupId());
variables.put("version", getProjectVersion());
variables.put("version", getProjectVersion(outputTimestampMs));
variables.put("description", getProject().getDescription());
variables.put("extension", "deb");
variables.put("baseDir", getProject().getBasedir().getAbsolutePath());
Expand Down Expand Up @@ -437,8 +438,9 @@ protected VariableResolver initializeVariableResolver( Map<String, String> varia
*
* @return the Maven project version
*/
private String getProjectVersion() {
return Utils.convertToDebianVersion(getProject().getVersion(), this.snapshotExpand, this.snapshotEnv, this.snapshotTemplate, session.getStartTime());
private String getProjectVersion(Long outputTimestampMs) {
Date buildTimeStamp = outputTimestampMs != null ? new Date(outputTimestampMs) : session.getStartTime();
return Utils.convertToDebianVersion(getProject().getVersion(), this.snapshotExpand, this.snapshotEnv, this.snapshotTemplate, buildTimeStamp);
}

/**
Expand Down Expand Up @@ -503,8 +505,10 @@ public void execute() throws MojoExecutionException {
console = new MojoConsole(getLog(), verbose);

initializeSignProperties();

Long outputTimestampMs = new OutputTimestampResolver(console).resolveOutputTimestamp(outputTimestamp);

final VariableResolver resolver = initializeVariableResolver(new HashMap<String, String>());
final VariableResolver resolver = initializeVariableResolver(new HashMap<String, String>(), outputTimestampMs);

final File debFile = new File(Utils.replaceVariables(resolver, deb, openReplaceToken, closeReplaceToken));
final File controlDirFile = new File(Utils.replaceVariables(resolver, controlDir, openReplaceToken, closeReplaceToken));
Expand Down Expand Up @@ -594,7 +598,6 @@ public void produce( final DataConsumer receiver ) {
debMaker.setDigest(digest);
debMaker.setTarBigNumberMode(tarBigNumberMode);
debMaker.setTarLongFileMode(tarLongFileMode);
Long outputTimestampMs = new OutputTimestampResolver(console).resolveOutputTimestamp(outputTimestamp);
debMaker.setOutputTimestampMs(outputTimestampMs);
debMaker.validate();
debMaker.makeDeb();
Expand All @@ -615,7 +618,7 @@ public void produce( final DataConsumer receiver ) {
}

if (!isBlank(propertyPrefix)) {
project.getProperties().put(propertyPrefix+"version", getProjectVersion() );
project.getProperties().put(propertyPrefix+"version", getProjectVersion(outputTimestampMs) );
project.getProperties().put(propertyPrefix+"deb", debFile.getAbsolutePath());
project.getProperties().put(propertyPrefix+"deb.name", debFile.getName());
project.getProperties().put(propertyPrefix+"changes", changesOutFile.getAbsolutePath());
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/vafer/jdeb/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,11 @@ private static String formatSnapshotTemplate( String template, Date timestamp )
return template;
} else {
// prefix[yyMMdd]suffix
final String date = new SimpleDateFormat(template.substring(startBracket + 1, endBracket)).format(timestamp);
SimpleDateFormat dateFormat = new SimpleDateFormat(template.substring(startBracket + 1, endBracket));
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String datePrefix = startBracket == 0 ? "" : template.substring(0, startBracket);
String dateSuffix = endBracket == template.length() ? "" : template.substring(endBracket + 1);
return datePrefix + date + dateSuffix;
return datePrefix + dateFormat.format(timestamp) + dateSuffix;
}
}

Expand Down
Loading