diff --git a/src/it/timestamp-timesource/invoker.properties b/src/it/timestamp-timesource/invoker.properties new file mode 100644 index 00000000..056ffdcc --- /dev/null +++ b/src/it/timestamp-timesource/invoker.properties @@ -0,0 +1 @@ +invoker.goals=compile diff --git a/src/it/timestamp-timesource/module-1/pom.xml b/src/it/timestamp-timesource/module-1/pom.xml new file mode 100644 index 00000000..2ba8de3d --- /dev/null +++ b/src/it/timestamp-timesource/module-1/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + + localdomain.localhost + timestamp-timesource + 1-SNAPSHOT + + + timestamp-timesource-module-1 + jar + + Timestamp TimeSource Module 1 + + + + + src/main/resources + + test.properties + + false + + + src/main/resources + + test.properties + + true + + + + diff --git a/src/it/timestamp-timesource/module-1/src/main/resources/test.properties b/src/it/timestamp-timesource/module-1/src/main/resources/test.properties new file mode 100644 index 00000000..cfac2965 --- /dev/null +++ b/src/it/timestamp-timesource/module-1/src/main/resources/test.properties @@ -0,0 +1,2 @@ +module.version=${module.build.timestamp} +session.version=${session.build.timestamp} diff --git a/src/it/timestamp-timesource/module-2/pom.xml b/src/it/timestamp-timesource/module-2/pom.xml new file mode 100644 index 00000000..69765c33 --- /dev/null +++ b/src/it/timestamp-timesource/module-2/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + + localdomain.localhost + timestamp-timesource + 1-SNAPSHOT + + + timestamp-timesource-module-2 + jar + + Timestamp TimeSource Module 2 + + + + + src/main/resources + + test.properties + + false + + + src/main/resources + + test.properties + + true + + + + diff --git a/src/it/timestamp-timesource/module-2/src/main/resources/test.properties b/src/it/timestamp-timesource/module-2/src/main/resources/test.properties new file mode 100644 index 00000000..cfac2965 --- /dev/null +++ b/src/it/timestamp-timesource/module-2/src/main/resources/test.properties @@ -0,0 +1,2 @@ +module.version=${module.build.timestamp} +session.version=${session.build.timestamp} diff --git a/src/it/timestamp-timesource/pom.xml b/src/it/timestamp-timesource/pom.xml new file mode 100644 index 00000000..31582db3 --- /dev/null +++ b/src/it/timestamp-timesource/pom.xml @@ -0,0 +1,61 @@ + + 4.0.0 + + localdomain.localhost + timestamp-timesource + 1-SNAPSHOT + pom + + Timestamp TimeSource + + Tests that a fixed timestamp gets generated + + + + module-1 + module-2 + + + + yyyy-MM-dd HH:mm:ss.SSS z + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + module-timestamp-property + validate + + timestamp-property + + + module.build.timestamp + ${maven.build.timestamp.format} + Europe/Amsterdam + + + + + + session-timestamp-property + validate + + timestamp-property + + + session.build.timestamp + ${maven.build.timestamp.format} + Europe/Amsterdam + build + + + + + + + diff --git a/src/it/timestamp-timesource/verify.bsh b/src/it/timestamp-timesource/verify.bsh new file mode 100644 index 00000000..e1c90f7a --- /dev/null +++ b/src/it/timestamp-timesource/verify.bsh @@ -0,0 +1,49 @@ +import java.io.*; +import java.util.*; + +try +{ + File module1File = new File( basedir, "module-1/target/classes/test.properties" ); + File module2File = new File( basedir, "module-2/target/classes/test.properties" ); + + Properties module1Props = new Properties(); + module1Props.load( new FileInputStream( module1File ) ); + Properties module2Props = new Properties(); + module2Props.load( new FileInputStream( module2File ) ); + + String module1ModuleVersion = module1Props.getProperty( "module.version" ); + String module1SessionVersion = module1Props.getProperty( "session.version" ); + String module2ModuleVersion = module2Props.getProperty( "module.version" ); + String module2SessionVersion = module2Props.getProperty( "session.version" ); + + if ( module1ModuleVersion.indexOf( "${module.build.timestamp}" ) >= 0 + || module2ModuleVersion.indexOf( "${module.build.timestamp}" ) >= 0) + { + System.err.println( "Module timestamp not set" ); + return false; + } + else if ( module1SessionVersion.indexOf( "${session.build.timestamp}" ) >= 0 + || module2SessionVersion.indexOf( "${session.build.timestamp}" ) >= 0) + { + System.err.println( "Session timestamp not set" ); + return false; + } + + if ( module1ModuleVersion.equals( module2ModuleVersion ) ) + { + System.err.println( "Module timestamps should not match by design" ); + return false; + } + else if ( !module1SessionVersion.equals( module2SessionVersion ) ) + { + System.err.println( "Session timestamps should match by design" ); + return false; + } +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/src/main/java/org/codehaus/mojo/buildhelper/TimestampPropertyMojo.java b/src/main/java/org/codehaus/mojo/buildhelper/TimestampPropertyMojo.java index f717f1bb..226ddcfa 100644 --- a/src/main/java/org/codehaus/mojo/buildhelper/TimestampPropertyMojo.java +++ b/src/main/java/org/codehaus/mojo/buildhelper/TimestampPropertyMojo.java @@ -32,6 +32,7 @@ import java.util.Locale; import java.util.TimeZone; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -89,12 +90,32 @@ public class TimestampPropertyMojo @Parameter( defaultValue = "second" ) private String unit; + /** + * The source of the time. Valid Values are + * + * + * @since 3.2.0 + */ + @Parameter( defaultValue = "current" ) + private String timeSource; + /** * The locale to use, for example en,US. */ @Parameter private String locale; + /** + * The Maven Session. + * + * @since 3.2.0 + */ + @Parameter( readonly = true, defaultValue = "${session}" ) + private MavenSession mavenSession; + /** * {@inheritDoc} */ @@ -199,7 +220,14 @@ else if ( unit.indexOf( "year" ) == 0 ) format.setTimeZone( timeZone ); - defineProperty( name, format.format( calendar.getTime() ) ); + if ("build".equals(timeSource)) + { + defineProperty( name, format.format( mavenSession.getStartTime() ) ); + } + else + { + defineProperty( name, format.format( calendar.getTime() ) ); + } } } diff --git a/src/site/apt/usage.apt.vm b/src/site/apt/usage.apt.vm index f7cbadbf..bbacd450 100644 --- a/src/site/apt/usage.apt.vm +++ b/src/site/apt/usage.apt.vm @@ -641,6 +641,61 @@ tomcat.http.port The <<>> and <<>> parameters can be further used to control the build-time behaviour. +* Set a property based on the <<>> + + The <<>> property does not allow for timezone overrides for obvious reasons. + The <<>> goal can be used to create one with a local timezone timestamp. + But the default implementation uses the <<>> time, which is thus not the same for all modules in a multi module project. + The new <<>> parameter with value <<>> now allows the usage of <<>> property instead of the <<>> timestamp. + +------------------- + + ... + + yyyy-MM-dd HH:mm:ss z + + ... + + + + org.codehaus.mojo + build-helper-maven-plugin + ${project.version} + + + module-timestamp-property + validate + + timestamp-property + + + module.build.timestamp + ${maven.build.timestamp.format} + Europe/Amsterdam + + + + + local-timestamp-property + validate + + timestamp-property + + + local.build.timestamp + ${maven.build.timestamp.format} + Europe/Amsterdam + build + + + + + + + ... + +------------------- + * Retrieve current host IP address The <<>> goal can be used to load current host address