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

rfscholte 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 3926bd4  [MJAVADOC-619] Maven Javadoc bottom claims copyright for 
future years
3926bd4 is described below

commit 3926bd4cadaa6e4c49c7f973f04927602e384d40
Author: rfscholte <rfscho...@apache.org>
AuthorDate: Fri May 7 13:03:22 2021 +0200

    [MJAVADOC-619] Maven Javadoc bottom claims copyright for future years
---
 .../MJAVADOC-619_copyright-year/invoker.properties | 17 +++++++++
 .../projects/MJAVADOC-619_copyright-year/pom.xml   | 43 ++++++++++++++++++++++
 .../src/main/java/foo/Bar.java                     | 32 ++++++++++++++++
 .../MJAVADOC-619_copyright-year/verify.groovy      | 22 +++++++++++
 .../maven/plugins/javadoc/AbstractJavadocMojo.java | 28 ++++++++++++--
 5 files changed, 138 insertions(+), 4 deletions(-)

diff --git a/src/it/projects/MJAVADOC-619_copyright-year/invoker.properties 
b/src/it/projects/MJAVADOC-619_copyright-year/invoker.properties
new file mode 100644
index 0000000..7a948bb
--- /dev/null
+++ b/src/it/projects/MJAVADOC-619_copyright-year/invoker.properties
@@ -0,0 +1,17 @@
+# 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.
+invoker.goals = compile javadoc:javadoc
diff --git a/src/it/projects/MJAVADOC-619_copyright-year/pom.xml 
b/src/it/projects/MJAVADOC-619_copyright-year/pom.xml
new file mode 100644
index 0000000..d009ed4
--- /dev/null
+++ b/src/it/projects/MJAVADOC-619_copyright-year/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>foo</groupId>
+  <artifactId>bar</artifactId>
+  <version>0.1.0-SNAPSHOT</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    
<project.build.outputTimestamp>2020-03-12T06:39:23Z</project.build.outputTimestamp>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/src/it/projects/MJAVADOC-619_copyright-year/src/main/java/foo/Bar.java 
b/src/it/projects/MJAVADOC-619_copyright-year/src/main/java/foo/Bar.java
new file mode 100644
index 0000000..e68b704
--- /dev/null
+++ b/src/it/projects/MJAVADOC-619_copyright-year/src/main/java/foo/Bar.java
@@ -0,0 +1,32 @@
+package foo;
+
+/*
+ * 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.
+ */
+
+/**
+ * Bar.
+ */
+public class Bar
+{
+    public void run()
+    {
+        System.out.println( "Bar" );
+    }
+
+}
diff --git a/src/it/projects/MJAVADOC-619_copyright-year/verify.groovy 
b/src/it/projects/MJAVADOC-619_copyright-year/verify.groovy
new file mode 100644
index 0000000..525b39c
--- /dev/null
+++ b/src/it/projects/MJAVADOC-619_copyright-year/verify.groovy
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+def file = new File( basedir, 'target/site/apidocs/options' )
+
+assert file.text.contains("'Copyright &#169; 2020. All rights reserved.'")
diff --git 
a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java 
b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index db58e77..0dbd61a 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -117,6 +117,8 @@ import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoField;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -156,6 +158,11 @@ public abstract class AbstractJavadocMojo
     extends AbstractMojo
 {
     /**
+     * Property with timestamp used for reproducible builds
+     */
+    private static final String PROJECT_BUILD_OUTPUTTIMESTAMP = 
"project.build.outputTimestamp";
+
+    /**
      * Classifier used in the name of the javadoc-options XML file, and in the 
resources bundle
      * artifact that gets attached to the project. This one is used for 
non-test javadocs.
      *
@@ -923,9 +930,12 @@ public abstract class AbstractJavadocMojo
      * Specifies the text to be placed at the bottom of each output file.<br/>
      * If you want to use html, you have to put it in a CDATA section, <br/>
      * e.g. <code>&lt;![CDATA[Copyright 2005, &lt;a 
href="http://www.mycompany.com";>MyCompany, Inc.&lt;a>]]&gt;</code>
-     * <br/>
+     * <br>
+     * <strong>Note:<strong>If the project has the property 
<code>project.build.outputTimestamp</code>, its year will
+     * be used as {currentYear}. This way it is possible to generate 
reproducible javadoc jars.
+     * <br>
      * See <a 
href="https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#bottom";>bottom</a>.
-     * <br/>
+     * <br>
      */
     @Parameter( property = "bottom",
                     defaultValue = "Copyright &#169; 
{inceptionYear}&#x2013;{currentYear} {organizationName}. "
@@ -2977,8 +2987,18 @@ public abstract class AbstractJavadocMojo
      */
     private String getBottomText()
     {
-        int currentYear = Calendar.getInstance().get( Calendar.YEAR );
-        String year = String.valueOf( currentYear );
+        final String year;
+        String buildTime = project.getProperties().getProperty( 
PROJECT_BUILD_OUTPUTTIMESTAMP );
+        if ( buildTime != null )
+        {
+            year = String.valueOf( DateTimeFormatter.ISO_DATE_TIME.parse( 
buildTime ).get( ChronoField.YEAR ) );
+        }
+        else
+        {
+            getLog().debug( "Using current year due to unavailable property '" 
+ PROJECT_BUILD_OUTPUTTIMESTAMP + "'" );
+            int currentYear = Calendar.getInstance().get( Calendar.YEAR );
+            year = String.valueOf( currentYear );
+        }
 
         String inceptionYear = project.getInceptionYear();
 

Reply via email to