[MJAVADOC-684] use MavenArchiver.parseOutputTimestamp(...) API
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 0655f8a..6c513a2 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -22,6 +22,7 @@
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.handler.ArtifactHandler;
@@ -117,13 +118,12 @@
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;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -158,11 +158,6 @@
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.
*
@@ -1831,6 +1826,16 @@
@Parameter( property = "maven.javadoc.skippedModules" )
private String skippedModules;
+ /**
+ * Timestamp for reproducible output archive entries, either formatted as ISO 8601
+ * <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
+ * <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
+ *
+ * @since 3.2.0
+ */
+ @Parameter( defaultValue = "${project.build.outputTimestamp}" )
+ protected String outputTimestamp;
+
// ----------------------------------------------------------------------
// protected methods
// ----------------------------------------------------------------------
@@ -3000,38 +3005,27 @@
*/
private String getBottomText()
{
- 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 );
- }
+ final String inceptionYear = project.getInceptionYear();
- String inceptionYear = project.getInceptionYear();
-
- String theBottom = StringUtils.replace( this.bottom, "{currentYear}", year );
-
- if ( inceptionYear != null )
+ // get Reproducible Builds outputTimestamp value
+ final Calendar currentYearCal = Calendar.getInstance();
+ final Date reproducibleDate = new MavenArchiver().parseOutputTimestamp( outputTimestamp );
+ if ( reproducibleDate != null )
{
- if ( inceptionYear.equals( year ) )
- {
- theBottom = StringUtils.replace( theBottom, "{inceptionYear}–", "" );
- }
- else
- {
- theBottom = StringUtils.replace( theBottom, "{inceptionYear}", inceptionYear );
- }
+ currentYearCal.setTime( reproducibleDate );
}
- else
+ final String currentYear = String.valueOf( currentYearCal.get( Calendar.YEAR ) );
+
+ String theBottom = StringUtils.replace( this.bottom, "{currentYear}", currentYear );
+
+ if ( ( inceptionYear == null ) || inceptionYear.equals( currentYear ) )
{
theBottom = StringUtils.replace( theBottom, "{inceptionYear}–", "" );
}
+ else
+ {
+ theBottom = StringUtils.replace( theBottom, "{inceptionYear}", inceptionYear );
+ }
if ( project.getOrganization() == null )
{
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
index d923983..d2c764b 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocJar.java
@@ -157,16 +157,6 @@
@Parameter( property = "maven.javadoc.classifier", defaultValue = "javadoc", required = true )
private String classifier;
- /**
- * Timestamp for reproducible output archive entries, either formatted as ISO 8601
- * <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
- * <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
- *
- * @since 3.2.0
- */
- @Parameter( defaultValue = "${project.build.outputTimestamp}" )
- private String outputTimestamp;
-
/** {@inheritDoc} */
@Override
public void doExecute()