Skip to content

Commit

Permalink
MJAVADOC-627 make output jars reproducible like m-source-p
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Nov 10, 2019
1 parent 112f5a5 commit b1b28fe
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 60 deletions.
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ under the License.
</parent>

<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.2-SNAPSHOT</version>
<version>3.2.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Apache Maven Javadoc Plugin</name>
Expand Down Expand Up @@ -177,7 +177,7 @@ under the License.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
<version>3.2.0</version>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
Expand Down Expand Up @@ -248,17 +248,17 @@ under the License.
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>3.6.0</version>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-io</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.24</version>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
Expand Down
47 changes: 0 additions & 47 deletions src/it/projects/MJAVADOC-137/verify.bsh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputTimestamp>2019-11-02T17:48:12Z</project.build.outputTimestamp>
</properties>

<build>
Expand Down
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions src/it/projects/MJAVADOC-137_jar/verify.bsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.io.*;
import java.util.*;
import java.util.jar.*;

boolean result = true;

try
{
File target1 = new File( basedir, "test1/target/test1-1.0-SNAPSHOT-javadoc.jar" );
if ( !target1.exists() )
{
System.err.println( "Javadoc jar for module test1 is missing." );
return false;
}

File target2 = new File( basedir, "test2/target/test2-1.0-SNAPSHOT-javadoc.jar" );
if ( !target2.exists() )
{
System.err.println( "Javadoc jar for module test2 is missing." );
return false;
}

JarFile jar = new JarFile( target1 );
Enumeration jarEntries = jar.entries();
long timestamp = -1;
while ( jarEntries.hasMoreElements() )
{
JarEntry entry = (JarEntry) jarEntries.nextElement();
if ( timestamp == -1 )
{
timestamp = entry.getTime(); // reproducible timestamp in jar file cause local timestamp depending on timezone
}
if ( entry.getTime() != timestamp )
{
System.out.println( "wrong entry time for " + entry.getName() + ": " + entry.getTime() + " instead of " + timestamp );
return false;
}
}
jarEntries = new JarFile( target1 ).entries();
while ( jarEntries.hasMoreElements() )
{
JarEntry entry = (JarEntry) jarEntries.nextElement();
if ( entry.getTime() != timestamp )
{
System.out.println( "wrong entry time for " + entry.getName() + ": " + entry.getTime() + " instead of " + timestamp );
return false;
}
}
}
catch( IOException e )
{
e.printStackTrace();
result = false;
}

return result;
14 changes: 14 additions & 0 deletions src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ public class JavadocJar
@Parameter( property = "maven.javadoc.classifier", defaultValue = "javadoc", required = true )
private String classifier;

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

/** {@inheritDoc} */
@Override
public void doExecute()
Expand Down Expand Up @@ -265,9 +275,13 @@ private File generateArchive( File javadocFiles, String jarFileName )
}

MavenArchiver archiver = new MavenArchiver();
archiver.setCreatedBy( "Maven Javadoc Plugin", "org.apache.maven.plugins", "maven-javadoc-plugin" );
archiver.setArchiver( jarArchiver );
archiver.setOutputFile( javadocJar );

// configure for Reproducible Builds based on outputTimestamp value
archiver.configureReproducible( outputTimestamp );

if ( !javadocFiles.exists() )
{
getLog().warn( "JAR will be empty - no content was marked for inclusion!" );
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1080,14 +1080,21 @@ private static InvocationResult invoke( Log log, Invoker invoker, InvocationRequ
InvocationOutputHandler outputHandler = new PrintStreamHandler( ps, false );
request.setOutputHandler( outputHandler );

outputHandler.consumeLine( "Invoking Maven for the goals: " + goals + " with "
+ ( properties == null ? "no properties" : "properties=" + properties ) );
outputHandler.consumeLine( "" );
outputHandler.consumeLine( "M2_HOME=" + getMavenHome( log ) );
outputHandler.consumeLine( "MAVEN_OPTS=" + getMavenOpts( log ) );
outputHandler.consumeLine( "JAVA_HOME=" + getJavaHome( log ) );
outputHandler.consumeLine( "JAVA_OPTS=" + getJavaOpts( log ) );
outputHandler.consumeLine( "" );
try
{
outputHandler.consumeLine( "Invoking Maven for the goals: " + goals + " with "
+ ( properties == null ? "no properties" : "properties=" + properties ) );
outputHandler.consumeLine( "" );
outputHandler.consumeLine( "M2_HOME=" + getMavenHome( log ) );
outputHandler.consumeLine( "MAVEN_OPTS=" + getMavenOpts( log ) );
outputHandler.consumeLine( "JAVA_HOME=" + getJavaHome( log ) );
outputHandler.consumeLine( "JAVA_OPTS=" + getJavaOpts( log ) );
outputHandler.consumeLine( "" );
}
catch ( IOException ioe )
{
throw new MavenInvocationException( "IOException while consuming invocation output", ioe );
}

try
{
Expand Down

0 comments on commit b1b28fe

Please sign in to comment.