Skip to content

Commit

Permalink
Support reproducible builds
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo committed Apr 10, 2024
1 parent 74ea7f6 commit 6004b1f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/io/trino/maven/ServiceDescriptorGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 6004b1f

Please sign in to comment.