Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify timestampFormat parameter between Create*Mojo #86

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
<svn>javasvn</svn>
</providerImplementations>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/org/codehaus/mojo/build/CreateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,21 @@ public class CreateMojo
private String locale;

/**
* Apply this java.text.MessageFormat to the timestamp only (as opposed to the <code>format</code> parameter).
* Apply this {@link java.text.SimpleDateFormat} to the timestamp only (as opposed to the <code>format</code> parameter).
*
* @since 1.0-beta-2
*/
@Parameter( property = "maven.buildNumber.timestampFormat" )
private String timestampFormat;

/**
* The timezone of the generated timestamp. If blank will default to {@link TimeZone#getDefault()}
*
* @since 3.0.0
*/
@Parameter( property = "maven.buildNumber.timestampTimeZone", defaultValue = "" )
private String timezone;

/**
* Selects alternative SCM provider implementations. Each map key denotes the original provider type as given in the
* SCM URL like "cvs" or "svn", the map value specifies the provider type of the desired implementation to use
Expand Down Expand Up @@ -437,7 +445,17 @@ private void buildNumberAndTimeStampForReactorProjects( Date now, String tainted
String timestamp = String.valueOf( now.getTime() );
if ( timestampFormat != null )
{
timestamp = MessageFormat.format( timestampFormat, new Object[] { now } );
if ( timestampFormat.matches( "\\{0,date,[^\\}]+\\}" ) )
{
getLog().warn( "The timestampFormat parameter now uses java.text.SimpleDateFormat." );
getLog().warn( "Please update your POM as support for java.text.MessageFormat may be removed." );
timestamp = Utils.createTimestamp( timestampFormat.replaceFirst( "\\{0,date,([^\\}]+)\\}", "$1" ),
timezone, now );
}
else
{
timestamp = Utils.createTimestamp( timestampFormat, timezone, now );
}
}

getLog().info( MessageFormat.format( "Storing buildNumber: {0} at timestamp: {1}",
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/codehaus/mojo/build/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ private Utils()

public static String createTimestamp( String timestampFormat, String timeZoneId )
{
Date now = Calendar.getInstance().getTime();
return createTimestamp( timestampFormat, timeZoneId, null );
}

public static String createTimestamp( String timestampFormat, String timeZoneId, Date now )
{
if ( null == now )
now = Calendar.getInstance().getTime();

if ( StringUtils.isBlank( timestampFormat ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/site/apt/usage.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Usage

+------------------------------------------+
<configuration>
<format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
<format>yyyy-MM-dd HH:mm:ss</format>
<items>
<item>timestamp</item>
</items>
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/codehaus/mojo/build/it/BuildNumberMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ public void createTimestampItTest()

}

@Test
public void legacyTimestampItTest()
throws Exception
{
File projDir = resources.getBasedir( "legacy-timestamp-it" );

MavenExecution mavenExec = maven.forProject( projDir );
MavenExecutionResult result = mavenExec.execute( "clean", "verify" );
result.assertLogText( "Please update your POM" );

File testDir = result.getBasedir();
File artifact = new File( testDir, "target/buildnumber-maven-plugin-legacy-timestamp-it-1.0-SNAPSHOT.jar" );
JarFile jarFile = new JarFile( artifact );
Attributes manifest = jarFile.getManifest().getMainAttributes();
jarFile.close();
String timestamp = manifest.getValue( "Build-Time" );
SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd" );
Assert.assertNotNull( format.parse( timestamp ) );

}

@Test
public void failLocalChangeItTest()
throws Exception
Expand Down
2 changes: 1 addition & 1 deletion src/test/projects/MBUILDNUM-83/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<svn>javasvn</svn>
</providerImplementations>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</providerImplementations>
<username>foo</username>
<password>bar</password>
<timestampFormat>{0,date,yyyyMMdd_HHmmss}</timestampFormat>
<timestampFormat>yyyyMMdd_HHmmss</timestampFormat>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/test/projects/MOJO-1668/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</providerImplementations>
<username>foo</username>
<password>bar</password>
<timestampFormat>{0,date,yyyyMMdd_HHmmss}</timestampFormat>
<timestampFormat>yyyyMMdd_HHmmss</timestampFormat>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/test/projects/basic-it-clearcase-scm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<configuration>
<revisionOnScmFailure>foo</revisionOnScmFailure>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
2 changes: 1 addition & 1 deletion src/test/projects/basic-it-git/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</goals>
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</goals>
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</goals>
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
2 changes: 1 addition & 1 deletion src/test/projects/basic-it-no-devscm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</goals>
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<svn>javasvn</svn>
</providerImplementations>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
2 changes: 1 addition & 1 deletion src/test/projects/basic-it-svnjava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<svn>javasvn</svn>
</providerImplementations>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</goals>
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</goals>
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
2 changes: 1 addition & 1 deletion src/test/projects/basic-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</goals>
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
2 changes: 1 addition & 1 deletion src/test/projects/git-basic-it-MBUILDNUM-66/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<goal>create</goal>
</goals>
<configuration>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
<timestampFormat>yyyy-MM-dd</timestampFormat>
</configuration>
</execution>
</executions>
Expand Down
58 changes: 58 additions & 0 deletions src/test/projects/legacy-timestamp-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.it</groupId>
<artifactId>buildnumber-maven-plugin-legacy-timestamp-it</artifactId>
<version>1.0-SNAPSHOT</version>

<scm>
<developerConnection>scm:git:https://github.com/mojohaus/buildnumber-maven-plugin/test/bogus.git</developerConnection>
</scm>

<build>

<defaultGoal>package</defaultGoal>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>${it-plugin.version}</version>
<executions>
<execution>
<id>legacyTimestampFormat</id>
<goals>
<goal>create</goal>
</goals>
<configuration>
<useLastCommittedRevision>true</useLastCommittedRevision>
<timestampFormat>{0,date,yyyy-MM-dd}</timestampFormat>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Time>${timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>

</build>

</project>