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

New property: updateBuildOutputTimestampPolicy = (onchange | always | never) (#595) #630

Merged
merged 2 commits into from Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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>/
27 changes: 23 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 @@ -204,12 +204,21 @@ public class SetMojo

/**
* Whether to update the <code>project.build.outputTimestamp<code> property in the POM when setting version.
* Deprecated; please use <code>updateBuildOutputTimestampPolicy</code> 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.
*
* @since 2.12
*/
@Parameter( property = "updateBuildOutputTimestampPolicy", defaultValue = "onchange" )
private String updateBuildOutputTimestampPolicy;
jarmoniuk marked this conversation as resolved.
Show resolved Hide resolved

/**
* The changes to module coordinates. Guarded by this.
*/
Expand Down Expand Up @@ -301,6 +310,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 +530,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