Skip to content

Commit 6004b1f

Browse files
committed
Support reproducible builds
1 parent 74ea7f6 commit 6004b1f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/main/java/io/trino/maven/ServiceDescriptorGenerator.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import java.io.IOException;
2929
import java.net.URL;
3030
import java.net.URLClassLoader;
31+
import java.text.DateFormat;
32+
import java.text.ParseException;
33+
import java.text.SimpleDateFormat;
3134
import java.util.ArrayList;
3235
import java.util.List;
3336
import java.util.jar.JarEntry;
@@ -46,6 +49,7 @@ public class ServiceDescriptorGenerator
4649
extends AbstractMojo
4750
{
4851
private static final String LS = System.lineSeparator();
52+
private static final DateFormat OUTPUT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
4953

5054
@Parameter(defaultValue = "io.trino.spi.Plugin")
5155
private String pluginClassName;
@@ -59,6 +63,9 @@ public class ServiceDescriptorGenerator
5963
@Parameter(defaultValue = "${project.build.outputDirectory}")
6064
private File classesDirectory;
6165

66+
@Parameter(defaultValue = "${project.build.outputTimestamp}")
67+
private String outputTimestamp;
68+
6269
@Parameter(defaultValue = "${project}")
6370
private MavenProject project;
6471

@@ -96,7 +103,18 @@ public void execute()
96103

97104
try (FileOutputStream out = new FileOutputStream(servicesJar);
98105
JarOutputStream jar = new JarOutputStream(out)) {
99-
jar.putNextEntry(new JarEntry("META-INF/services/" + pluginClassName));
106+
107+
JarEntry jarEntry = new JarEntry("META-INF/services/" + pluginClassName);
108+
if (outputTimestamp != null && !outputTimestamp.isBlank()) {
109+
try {
110+
jarEntry.setTime(OUTPUT_DATE_FORMAT.parse(outputTimestamp).getTime());
111+
}
112+
catch (ParseException e) {
113+
throw new RuntimeException("Could not parse outputTimestamp: " + outputTimestamp, e);
114+
}
115+
}
116+
117+
jar.putNextEntry(jarEntry);
100118
jar.write(servicesFileData);
101119
jar.closeEntry();
102120
}

0 commit comments

Comments
 (0)