Skip to content

Commit 3926bd4

Browse files
committed
[MJAVADOC-619] Maven Javadoc bottom claims copyright for future years
1 parent 15a02d6 commit 3926bd4

File tree

5 files changed

+138
-4
lines changed

5 files changed

+138
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
invoker.goals = compile javadoc:javadoc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<groupId>foo</groupId>
26+
<artifactId>bar</artifactId>
27+
<version>0.1.0-SNAPSHOT</version>
28+
29+
<properties>
30+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31+
<project.build.outputTimestamp>2020-03-12T06:39:23Z</project.build.outputTimestamp>
32+
</properties>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-javadoc-plugin</artifactId>
39+
<version>@project.version@</version>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package foo;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
/**
23+
* Bar.
24+
*/
25+
public class Bar
26+
{
27+
public void run()
28+
{
29+
System.out.println( "Bar" );
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
def file = new File( basedir, 'target/site/apidocs/options' )
21+
22+
assert file.text.contains("'Copyright &#169; 2020. All rights reserved.'")

src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java

+24-4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
import java.nio.file.Files;
118118
import java.nio.file.Path;
119119
import java.nio.file.StandardCopyOption;
120+
import java.time.format.DateTimeFormatter;
121+
import java.time.temporal.ChronoField;
120122
import java.util.ArrayList;
121123
import java.util.Arrays;
122124
import java.util.Calendar;
@@ -155,6 +157,11 @@
155157
public abstract class AbstractJavadocMojo
156158
extends AbstractMojo
157159
{
160+
/**
161+
* Property with timestamp used for reproducible builds
162+
*/
163+
private static final String PROJECT_BUILD_OUTPUTTIMESTAMP = "project.build.outputTimestamp";
164+
158165
/**
159166
* Classifier used in the name of the javadoc-options XML file, and in the resources bundle
160167
* artifact that gets attached to the project. This one is used for non-test javadocs.
@@ -923,9 +930,12 @@ public abstract class AbstractJavadocMojo
923930
* Specifies the text to be placed at the bottom of each output file.<br/>
924931
* If you want to use html, you have to put it in a CDATA section, <br/>
925932
* e.g. <code>&lt;![CDATA[Copyright 2005, &lt;a href="http://www.mycompany.com">MyCompany, Inc.&lt;a>]]&gt;</code>
926-
* <br/>
933+
* <br>
934+
* <strong>Note:<strong>If the project has the property <code>project.build.outputTimestamp</code>, its year will
935+
* be used as {currentYear}. This way it is possible to generate reproducible javadoc jars.
936+
* <br>
927937
* See <a href="https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#bottom">bottom</a>.
928-
* <br/>
938+
* <br>
929939
*/
930940
@Parameter( property = "bottom",
931941
defaultValue = "Copyright &#169; {inceptionYear}&#x2013;{currentYear} {organizationName}. "
@@ -2977,8 +2987,18 @@ private void populateCompileArtifactMap( Map<String, Artifact> compileArtifactMa
29772987
*/
29782988
private String getBottomText()
29792989
{
2980-
int currentYear = Calendar.getInstance().get( Calendar.YEAR );
2981-
String year = String.valueOf( currentYear );
2990+
final String year;
2991+
String buildTime = project.getProperties().getProperty( PROJECT_BUILD_OUTPUTTIMESTAMP );
2992+
if ( buildTime != null )
2993+
{
2994+
year = String.valueOf( DateTimeFormatter.ISO_DATE_TIME.parse( buildTime ).get( ChronoField.YEAR ) );
2995+
}
2996+
else
2997+
{
2998+
getLog().debug( "Using current year due to unavailable property '" + PROJECT_BUILD_OUTPUTTIMESTAMP + "'" );
2999+
int currentYear = Calendar.getInstance().get( Calendar.YEAR );
3000+
year = String.valueOf( currentYear );
3001+
}
29823002

29833003
String inceptionYear = project.getInceptionYear();
29843004

0 commit comments

Comments
 (0)