You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/05/01 15:54:56 UTC

[maven-javadoc-plugin] 01/01: [MJAVADOC-619] Maven Javadoc bottom claims copyright for future years

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

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

commit e77a783386342b3a0cdb9d56dbdb5c6c3d966093
Author: rfscholte <rf...@apache.org>
AuthorDate: Sat May 1 17:54:32 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 | 23 ++++++++++--
 .../maven/plugins/javadoc/JavadocUtilTest.java     |  2 +
 6 files changed, 135 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 ab51e51..303ef4f 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;
@@ -922,9 +924,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}. "
@@ -2954,8 +2959,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( "Missing property project.build.outputTimestamp, using current year instead" );
+            int currentYear = Calendar.getInstance().get( Calendar.YEAR );
+            year = String.valueOf( currentYear );
+        }
 
         String inceptionYear = project.getInceptionYear();
 
diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
index 8260d66..23e9482 100644
--- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
+++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocUtilTest.java
@@ -28,6 +28,8 @@ import java.net.URI;
 import java.net.URL;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoField;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;