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 000000000..7a948bb3e --- /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 000000000..d009ed4c4 --- /dev/null +++ b/src/it/projects/MJAVADOC-619_copyright-year/pom.xml @@ -0,0 +1,43 @@ + + + + 4.0.0 + + foo + bar + 0.1.0-SNAPSHOT + + + UTF-8 + 2020-03-12T06:39:23Z + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + @project.version@ + + + + 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 000000000..e68b7043a --- /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 000000000..525b39c02 --- /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 © 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 db58e7750..0dbd61a4c 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.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; @@ -155,6 +157,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.
* If you want to use html, you have to put it in a CDATA section,
* e.g. <![CDATA[Copyright 2005, <a href="http://www.mycompany.com">MyCompany, Inc.<a>]]> - *
+ *
+ * Note:If the project has the property project.build.outputTimestamp, its year will + * be used as {currentYear}. This way it is possible to generate reproducible javadoc jars. + *
* See bottom. - *
+ *
*/ @Parameter( property = "bottom", defaultValue = "Copyright © {inceptionYear}–{currentYear} {organizationName}. " @@ -2977,8 +2987,18 @@ private void populateCompileArtifactMap( Map compileArtifactMa */ 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();