Skip to content

Commit

Permalink
JAR and JPI creation is nondeterministic (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Apr 12, 2024
1 parent 47b996d commit 77ae644
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
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

0 comments on commit 77ae644

Please sign in to comment.