This is an automated email from the ASF dual-hosted git repository. khmarbaise pushed a commit to branch MPH-189 in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git
commit f6d41812b9bb7df8f6b962fff0a5a5f198b9df1e Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Thu Aug 4 21:08:42 2022 +0200 WIP. --- .../apache/maven/plugins/help/AbstractHelpMojo.java | 19 +++++++++++++++++-- .../apache/maven/plugins/help/ActiveProfilesMojo.java | 7 ++----- .../org/apache/maven/plugins/help/SystemMojo.java | 11 ++++------- .../maven/plugins/help/ActiveProfilesMojoTest.java | 2 +- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java index 0f079ff..801f667 100644 --- a/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/AbstractHelpMojo.java @@ -46,6 +46,11 @@ import org.eclipse.aether.resolution.ArtifactRequest; import java.io.File; import java.io.IOException; import java.io.Writer; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; /** @@ -61,8 +66,11 @@ public abstract class AbstractHelpMojo protected static final int LINE_LENGTH = 79; /** The line separator for the current OS. */ - protected static final String LS = System.getProperty( "line.separator" ); - + protected static final String LS = System.lineSeparator(); + + protected static final DateTimeFormatter DATE_TIME_FORMATTER = + DateTimeFormatter.ofPattern( "YYYY-MM-dd'T'HH:mm:ssxxxxx" ); + /** * Maven Project Builder component. */ @@ -108,6 +116,13 @@ public abstract class AbstractHelpMojo @Parameter( property = "output" ) protected File output; + protected static String formatMillis( long millis ) + { + ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant( Instant.ofEpochMilli( millis ), + ZoneId.from( ZoneOffset.UTC ) ); + return DATE_TIME_FORMATTER.format( zonedDateTime ); + } + /** * Utility method to write a content in a given file. * diff --git a/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java b/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java index 326ee9c..7cdfda4 100644 --- a/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/ActiveProfilesMojo.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.util.List; import java.util.Map; -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -67,12 +66,10 @@ public class ActiveProfilesMojo if ( output != null ) { - String formattedDateTime = DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT - .format( System.currentTimeMillis() ); StringBuilder sb = new StringBuilder(); sb.append( "Created by: " ).append( getClass().getName() ).append( LS ); - sb.append( "Created on: " ).append( formattedDateTime ).append( LS ).append( LS ); - sb.append( message.toString() ); + sb.append( "Created on: " ).append( formatMillis( System.currentTimeMillis() ) ).append( LS ).append( LS ); + sb.append( message ); try { diff --git a/src/main/java/org/apache/maven/plugins/help/SystemMojo.java b/src/main/java/org/apache/maven/plugins/help/SystemMojo.java index 85973e9..970995a 100644 --- a/src/main/java/org/apache/maven/plugins/help/SystemMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/SystemMojo.java @@ -19,15 +19,14 @@ package org.apache.maven.plugins.help; * under the License. */ -import org.apache.commons.lang3.time.DateFormatUtils; +import java.io.IOException; +import java.util.Properties; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineUtils; -import java.io.IOException; -import java.util.Properties; - /** * Displays a list of the platform details like system properties and environment variables. * @@ -92,11 +91,9 @@ public class SystemMojo if ( output != null ) { - String formattedDateTime = DateFormatUtils.ISO_8601_EXTENDED_DATETIME_TIME_ZONE_FORMAT - .format( System.currentTimeMillis() ); StringBuilder sb = new StringBuilder(); sb.append( "Created by: " ).append( getClass().getName() ).append( LS ); - sb.append( "Created on: " ).append( formattedDateTime ).append( LS ).append( LS ); + sb.append( "Created on: " ).append( formatMillis( System.currentTimeMillis() ) ).append( LS ).append( LS ); sb.append( message.toString() ); try diff --git a/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java b/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java index 6d70fd2..5f7490a 100644 --- a/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/ActiveProfilesMojoTest.java @@ -95,7 +95,7 @@ public class ActiveProfilesMojoTest Map<String, List<String>> profiles = new HashMap<>(); profiles.put( "external", externals ); // from settings profiles.put( "org.apache.maven.test:test:1.0", pom ); // from POM - profiles.put( "", Collections.<String>emptyList() ); // from super POM + profiles.put( "", Collections.emptyList() ); // from super POM return profiles; }