From 0dbc61937df64d1c804566e451638661a4ad1f28 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk <1554729+ajarmoniuk@users.noreply.github.com> Date: Mon, 15 Aug 2022 11:05:55 +0200 Subject: [PATCH] New property: updateBuildOutputTimestampPolicy = (onchange | always | never) (#595) (#630) Co-authored-by: Andrzej Jarmoniuk --- .../invoker.properties | 1 + .../pom.xml | 14 +++++++++ .../verify.groovy | 3 ++ .../invoker.properties | 1 + .../pom.xml | 14 +++++++++ .../verify.groovy | 3 ++ .../invoker.properties | 1 + .../pom.xml | 14 +++++++++ .../verify.groovy | 3 ++ .../org/codehaus/mojo/versions/SetMojo.java | 29 ++++++++++++++++--- 10 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/it/it-set-021-outputTimestampPolicy-always/invoker.properties create mode 100644 src/it/it-set-021-outputTimestampPolicy-always/pom.xml create mode 100644 src/it/it-set-021-outputTimestampPolicy-always/verify.groovy create mode 100644 src/it/it-set-022-outputTimestampPolicy-onchange/invoker.properties create mode 100644 src/it/it-set-022-outputTimestampPolicy-onchange/pom.xml create mode 100644 src/it/it-set-022-outputTimestampPolicy-onchange/verify.groovy create mode 100644 src/it/it-set-023-outputTimestampPolicy-never/invoker.properties create mode 100644 src/it/it-set-023-outputTimestampPolicy-never/pom.xml create mode 100644 src/it/it-set-023-outputTimestampPolicy-never/verify.groovy diff --git a/src/it/it-set-021-outputTimestampPolicy-always/invoker.properties b/src/it/it-set-021-outputTimestampPolicy-always/invoker.properties new file mode 100644 index 000000000..244cd7e9f --- /dev/null +++ b/src/it/it-set-021-outputTimestampPolicy-always/invoker.properties @@ -0,0 +1 @@ +invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set -DnewVersion=1.0 -DupdateBuildOutputTimestampPolicy=always \ No newline at end of file diff --git a/src/it/it-set-021-outputTimestampPolicy-always/pom.xml b/src/it/it-set-021-outputTimestampPolicy-always/pom.xml new file mode 100644 index 000000000..d354e672e --- /dev/null +++ b/src/it/it-set-021-outputTimestampPolicy-always/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + + localhost + it-set-021-outputTimestampPolicy-always + 1.0 + pom + set + + + 10 + + diff --git a/src/it/it-set-021-outputTimestampPolicy-always/verify.groovy b/src/it/it-set-021-outputTimestampPolicy-always/verify.groovy new file mode 100644 index 000000000..9c85ced4f --- /dev/null +++ b/src/it/it-set-021-outputTimestampPolicy-always/verify.groovy @@ -0,0 +1,3 @@ +pom = new File( basedir, "pom.xml" ).text + +assert pom =~ /\d\d\d\d+<.project.build.outputTimestamp>/ diff --git a/src/it/it-set-022-outputTimestampPolicy-onchange/invoker.properties b/src/it/it-set-022-outputTimestampPolicy-onchange/invoker.properties new file mode 100644 index 000000000..944314bca --- /dev/null +++ b/src/it/it-set-022-outputTimestampPolicy-onchange/invoker.properties @@ -0,0 +1 @@ +invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set -DnewVersion=1.0 -DupdateBuildOutputTimestampPolicy=onchange \ No newline at end of file diff --git a/src/it/it-set-022-outputTimestampPolicy-onchange/pom.xml b/src/it/it-set-022-outputTimestampPolicy-onchange/pom.xml new file mode 100644 index 000000000..41082c619 --- /dev/null +++ b/src/it/it-set-022-outputTimestampPolicy-onchange/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + + localhost + it-set-022-outputTimestampPolicy-onchange + 1.0 + pom + set + + + 10 + + diff --git a/src/it/it-set-022-outputTimestampPolicy-onchange/verify.groovy b/src/it/it-set-022-outputTimestampPolicy-onchange/verify.groovy new file mode 100644 index 000000000..29f438915 --- /dev/null +++ b/src/it/it-set-022-outputTimestampPolicy-onchange/verify.groovy @@ -0,0 +1,3 @@ +pom = new File( basedir, "pom.xml" ).text + +assert pom =~ /10<.project.build.outputTimestamp>/ diff --git a/src/it/it-set-023-outputTimestampPolicy-never/invoker.properties b/src/it/it-set-023-outputTimestampPolicy-never/invoker.properties new file mode 100644 index 000000000..7d71944e2 --- /dev/null +++ b/src/it/it-set-023-outputTimestampPolicy-never/invoker.properties @@ -0,0 +1 @@ +invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set -DnewVersion=2.0 -DupdateBuildOutputTimestampPolicy=never \ No newline at end of file diff --git a/src/it/it-set-023-outputTimestampPolicy-never/pom.xml b/src/it/it-set-023-outputTimestampPolicy-never/pom.xml new file mode 100644 index 000000000..212722023 --- /dev/null +++ b/src/it/it-set-023-outputTimestampPolicy-never/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + + localhost + it-set-023-outputTimestampPolicy-never + 1.0 + pom + set + + + 10 + + diff --git a/src/it/it-set-023-outputTimestampPolicy-never/verify.groovy b/src/it/it-set-023-outputTimestampPolicy-never/verify.groovy new file mode 100644 index 000000000..29f438915 --- /dev/null +++ b/src/it/it-set-023-outputTimestampPolicy-never/verify.groovy @@ -0,0 +1,3 @@ +pom = new File( basedir, "pom.xml" ).text + +assert pom =~ /10<.project.build.outputTimestamp>/ diff --git a/src/main/java/org/codehaus/mojo/versions/SetMojo.java b/src/main/java/org/codehaus/mojo/versions/SetMojo.java index a94632fd5..a268fb4a2 100644 --- a/src/main/java/org/codehaus/mojo/versions/SetMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/SetMojo.java @@ -84,7 +84,7 @@ public class SetMojo /** * The groupId of the dependency/module to update. - * If you like to update modules of a aggregator you + * If you like to update modules of a aggregator you * should set -DgroupId='*' to ignore the * group of the current project. On Windows you can omit * the single quotes on Linux they are necessary to prevent @@ -97,7 +97,7 @@ public class SetMojo /** * The artifactId of the dependency/module to update. - * If you like to update modules of a aggregator you + * If you like to update modules of a aggregator you * should set -DartifactId='*' to ignore the * artifactId of the current project. On Windows you can omit * the single quotes on Linux they are necessary to prevent @@ -205,11 +205,22 @@ public class SetMojo /** * Whether to update the project.build.outputTimestamp property in the POM when setting version. * + * @deprecated please use {@link #updateBuildOutputTimestampPolicy} instead * @since 2.10 */ @Parameter( property = "updateBuildOutputTimestamp", defaultValue = "true" ) private boolean updateBuildOutputTimestamp; + /** + * Whether to update the project.build.outputTimestamp property in the POM when setting version. + * Valid values are: onchange, which will only change outputTimestamp for changed POMs, + * always, never. + * + * @since 2.12 + */ + @Parameter( property = "updateBuildOutputTimestampPolicy", defaultValue = "onchange" ) + private String updateBuildOutputTimestampPolicy; + /** * The changes to module coordinates. Guarded by this. */ @@ -301,6 +312,14 @@ public void execute() + "property (that is -DnewVersion=... on the command line) or run in interactive mode" ); } + if ( !"onchange".equals( updateBuildOutputTimestampPolicy ) + && !"always".equals( updateBuildOutputTimestampPolicy ) + && !"never".equals( updateBuildOutputTimestampPolicy ) ) + { + throw new MojoExecutionException( "updateBuildOutputTimestampPolicy should be one of: " + + "\"onchange\", \"always\", \"never\"." ); + } + try { final MavenProject project; @@ -513,10 +532,12 @@ protected synchronized void update( ModifiedPomXMLEventReader pom ) for ( VersionChange versionChange : sourceChanges ) { changer.apply( versionChange ); + } - if (updateBuildOutputTimestamp) { + if ( updateBuildOutputTimestamp && !"never".equals( updateBuildOutputTimestampPolicy ) ) { + if ( "always".equals( updateBuildOutputTimestampPolicy) || !sourceChanges.isEmpty() ) { // also update project.build.outputTimestamp - updateBuildOutputTimestamp( pom, model ); + updateBuildOutputTimestamp(pom, model); } } }