Skip to content

Commit

Permalink
[MWAR-436] use outputTimestamp for jar created by archiveClasses
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Jun 13, 2020
1 parent c748932 commit 1619871
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/it/archiveClasses/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ under the License.

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputTimestamp>2020-06-06T06:50:15Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,16 @@ public abstract class AbstractWarMojo
@Parameter
private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();

/**
* 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 3.3.0
*/
@Parameter( defaultValue = "${project.build.outputTimestamp}" )
protected String outputTimestamp;

private final Overlay currentProjectOverlay = Overlay.createInstance();

/**
Expand Down Expand Up @@ -502,7 +512,8 @@ public void buildWebapp( MavenProject mavenProject, File webapplicationDirectory
final WarPackagingContext context =
new DefaultWarPackagingContext( webapplicationDirectory, structure, overlayManager, defaultFilterWrappers,
getNonFilteredFileExtensions(), filteringDeploymentDescriptors,
this.artifactFactory, resourceEncoding, useJvmChmod, failOnMissingWebXml );
this.artifactFactory, resourceEncoding, useJvmChmod, failOnMissingWebXml,
outputTimestamp );

final List<WarPackagingTask> packagingTasks = getPackagingTasks( overlayManager );

Expand Down Expand Up @@ -574,6 +585,8 @@ private class DefaultWarPackagingContext

private final Collection<String> outdatedResources;

private final String outputTimestamp;

/**
* @param webappDirectory The web application directory.
* @param webappStructure The web app structure.
Expand All @@ -585,14 +598,15 @@ private class DefaultWarPackagingContext
* @param resourceEncoding The resource encoding.
* @param useJvmChmod use Jvm chmod or not.
* @param failOnMissingWebXml Flag to check whether we should ignore missing web.xml or not
* @param outputTimestamp the output timestamp for reproducible archive creation
*/
DefaultWarPackagingContext( final File webappDirectory, final WebappStructure webappStructure,
final OverlayManager overlayManager,
List<FileUtils.FilterWrapper> filterWrappers,
List<String> nonFilteredFileExtensions,
boolean filteringDeploymentDescriptors, ArtifactFactory artifactFactory,
String resourceEncoding, boolean useJvmChmod,
final Boolean failOnMissingWebXml )
final Boolean failOnMissingWebXml, String outputTimestamp )
{
this.webappDirectory = webappDirectory;
this.webappStructure = webappStructure;
Expand Down Expand Up @@ -642,6 +656,7 @@ public FileVisitResult visitFile( Path file, BasicFileAttributes attrs )
getLog().warn( "Can't detect outdated resources", e );
}
}
this.outputTimestamp = outputTimestamp;
}

@Override
Expand Down Expand Up @@ -815,6 +830,12 @@ public void deleteOutdatedResources()
new File( getWebappDirectory(), resource ).delete();
}
}

@Override
public String getOutputTimestamp()
{
return outputTimestamp;
}
}

/**
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/org/apache/maven/plugins/war/WarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,6 @@ public class WarMojo
@Parameter( property = "maven.war.skip", defaultValue = "false" )
private boolean skip;

/**
* 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 3.3.0
*/
@Parameter( defaultValue = "${project.build.outputTimestamp}" )
private String outputTimestamp;

// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -276,7 +266,7 @@ private void performPackaging( File warFile )
{
getLog().info( "Packaging classes" );
packager.packageClasses( classesDirectory, getTargetClassesFile(), getJarArchiver(), getSession(),
getProject(), getArchive() );
getProject(), getArchive(), outputTimestamp );
projectHelper.attachArtifact( getProject(), "jar", getClassesClassifier(), getTargetClassesFile() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ protected void generateJarArchive( WarPackagingContext context )
final File jarFile = new File( libDirectory, archiveName );
final ClassesPackager packager = new ClassesPackager();
packager.packageClasses( context.getClassesDirectory(), jarFile, context.getJarArchiver(),
context.getSession(), project, context.getArchive() );
context.getSession(), project, context.getArchive(),
context.getOutputTimestamp() );
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,12 @@ public interface WarPackagingContext
* @see #addResource
*/
void deleteOutdatedResources();

/**
* Output timestamp for reproducible archive creation.
*
* @return the output timestamp (may be null)
* @since 3.3.0
*/
String getOutputTimestamp();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public class ClassesPackager
* @param session the current session
* @param project the related project
* @param archiveConfiguration the archive configuration to use
* @param outputTimestamp the output timestamp for reproducibility
* @throws MojoExecutionException if an error occurred while creating the archive
*/
public void packageClasses( File classesDirectory, File targetFile, JarArchiver jarArchiver, MavenSession session,
MavenProject project, MavenArchiveConfiguration archiveConfiguration )
MavenProject project, MavenArchiveConfiguration archiveConfiguration,
String outputTimestamp )
throws MojoExecutionException
{

Expand All @@ -62,6 +64,8 @@ public void packageClasses( File classesDirectory, File targetFile, JarArchiver
final MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver( jarArchiver );
archiver.setOutputFile( targetFile );
archiver.setCreatedBy( "Maven WAR Plugin", "org.apache.maven.plugins", "maven-war-plugin" );
archiver.configureReproducible( outputTimestamp );
archiver.getArchiver().addDirectory( classesDirectory );
archiver.createArchive( session, project, archiveConfiguration );
}
Expand Down

0 comments on commit 1619871

Please sign in to comment.