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

Support reproducible builds #24

Merged
merged 1 commit into from
Apr 10, 2024
Merged
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
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}")
wendigo marked this conversation as resolved.
Show resolved Hide resolved
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
Loading