diff --git a/versions-maven-plugin/src/it/it-update-properties-issue-837/invoker.properties b/versions-maven-plugin/src/it/it-update-properties-issue-837/invoker.properties new file mode 100644 index 000000000..b992cb3c7 --- /dev/null +++ b/versions-maven-plugin/src/it/it-update-properties-issue-837/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-properties +invoker.mavenOpts = -DincludeParent=false diff --git a/versions-maven-plugin/src/it/it-update-properties-issue-837/parent-pom.xml b/versions-maven-plugin/src/it/it-update-properties-issue-837/parent-pom.xml new file mode 100644 index 000000000..d01abb3ee --- /dev/null +++ b/versions-maven-plugin/src/it/it-update-properties-issue-837/parent-pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + + default-group + parent-artifact + 1.0.0 + pom + + + 1.0 + + + diff --git a/versions-maven-plugin/src/it/it-update-properties-issue-837/pom.xml b/versions-maven-plugin/src/it/it-update-properties-issue-837/pom.xml new file mode 100644 index 000000000..e80ba17a4 --- /dev/null +++ b/versions-maven-plugin/src/it/it-update-properties-issue-837/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + + default-group + parent-artifact + 1.0.0 + parent-pom.xml + + + child-artifact + 1.0.0 + + + + localhost + dummy-api + ${artifact-version} + + + + diff --git a/versions-maven-plugin/src/it/it-update-properties-issue-837/verify.groovy b/versions-maven-plugin/src/it/it-update-properties-issue-837/verify.groovy new file mode 100644 index 000000000..5b4f858ad --- /dev/null +++ b/versions-maven-plugin/src/it/it-update-properties-issue-837/verify.groovy @@ -0,0 +1 @@ +assert ! ( new File( basedir, "build.log" ).text.contains( 'Property ${artifact-version}' ) ) diff --git a/versions-maven-plugin/src/it/it-update-property-issue-837/invoker.properties b/versions-maven-plugin/src/it/it-update-property-issue-837/invoker.properties new file mode 100644 index 000000000..3d5b27837 --- /dev/null +++ b/versions-maven-plugin/src/it/it-update-property-issue-837/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-property +invoker.mavenOpts = -DincludeParent=false -Dproperty=artifact-version diff --git a/versions-maven-plugin/src/it/it-update-property-issue-837/parent-pom.xml b/versions-maven-plugin/src/it/it-update-property-issue-837/parent-pom.xml new file mode 100644 index 000000000..d01abb3ee --- /dev/null +++ b/versions-maven-plugin/src/it/it-update-property-issue-837/parent-pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + + default-group + parent-artifact + 1.0.0 + pom + + + 1.0 + + + diff --git a/versions-maven-plugin/src/it/it-update-property-issue-837/pom.xml b/versions-maven-plugin/src/it/it-update-property-issue-837/pom.xml new file mode 100644 index 000000000..e80ba17a4 --- /dev/null +++ b/versions-maven-plugin/src/it/it-update-property-issue-837/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + + default-group + parent-artifact + 1.0.0 + parent-pom.xml + + + child-artifact + 1.0.0 + + + + localhost + dummy-api + ${artifact-version} + + + + diff --git a/versions-maven-plugin/src/it/it-update-property-issue-837/verify.groovy b/versions-maven-plugin/src/it/it-update-property-issue-837/verify.groovy new file mode 100644 index 000000000..f60420cb9 --- /dev/null +++ b/versions-maven-plugin/src/it/it-update-property-issue-837/verify.groovy @@ -0,0 +1,2 @@ +assert ! ( new File( basedir, "build.log" ).text + .contains( 'Property ${artifact-version}: Set of valid available versions is [1.0, 1.0.1,' ) ) diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java index c2f28e790..92021ba27 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java @@ -495,6 +495,20 @@ protected boolean shouldApplyUpdate( Artifact artifact, String currentVersion, A return true; } + /** + * Attempts to update the property to a newer version, if that exists + * @param pom pom to update + * @param property property to update + * @param version {@link PropertyVersions} object + * @param currentVersion current version + * @param allowDowngrade if downgrades should be allowed if snapshots are not allowed + * @param unchangedSegment most major segment not to be changed + * @return new version of the artifact, if the property was updated; {@code null} if there was no update + * @throws XMLStreamException thrown from {@link ModifiedPomXMLEventReader} if the update doesn't succeed + * @throws InvalidVersionSpecificationException thrown if {@code unchangedSegment} doesn't match the version + * @throws InvalidSegmentException thrown if {@code unchangedSegment} is invalid + * @throws MojoExecutionException thrown if any other error occurs + */ protected ArtifactVersion updatePropertyToNewestVersion( ModifiedPomXMLEventReader pom, Property property, PropertyVersions version, String currentVersion, boolean allowDowngrade, @@ -513,9 +527,10 @@ protected ArtifactVersion updatePropertyToNewestVersion( ModifiedPomXMLEventRead else if ( PomHelper.setPropertyVersion( pom, version.getProfileId(), property.getName(), winner.toString() ) ) { getLog().info( "Updated ${" + property.getName() + "} from " + currentVersion + " to " + winner ); + return winner; } - return winner; + return null; } /** diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java index 9ef536db4..a91837629 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java @@ -19,32 +19,20 @@ * under the License. */ -import javax.inject.Inject; -import javax.xml.stream.XMLStreamException; - -import java.util.Map; -import java.util.Optional; - -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.wagon.Wagon; -import org.codehaus.mojo.versions.api.ArtifactAssociation; import org.codehaus.mojo.versions.api.Property; -import org.codehaus.mojo.versions.api.PropertyVersions; -import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionsHelper; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; -import org.codehaus.mojo.versions.ordering.InvalidSegmentException; -import org.codehaus.mojo.versions.recording.DefaultChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; -import static org.codehaus.mojo.versions.utils.SegmentUtils.determineUnchangedSegment; +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import java.util.Map; /** * Sets properties to the latest versions of specific artifacts. @@ -53,11 +41,8 @@ * @since 1.0-alpha-1 */ @Mojo( name = "update-properties", threadSafe = true ) -public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo +public class UpdatePropertiesMojo extends UpdatePropertiesMojoBase { - - // ------------------------------ FIELDS ------------------------------ - /** * Any restrictions that apply to specific properties. * @@ -82,61 +67,6 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo @Parameter( property = "excludeProperties" ) private String excludeProperties = null; - /** - * Whether properties linking versions should be auto-detected or not. - * - * @since 1.0-alpha-2 - */ - @Parameter( property = "autoLinkItems", - defaultValue = "true" ) - private boolean autoLinkItems; - - /** - * If a property points to a version like 1.2.3-SNAPSHOT and your repo contains a version like - * 1.1.0 without settings this to true the property will not being changed. - * - * @since 2.4 - */ - @Parameter( property = "allowDowngrade", - defaultValue = "false" ) - private boolean allowDowngrade; - - /** - * Whether to allow the major version number to be changed. - * - * @since 2.4 - */ - @Parameter( property = "allowMajorUpdates", - defaultValue = "true" ) - protected boolean allowMajorUpdates = true; - - /** - *

Whether to allow the minor version number to be changed.

- * - *

Note: {@code false} also implies {@linkplain #allowMajorUpdates} {@code false}

- * - * @since 2.4 - */ - @Parameter( property = "allowMinorUpdates", - defaultValue = "true" ) - protected boolean allowMinorUpdates = true; - - /** - *

Whether to allow the incremental version number to be changed.

- * - *

Note: {@code false} also implies {@linkplain #allowMajorUpdates} - * and {@linkplain #allowMinorUpdates} {@code false}

- * - * @since 2.4 - */ - @Parameter( property = "allowIncrementalUpdates", - defaultValue = "true" ) - protected boolean allowIncrementalUpdates = true; - - // -------------------------- STATIC METHODS -------------------------- - - // -------------------------- OTHER METHODS -------------------------- - @Inject public UpdatePropertiesMojo( RepositorySystem repositorySystem, org.eclipse.aether.RepositorySystem aetherRepositorySystem, @@ -157,74 +87,15 @@ public UpdatePropertiesMojo( RepositorySystem repositorySystem, protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { - Map propertyVersions = getHelper().getVersionPropertiesMap( + update( pom, getHelper().getVersionPropertiesMap( VersionsHelper.VersionPropertiesMapRequest.builder() .withMavenProject( getProject() ) .withPropertyDefinitions( properties ) .withIncludeProperties( includeProperties ) .withExcludeProperties( excludeProperties ) .withAutoLinkItems( autoLinkItems ) - .build() ); - for ( Map.Entry entry : propertyVersions.entrySet() ) - { - Property property = entry.getKey(); - PropertyVersions version = entry.getValue(); - - final String currentVersion = getProject().getProperties().getProperty( property.getName() ); - if ( currentVersion == null ) - { - continue; - } - boolean canUpdateProperty = true; - for ( ArtifactAssociation association : version.getAssociations() ) - { - if ( !( isIncluded( association.getArtifact() ) ) ) - { - getLog().info( - "Not updating the property ${" + property.getName() + "} because it is used by artifact " - + association.getArtifact().toString() - + " and that artifact is not included in the list of " - + " allowed artifacts to be updated." ); - canUpdateProperty = false; - break; - } - } - - if ( canUpdateProperty ) - { - Optional unchangedSegment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, - allowIncrementalUpdates, getLog() ); - try - { - ArtifactVersion targetVersion = - updatePropertyToNewestVersion( pom, property, version, currentVersion, - allowDowngrade, unchangedSegment ); - - if ( targetVersion != null ) - { - for ( final ArtifactAssociation association : version.getAssociations() ) - { - if ( ( isIncluded( association.getArtifact() ) ) ) - { - getChangeRecorder().recordChange( DefaultChangeRecord.builder() - .withKind( - ChangeRecord.ChangeKind.PROPERTY ) - .withArtifact( association.getArtifact() ) - .withOldVersion( currentVersion ) - .withNewVersion( targetVersion.toString() ) - .build() ); - } - } - } - } - catch ( InvalidSegmentException | InvalidVersionSpecificationException e ) - { - getLog().warn( String.format( "Skipping the processing of %s:%s due to: %s", property.getName(), - property.getVersion(), e.getMessage() ) ); - } - } - - } + .withIncludeParent( includeParent ) + .build() ) ); } } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java new file mode 100644 index 000000000..8baa1eda0 --- /dev/null +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java @@ -0,0 +1,179 @@ +package org.codehaus.mojo.versions; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.repository.RepositorySystem; +import org.apache.maven.wagon.Wagon; +import org.codehaus.mojo.versions.api.ArtifactAssociation; +import org.codehaus.mojo.versions.api.Property; +import org.codehaus.mojo.versions.api.PropertyVersions; +import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.ordering.InvalidSegmentException; +import org.codehaus.mojo.versions.recording.DefaultChangeRecord; +import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; + +import javax.xml.stream.XMLStreamException; +import java.util.Map; +import java.util.Optional; + +import static org.codehaus.mojo.versions.utils.SegmentUtils.determineUnchangedSegment; + +/** + * Common base class for {@link UpdatePropertiesMojo} + * and {@link UpdatePropertyMojo} + */ +public abstract class UpdatePropertiesMojoBase extends AbstractVersionsDependencyUpdaterMojo +{ + /** + * Whether properties linking versions should be auto-detected or not. + * + * @since 1.0-alpha-2 + */ + @Parameter( property = "autoLinkItems", defaultValue = "true" ) + protected boolean autoLinkItems; + + /** + * If a property points to a version like 1.2.3 and your repository contains versions like + * 1.2.3 and 1.1.0 without settings this to true the property will never + * being changed back to 1.1.0 by using -DnewVersion=[1.1.0]. + * + * @since 3.0.0 + */ + @Parameter( property = "allowDowngrade", defaultValue = "false" ) + protected boolean allowDowngrade; + + /** + * Whether to allow the major version number to be changed. + * + * @since 2.4 + */ + @Parameter( property = "allowMajorUpdates", defaultValue = "true" ) + protected boolean allowMajorUpdates; + + /** + *

Whether to allow the minor version number to be changed.

+ * + *

Note: {@code false} also implies {@linkplain #allowMajorUpdates} {@code false}

+ * + * @since 2.4 + */ + @Parameter( property = "allowMinorUpdates", defaultValue = "true" ) + protected boolean allowMinorUpdates; + + /** + *

Whether to allow the incremental version number to be changed.

+ * + *

Note: {@code false} also implies {@linkplain #allowMajorUpdates} + * and {@linkplain #allowMinorUpdates} {@code false}

+ * + * @since 2.4 + */ + @Parameter( property = "allowIncrementalUpdates", defaultValue = "true" ) + protected boolean allowIncrementalUpdates; + + /** + *

Whether to include parent POMs in the search. Default: {@code true}

+ *

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; + + public UpdatePropertiesMojoBase( RepositorySystem repositorySystem, + org.eclipse.aether.RepositorySystem aetherRepositorySystem, + Map wagonMap, + Map changeRecorders ) + { + super( repositorySystem, aetherRepositorySystem, wagonMap, changeRecorders ); + } + + protected void update( ModifiedPomXMLEventReader pom, Map propertyVersions ) + throws XMLStreamException + { + for ( Map.Entry entry : propertyVersions.entrySet() ) + { + Property property = entry.getKey(); + PropertyVersions version = entry.getValue(); + + final String currentVersion = getProject().getProperties().getProperty( property.getName() ); + if ( currentVersion == null ) + { + continue; + } + boolean canUpdateProperty = true; + for ( ArtifactAssociation association : version.getAssociations() ) + { + if ( !( isIncluded( association.getArtifact() ) ) ) + { + getLog().info( + "Not updating the property ${" + property.getName() + "} because it is used by artifact " + + association.getArtifact().toString() + + " and that artifact is not included in the list of " + + " allowed artifacts to be updated." ); + canUpdateProperty = false; + break; + } + } + + if ( canUpdateProperty ) + { + Optional unchangedSegment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, + allowIncrementalUpdates, getLog() ); + try + { + ArtifactVersion targetVersion = + updatePropertyToNewestVersion( pom, property, version, currentVersion, + allowDowngrade, unchangedSegment ); + + if ( targetVersion != null ) + { + for ( final ArtifactAssociation association : version.getAssociations() ) + { + if ( ( isIncluded( association.getArtifact() ) ) ) + { + getChangeRecorder().recordChange( DefaultChangeRecord.builder() + .withKind( + ChangeRecord.ChangeKind.PROPERTY ) + .withArtifact( association.getArtifact() ) + .withOldVersion( currentVersion ) + .withNewVersion( targetVersion.toString() ) + .build() ); + } + } + } + } + catch ( InvalidSegmentException | InvalidVersionSpecificationException | MojoExecutionException e ) + { + getLog().warn( String.format( "Skipping the processing of %s:%s due to: %s", property.getName(), + property.getVersion(), e.getMessage() ) ); + } + } + + } + } +} diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java index 32c569623..2fc55cf48 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java @@ -19,31 +19,20 @@ * under the License. */ -import javax.inject.Inject; -import javax.xml.stream.XMLStreamException; - -import java.util.Map; -import java.util.Optional; - -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.repository.RepositorySystem; import org.apache.maven.wagon.Wagon; -import org.codehaus.mojo.versions.api.ArtifactAssociation; import org.codehaus.mojo.versions.api.Property; -import org.codehaus.mojo.versions.api.PropertyVersions; -import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionsHelper; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; -import org.codehaus.mojo.versions.ordering.InvalidSegmentException; -import org.codehaus.mojo.versions.recording.DefaultChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; -import org.codehaus.mojo.versions.utils.SegmentUtils; + +import javax.inject.Inject; +import javax.xml.stream.XMLStreamException; +import java.util.Map; /** * Sets a property to the latest version in a given range of associated artifacts. @@ -52,12 +41,8 @@ * @since 1.3 */ @Mojo( name = "update-property", threadSafe = true ) -public class UpdatePropertyMojo - extends AbstractVersionsUpdaterMojo +public class UpdatePropertyMojo extends UpdatePropertiesMojoBase { - - // ------------------------------ FIELDS ------------------------------ - /** * A property to update. * @@ -85,57 +70,6 @@ public class UpdatePropertyMojo @Parameter( property = "newVersion" ) private String newVersion = null; - /** - * Whether properties linking versions should be auto-detected or not. - * - * @since 1.0-alpha-2 - */ - @Parameter( property = "autoLinkItems", defaultValue = "true" ) - private boolean autoLinkItems; - - /** - * If a property points to a version like 1.2.3 and your repository contains versions like - * 1.2.3 and 1.1.0 without settings this to true the property will never - * being changed back to 1.1.0 by using -DnewVersion=[1.1.0]. - * - * @since 3.0.0 - */ - @Parameter( property = "allowDowngrade", defaultValue = "false" ) - private boolean allowDowngrade; - - /** - * Whether to allow the major version number to be changed. - * - * @since 2.4 - */ - @Parameter( property = "allowMajorUpdates", defaultValue = "true" ) - protected boolean allowMajorUpdates; - - /** - *

Whether to allow the minor version number to be changed.

- * - *

Note: {@code false} also implies {@linkplain #allowMajorUpdates} {@code false}

- * - * @since 2.4 - */ - @Parameter( property = "allowMinorUpdates", defaultValue = "true" ) - protected boolean allowMinorUpdates; - - /** - *

Whether to allow the incremental version number to be changed.

- * - *

Note: {@code false} also implies {@linkplain #allowMajorUpdates} - * and {@linkplain #allowMinorUpdates} {@code false}

- * - * @since 2.4 - */ - @Parameter( property = "allowIncrementalUpdates", defaultValue = "true" ) - protected boolean allowIncrementalUpdates; - - // -------------------------- STATIC METHODS -------------------------- - - // -------------------------- OTHER METHODS -------------------------- - @Inject public UpdatePropertyMojo( RepositorySystem repositorySystem, org.eclipse.aether.RepositorySystem aetherRepositorySystem, @@ -156,54 +90,17 @@ public UpdatePropertyMojo( RepositorySystem repositorySystem, protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { - Property propertyConfig = new Property( property ); - propertyConfig.setVersion( newVersion ); - Map propertyVersions = - this.getHelper().getVersionPropertiesMap( - VersionsHelper.VersionPropertiesMapRequest.builder() - .withMavenProject( getProject() ) - .withPropertyDefinitions( new Property[] {propertyConfig} ) - .withIncludeProperties( property ) - .withAutoLinkItems( autoLinkItems ) - .build() ); - for ( Map.Entry entry : propertyVersions.entrySet() ) - { - Property property = entry.getKey(); - PropertyVersions version = entry.getValue(); - - final String currentVersion = getProject().getProperties().getProperty( property.getName() ); - if ( currentVersion == null ) - { - continue; - } - - Optional unchangedSegment = - SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, - allowIncrementalUpdates, getLog() ); - try - { - ArtifactVersion targetVersion = updatePropertyToNewestVersion( pom, property, version, currentVersion, - allowDowngrade, unchangedSegment ); - - if ( targetVersion != null ) - { - for ( final ArtifactAssociation association : version.getAssociations() ) - { - this.getChangeRecorder().recordChange( DefaultChangeRecord.builder() - .withKind( ChangeRecord.ChangeKind.PROPERTY ) - .withArtifact( association.getArtifact() ) - .withOldVersion( currentVersion ) - .withNewVersion( targetVersion.toString() ) - .build() ); - } - } - } - catch ( InvalidSegmentException | InvalidVersionSpecificationException e ) - { - getLog().warn( String.format( "Skipping the processing of %s:%s due to: %s", property.getName(), - property.getVersion(), e.getMessage() ) ); - } - } + update( pom, getHelper().getVersionPropertiesMap( + VersionsHelper.VersionPropertiesMapRequest.builder() + .withMavenProject( getProject() ) + .withPropertyDefinitions( new Property[] { new Property( property ) + {{ + setVersion( newVersion ); + }} } ) + .withIncludeProperties( property ) + .withAutoLinkItems( autoLinkItems ) + .withIncludeParent( includeParent ) + .build() ) ); } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java index 62c034b10..2da6749d0 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java @@ -22,11 +22,15 @@ import java.nio.file.Paths; import org.codehaus.mojo.versions.change.DefaultVersionChange; -import org.hamcrest.Matchers; +import org.codehaus.mojo.versions.utils.TestChangeRecorder; +import org.codehaus.mojo.versions.utils.TestUtils; import org.junit.Test; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; /** * Unit tests for {@link UpdatePropertiesMojo} @@ -39,7 +43,7 @@ public void testAllowMajorUpdates() throws Exception Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/update-properties/issue-454-pom.xml" ), Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING ); setUpMojo( "update-properties" ).execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( + assertThat( changeRecorder.getChanges(), hasItem( new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "2.0.0-M1" ) ) ); } @@ -51,7 +55,7 @@ public void testAllowMinorUpdates() throws Exception UpdatePropertiesMojo mojo = setUpMojo( "update-properties" ); mojo.allowMajorUpdates = false; mojo.execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( + assertThat( changeRecorder.getChanges(), hasItem( new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "1.1.0-alpha" ) ) ); } @@ -64,7 +68,23 @@ public void testAllowIncrementalUpdates() throws Exception mojo.allowMajorUpdates = false; mojo.allowMinorUpdates = false; mojo.execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( + assertThat( changeRecorder.getChanges(), hasItem( new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "1.0.1-rc1" ) ) ); } + + @Test + public void testChangesNotRegisteredIfNoUpdatesInPom() + throws Exception + { + TestUtils.copyDir( Paths.get( "src/test/resources/org/codehaus/mojo/update-properties/issue-837" ), + pomDir ); + UpdatePropertiesMojo mojo = setUpMojo( "update-properties" ); + TestChangeRecorder changeRecorder = new TestChangeRecorder(); + setVariableValueToObject( mojo, "changeRecorders", changeRecorder.asTestMap() ); + setVariableValueToObject( mojo, "changeRecorderFormat", "none" ); +// pomHelperClass.when( () -> PomHelper.setPropertyVersion( any(), anyString(), anyString(), anyString() ) ) +// .thenReturn( false ); + mojo.execute( ); + assertThat( changeRecorder.getChanges(), is( empty() ) ); + } } diff --git a/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/parent-pom.xml b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/parent-pom.xml new file mode 100644 index 000000000..d01abb3ee --- /dev/null +++ b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/parent-pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + + default-group + parent-artifact + 1.0.0 + pom + + + 1.0 + + + diff --git a/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/pom.xml b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/pom.xml new file mode 100644 index 000000000..31c6622ec --- /dev/null +++ b/versions-maven-plugin/src/test/resources/org/codehaus/mojo/update-properties/issue-837/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + + default-group + parent-artifact + 1.0.0 + parent-pom.xml + + + child-artifact + 1.0.0 + + + + default-group + default-artifact + ${artifact-version} + + + +