From 6004b1fadb4b3cc0a1ddfd3860fdb0e181135c8a Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Wed, 10 Apr 2024 13:29:45 +0200 Subject: [PATCH] Support reproducible builds --- .../maven/ServiceDescriptorGenerator.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/trino/maven/ServiceDescriptorGenerator.java b/src/main/java/io/trino/maven/ServiceDescriptorGenerator.java index e4e8617..ba251f5 100644 --- a/src/main/java/io/trino/maven/ServiceDescriptorGenerator.java +++ b/src/main/java/io/trino/maven/ServiceDescriptorGenerator.java @@ -28,6 +28,9 @@ import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import java.util.jar.JarEntry; @@ -46,6 +49,7 @@ public class ServiceDescriptorGenerator extends AbstractMojo { private static final String LS = System.lineSeparator(); + private static final DateFormat OUTPUT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX"); @Parameter(defaultValue = "io.trino.spi.Plugin") private String pluginClassName; @@ -59,6 +63,9 @@ public class ServiceDescriptorGenerator @Parameter(defaultValue = "${project.build.outputDirectory}") private File classesDirectory; + @Parameter(defaultValue = "${project.build.outputTimestamp}") + private String outputTimestamp; + @Parameter(defaultValue = "${project}") private MavenProject project; @@ -96,7 +103,18 @@ public void execute() try (FileOutputStream out = new FileOutputStream(servicesJar); JarOutputStream jar = new JarOutputStream(out)) { - jar.putNextEntry(new JarEntry("META-INF/services/" + pluginClassName)); + + JarEntry jarEntry = new JarEntry("META-INF/services/" + pluginClassName); + if (outputTimestamp != null && !outputTimestamp.isBlank()) { + try { + jarEntry.setTime(OUTPUT_DATE_FORMAT.parse(outputTimestamp).getTime()); + } + catch (ParseException e) { + throw new RuntimeException("Could not parse outputTimestamp: " + outputTimestamp, e); + } + } + + jar.putNextEntry(jarEntry); jar.write(servicesFileData); jar.closeEntry(); }