Skip to content

Commit

Permalink
[MJAVADOC-619] Maven Javadoc bottom claims copyright for future years
Browse files Browse the repository at this point in the history
  • Loading branch information
rfscholte committed May 7, 2021
1 parent 15a02d6 commit 3926bd4
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/it/projects/MJAVADOC-619_copyright-year/invoker.properties
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions src/it/projects/MJAVADOC-619_copyright-year/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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" );
}

}
22 changes: 22 additions & 0 deletions src/it/projects/MJAVADOC-619_copyright-year/verify.groovy
Original file line number Diff line number Diff line change
@@ -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.'")
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}. "
Expand Down Expand Up @@ -2977,8 +2987,18 @@ private void populateCompileArtifactMap( Map<String, Artifact> 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();

Expand Down

0 comments on commit 3926bd4

Please sign in to comment.