Skip to content

Commit

Permalink
New property: updateBuildOutputTimestampPolicy = (onchange | always |…
Browse files Browse the repository at this point in the history
… never) (#595) (#630)


Co-authored-by: Andrzej Jarmoniuk <git@jarmoniuk.nl>
  • Loading branch information
jarmoniuk and Andrzej Jarmoniuk committed Aug 15, 2022
1 parent 6e6efcb commit 0dbc619
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 4 deletions.
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set -DnewVersion=1.0 -DupdateBuildOutputTimestampPolicy=always
14 changes: 14 additions & 0 deletions src/it/it-set-021-outputTimestampPolicy-always/pom.xml
@@ -0,0 +1,14 @@
<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>localhost</groupId>
<artifactId>it-set-021-outputTimestampPolicy-always</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>set</name>

<properties>
<project.build.outputTimestamp>10</project.build.outputTimestamp>
</properties>
</project>
3 changes: 3 additions & 0 deletions src/it/it-set-021-outputTimestampPolicy-always/verify.groovy
@@ -0,0 +1,3 @@
pom = new File( basedir, "pom.xml" ).text

assert pom =~ /<project.build.outputTimestamp>\d\d\d\d+<.project.build.outputTimestamp>/
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set -DnewVersion=1.0 -DupdateBuildOutputTimestampPolicy=onchange
14 changes: 14 additions & 0 deletions src/it/it-set-022-outputTimestampPolicy-onchange/pom.xml
@@ -0,0 +1,14 @@
<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>localhost</groupId>
<artifactId>it-set-022-outputTimestampPolicy-onchange</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>set</name>

<properties>
<project.build.outputTimestamp>10</project.build.outputTimestamp>
</properties>
</project>
@@ -0,0 +1,3 @@
pom = new File( basedir, "pom.xml" ).text

assert pom =~ /<project.build.outputTimestamp>10<.project.build.outputTimestamp>/
@@ -0,0 +1 @@
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:set -DnewVersion=2.0 -DupdateBuildOutputTimestampPolicy=never
14 changes: 14 additions & 0 deletions src/it/it-set-023-outputTimestampPolicy-never/pom.xml
@@ -0,0 +1,14 @@
<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>localhost</groupId>
<artifactId>it-set-023-outputTimestampPolicy-never</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>set</name>

<properties>
<project.build.outputTimestamp>10</project.build.outputTimestamp>
</properties>
</project>
3 changes: 3 additions & 0 deletions src/it/it-set-023-outputTimestampPolicy-never/verify.groovy
@@ -0,0 +1,3 @@
pom = new File( basedir, "pom.xml" ).text

assert pom =~ /<project.build.outputTimestamp>10<.project.build.outputTimestamp>/
29 changes: 25 additions & 4 deletions src/main/java/org/codehaus/mojo/versions/SetMojo.java
Expand Up @@ -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 <code>-DgroupId='*'</code> to ignore the
* group of the current project. On Windows you can omit
* the single quotes on Linux they are necessary to prevent
Expand All @@ -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 <code>-DartifactId='*'</code> to ignore the
* artifactId of the current project. On Windows you can omit
* the single quotes on Linux they are necessary to prevent
Expand Down Expand Up @@ -205,11 +205,22 @@ public class SetMojo
/**
* Whether to update the <code>project.build.outputTimestamp<code> 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 <code>project.build.outputTimestamp<code> property in the POM when setting version.
* Valid values are: <code>onchange</code>, which will only change <code>outputTimestamp</code> for changed POMs,
* <code>always</code>, <code>never</code>.
*
* @since 2.12
*/
@Parameter( property = "updateBuildOutputTimestampPolicy", defaultValue = "onchange" )
private String updateBuildOutputTimestampPolicy;

/**
* The changes to module coordinates. Guarded by this.
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 0dbc619

Please sign in to comment.