You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2021/07/24 10:16:03 UTC
[maven-javadoc-plugin] branch master updated: [MJAVADOC-684] use
MavenArchiver.parseOutputTimestamp(...) API
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 9ff51bf [MJAVADOC-684] use MavenArchiver.parseOutputTimestamp(...) API
9ff51bf is described below
commit 9ff51bf4c785616397c752d5b734344a3ec9c9a9
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Jul 24 12:15:58 2021 +0200
[MJAVADOC-684] use MavenArchiver.parseOutputTimestamp(...) API
---
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 54 ++++++++++------------
.../apache/maven/plugins/javadoc/JavadocJar.java | 10 ----
2 files changed, 24 insertions(+), 40 deletions(-)
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 @@ package org.apache.maven.plugins.javadoc;
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.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;
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 @@ 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.
*
@@ -1831,6 +1826,16 @@ public abstract class AbstractJavadocMojo
@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,37 +3005,26 @@ public abstract class AbstractJavadocMojo
*/
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
+ final String inceptionYear = project.getInceptionYear();
+
+ // get Reproducible Builds outputTimestamp value
+ final Calendar currentYearCal = Calendar.getInstance();
+ final Date reproducibleDate = new MavenArchiver().parseOutputTimestamp( outputTimestamp );
+ if ( reproducibleDate != null )
{
- getLog().debug( "Using current year due to unavailable property '" + PROJECT_BUILD_OUTPUTTIMESTAMP + "'" );
- int currentYear = Calendar.getInstance().get( Calendar.YEAR );
- year = String.valueOf( currentYear );
+ currentYearCal.setTime( reproducibleDate );
}
+ final String currentYear = String.valueOf( currentYearCal.get( Calendar.YEAR ) );
- String inceptionYear = project.getInceptionYear();
-
- String theBottom = StringUtils.replace( this.bottom, "{currentYear}", year );
+ String theBottom = StringUtils.replace( this.bottom, "{currentYear}", currentYear );
- if ( inceptionYear != null )
+ if ( ( inceptionYear == null ) || inceptionYear.equals( currentYear ) )
{
- if ( inceptionYear.equals( year ) )
- {
- theBottom = StringUtils.replace( theBottom, "{inceptionYear}–", "" );
- }
- else
- {
- theBottom = StringUtils.replace( theBottom, "{inceptionYear}", inceptionYear );
- }
+ theBottom = StringUtils.replace( theBottom, "{inceptionYear}–", "" );
}
else
{
- theBottom = StringUtils.replace( theBottom, "{inceptionYear}–", "" );
+ 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 @@ public class JavadocJar
@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()