Skip to content

Commit

Permalink
Resolves #837: Add includeParent (default true) to UpdatePropertiesMojo
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Dec 1, 2022
1 parent 9576c2e commit 3689b13
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-properties
invoker.mavenOpts = -DincludeParent=false
Original file line number Diff line number Diff line change
@@ -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>default-group</groupId>
<artifactId>parent-artifact</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

<properties>
<artifact-version>1.0</artifact-version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<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>

<parent>
<groupId>default-group</groupId>
<artifactId>parent-artifact</artifactId>
<version>1.0.0</version>
<relativePath>parent-pom.xml</relativePath>
</parent>

<artifactId>child-artifact</artifactId>
<version>1.0.0</version>

<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>${artifact-version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert ! ( new File( basedir, "build.log" ).text.contains( 'Property ${artifact-version}' ) )
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.codehaus.mojo.versions.recording.DefaultChangeRecord;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;

import static java.util.Optional.ofNullable;
import static org.codehaus.mojo.versions.utils.SegmentUtils.determineUnchangedSegment;

/**
Expand Down Expand Up @@ -133,6 +134,16 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo
defaultValue = "true" )
protected boolean allowIncrementalUpdates = true;

/**
* <p>Whether to include parent POMs in the search. Default: {@code true}</p>
* <p>Setting this to {@code false} can speed up execution, but will not resolve
* property-bound dependencies, defined in parent POMs.
*
* @since 2.14.0
*/
@Parameter( property = "includeParent", defaultValue = "true" )
protected boolean includeParent = true;

// -------------------------- STATIC METHODS --------------------------

// -------------------------- OTHER METHODS --------------------------
Expand Down Expand Up @@ -164,6 +175,7 @@ protected void update( ModifiedPomXMLEventReader pom )
.withIncludeProperties( includeProperties )
.withExcludeProperties( excludeProperties )
.withAutoLinkItems( autoLinkItems )
.withIncludeParent( includeParent )
.build() );
for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() )
{
Expand Down Expand Up @@ -200,7 +212,7 @@ protected void update( ModifiedPomXMLEventReader pom )
updatePropertyToNewestVersion( pom, property, version, currentVersion,
allowDowngrade, unchangedSegment );

if ( targetVersion != null )
if ( pom.isModified() )
{
for ( final ArtifactAssociation association : version.getAssociations() )
{
Expand All @@ -211,7 +223,9 @@ protected void update( ModifiedPomXMLEventReader pom )
ChangeRecord.ChangeKind.PROPERTY )
.withArtifact( association.getArtifact() )
.withOldVersion( currentVersion )
.withNewVersion( targetVersion.toString() )
.withNewVersion( ofNullable( targetVersion )
.map( ArtifactVersion::toString )
.orElse( "(empty)" ) )
.build() );
}
}
Expand Down

0 comments on commit 3689b13

Please sign in to comment.