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

JAR and JPI creation is nondeterministic #599

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.jar.Manifest;
import org.codehaus.plexus.archiver.jar.ManifestException;

Expand All @@ -64,6 +65,16 @@ public abstract class AbstractJenkinsManifestMojo extends AbstractHpiMojo {
@Parameter(property = "hpi.compatibleSinceVersion")
private String compatibleSinceVersion;

/**
* Timestamp for reproducible output archive entries, either formatted as ISO 8601
* <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
* <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
*
* @since TODO
*/
@Parameter(defaultValue = "${project.build.outputTimestamp}")
private String outputTimestamp;

/**
* Optional - sandbox status of this plugin.
*/
Expand All @@ -79,6 +90,19 @@ public abstract class AbstractJenkinsManifestMojo extends AbstractHpiMojo {
@Parameter
protected String minimumJavaVersion;

/**
* @return an instance of {@link MavenArchiver} preconfigured for reproducible builds
*
* @since TODO
*/
protected MavenArchiver newMavenArchiver(JarArchiver jarArchiver, File outputFile) {
MavenArchiver mavenArchiver = new MavenArchiver();
mavenArchiver.setArchiver(jarArchiver);
mavenArchiver.setOutputFile(outputFile);
mavenArchiver.configureReproducibleBuild(outputTimestamp);
return mavenArchiver;
}

/**
* Generates a manifest file to be included in the .hpi file
*/
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/HpiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ private void performPackaging()
// create a jar file to be used when other plugins depend on this plugin.
jarFile = getOutputFile(".jar");
getLog().info("Generating jar " + jarFile.getAbsolutePath());
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
MavenArchiver archiver = newMavenArchiver(jarArchiver, jarFile);
jarArchiver.addConfiguredManifest(manifest);
File indexJelly = new File(getClassesDirectory(), "index.jelly");
if (!indexJelly.isFile()) {
Expand Down Expand Up @@ -165,10 +163,7 @@ private void performPackaging()
File hpiFile = getOutputFile(".hpi");
getLog().info("Generating hpi " + hpiFile.getAbsolutePath());

MavenArchiver archiver = new MavenArchiver();

archiver.setArchiver(hpiArchiver);
archiver.setOutputFile(hpiFile);
MavenArchiver archiver = newMavenArchiver(hpiArchiver, hpiFile);

hpiArchiver.addConfiguredManifest(manifest);
hpiArchiver.addDirectory(getWebappDirectory(), getIncludes(), getExcludes());
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/JarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ private void performPackaging()

// create a jar file to be used when other plugins depend on this plugin.
File jarFile = getOutputFile(".jar");
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(jarFile);
MavenArchiver archiver = newMavenArchiver(jarArchiver, jarFile);
jarArchiver.addConfiguredManifest(manifest);
jarArchiver.addDirectory(getClassesDirectory());
archiver.createArchive(session, project, archive);
Expand Down