From 98a7387661051b56e29a933106e6cf7e049bff7f Mon Sep 17 00:00:00 2001 From: Roman Huber <26764588+alerosmile@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:26:12 +0100 Subject: [PATCH 1/2] Use project.build.outputTimestamp in snapshot version timestamp. --- src/main/java/org/vafer/jdeb/maven/DebMojo.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/vafer/jdeb/maven/DebMojo.java b/src/main/java/org/vafer/jdeb/maven/DebMojo.java index ca98c1547..4ab8d52b8 100644 --- a/src/main/java/org/vafer/jdeb/maven/DebMojo.java +++ b/src/main/java/org/vafer/jdeb/maven/DebMojo.java @@ -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; @@ -398,13 +399,13 @@ protected void setData( Data[] dataSet ) { } @SuppressWarnings("unchecked,rawtypes") - protected VariableResolver initializeVariableResolver( Map variables ) { + protected VariableResolver initializeVariableResolver( Map 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()); @@ -437,8 +438,9 @@ protected VariableResolver initializeVariableResolver( Map 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); } /** @@ -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()); + final VariableResolver resolver = initializeVariableResolver(new HashMap(), outputTimestampMs); final File debFile = new File(Utils.replaceVariables(resolver, deb, openReplaceToken, closeReplaceToken)); final File controlDirFile = new File(Utils.replaceVariables(resolver, controlDir, openReplaceToken, closeReplaceToken)); @@ -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(); @@ -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()); From 268eab1d4b93ff3bff72c4025f893b9fb2521dfc Mon Sep 17 00:00:00 2001 From: Roman Huber <26764588+alerosmile@users.noreply.github.com> Date: Fri, 3 Jan 2025 17:29:55 +0100 Subject: [PATCH 2/2] Set snapshot timestamp to UTC. --- src/main/java/org/vafer/jdeb/utils/Utils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/vafer/jdeb/utils/Utils.java b/src/main/java/org/vafer/jdeb/utils/Utils.java index 396a045fe..e77aeaabf 100644 --- a/src/main/java/org/vafer/jdeb/utils/Utils.java +++ b/src/main/java/org/vafer/jdeb/utils/Utils.java @@ -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; } }