[maven-javadoc-plugin] branch master updated: MJAVADOC-627 make output jars reproducible like m-source-p

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[maven-javadoc-plugin] branch master updated: MJAVADOC-627 make output jars reproducible like m-source-p

hboutemy
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new b1b28fe  MJAVADOC-627 make output jars reproducible like m-source-p
b1b28fe is described below

commit b1b28fe72ec89d42856f4c046421076169073946
Author: Hervé Boutemy <[hidden email]>
AuthorDate: Sun Nov 10 13:42:35 2019 +0100

    MJAVADOC-627 make output jars reproducible like m-source-p
---
 pom.xml                                            | 10 +--
 src/it/projects/MJAVADOC-137/verify.bsh            | 47 -------------
 .../invoker.properties                             |  0
 .../{MJAVADOC-137 => MJAVADOC-137_jar}/pom.xml     |  1 +
 .../test1/pom.xml                                  |  0
 .../test1}/src/main/java/com/example/App.java      |  0
 .../test2/pom.xml                                  |  0
 .../test2}/src/main/java/com/example/App.java      |  0
 src/it/projects/MJAVADOC-137_jar/verify.bsh        | 76 ++++++++++++++++++++++
 .../apache/maven/plugins/javadoc/JavadocJar.java   | 14 ++++
 .../apache/maven/plugins/javadoc/JavadocUtil.java  | 23 ++++---
 11 files changed, 111 insertions(+), 60 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0bb2616..4ac6f93 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
@@ -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>
@@ -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>
diff --git a/src/it/projects/MJAVADOC-137/verify.bsh b/src/it/projects/MJAVADOC-137/verify.bsh
deleted file mode 100644
index 7d2d4c0..0000000
--- a/src/it/projects/MJAVADOC-137/verify.bsh
+++ /dev/null
@@ -1,47 +0,0 @@
-
-/*
- * 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.*;
-
-boolean result = true;
-
-try
-{
-    File target = new File( basedir, "test1/target/test1-1.0-SNAPSHOT-javadoc.jar" );
-    if ( !target.exists() )
-    {
-        System.err.println( "Javadoc jar for module test1 is missing." );
-        return false;
-    }
-
-    File target = new File( basedir, "test2/target/test2-1.0-SNAPSHOT-javadoc.jar" );
-    if ( !target.exists() )
-    {
-        System.err.println( "Javadoc jar for module test2 is missing." );
-        return false;
-    }
-}
-catch( IOException e )
-{
-    e.printStackTrace();
-    result = false;
-}
-
-return result;
diff --git a/src/it/projects/MJAVADOC-137/invoker.properties b/src/it/projects/MJAVADOC-137_jar/invoker.properties
similarity index 100%
rename from src/it/projects/MJAVADOC-137/invoker.properties
rename to src/it/projects/MJAVADOC-137_jar/invoker.properties
diff --git a/src/it/projects/MJAVADOC-137/pom.xml b/src/it/projects/MJAVADOC-137_jar/pom.xml
similarity index 93%
rename from src/it/projects/MJAVADOC-137/pom.xml
rename to src/it/projects/MJAVADOC-137_jar/pom.xml
index 8b8d773..73c5ca9 100644
--- a/src/it/projects/MJAVADOC-137/pom.xml
+++ b/src/it/projects/MJAVADOC-137_jar/pom.xml
@@ -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>
diff --git a/src/it/projects/MJAVADOC-137/test1/pom.xml b/src/it/projects/MJAVADOC-137_jar/test1/pom.xml
similarity index 100%
rename from src/it/projects/MJAVADOC-137/test1/pom.xml
rename to src/it/projects/MJAVADOC-137_jar/test1/pom.xml
diff --git a/src/it/projects/MJAVADOC-137/test2/src/main/java/com/example/App.java b/src/it/projects/MJAVADOC-137_jar/test1/src/main/java/com/example/App.java
similarity index 100%
rename from src/it/projects/MJAVADOC-137/test2/src/main/java/com/example/App.java
rename to src/it/projects/MJAVADOC-137_jar/test1/src/main/java/com/example/App.java
diff --git a/src/it/projects/MJAVADOC-137/test2/pom.xml b/src/it/projects/MJAVADOC-137_jar/test2/pom.xml
similarity index 100%
rename from src/it/projects/MJAVADOC-137/test2/pom.xml
rename to src/it/projects/MJAVADOC-137_jar/test2/pom.xml
diff --git a/src/it/projects/MJAVADOC-137/test1/src/main/java/com/example/App.java b/src/it/projects/MJAVADOC-137_jar/test2/src/main/java/com/example/App.java
similarity index 100%
rename from src/it/projects/MJAVADOC-137/test1/src/main/java/com/example/App.java
rename to src/it/projects/MJAVADOC-137_jar/test2/src/main/java/com/example/App.java
diff --git a/src/it/projects/MJAVADOC-137_jar/verify.bsh b/src/it/projects/MJAVADOC-137_jar/verify.bsh
new file mode 100644
index 0000000..6fa71a3
--- /dev/null
+++ b/src/it/projects/MJAVADOC-137_jar/verify.bsh
@@ -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;
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
index 97dca13..d923983 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
@@ -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()
@@ -265,9 +275,13 @@ public class JavadocJar
         }
 
         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!" );
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
index 7767b31..997c5ed 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocUtil.java
@@ -1080,14 +1080,21 @@ public class JavadocUtil
         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
         {