From 8fe726e5c434d9676e811220e3642b018bd28cbb Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Fri, 11 Nov 2022 08:28:36 +0100 Subject: [PATCH] Issue #134: Removing the patch: no longer needed; PomHelper.getRawModel can be used instead. Adding more integration tests. --- .../codehaus/mojo/versions/api/PomHelper.java | 75 ------------------- .../mojo/versions/api/PomHelperTest.java | 35 --------- ...elperTest.dependencyManagementBOMs.pom.xml | 37 --------- .../src/it-repo/dummy-bom2-1.0.0-SNAPSHOT.pom | 12 +++ .../src/it-repo/dummy-bom2-1.0.0.pom | 12 +++ .../src/it-repo/dummy-bom2-1.1.0.pom | 12 +++ .../src/it-repo/dummy-bom2-2.0.0.pom | 12 +++ .../src/it-repo/dummy-bom2-3.0.0-SNAPSHOT.pom | 12 +++ .../invoker.properties | 1 + .../it/it-force-releases-issue-134/pom.xml | 22 ++++++ .../it-force-releases-issue-134/verify.groovy | 4 + .../invoker.properties | 1 + .../it/it-unlock-snapshots-issue-134/pom.xml | 22 ++++++ .../verify.groovy | 4 + .../invoker.properties | 2 + .../it/it-use-dep-version-issue-134/pom.xml | 24 ++++++ .../verify.groovy | 4 + .../invoker.properties | 1 + .../it-use-latest-releases-issue-134/pom.xml | 24 ++++++ .../verify.groovy | 4 + .../invoker.properties | 2 + .../it-use-latest-snapshots-issue-134/pom.xml | 22 ++++++ .../verify.groovy | 4 + .../invoker.properties | 1 + .../it-use-latest-versions-issue-134/pom.xml | 24 ++++++ .../verify.groovy | 4 + .../invoker.properties | 1 + .../it/it-use-next-releases-issue-134/pom.xml | 24 ++++++ .../verify.groovy | 4 + .../invoker.properties | 2 + .../it-use-next-snapshots-issue-134/pom.xml | 22 ++++++ .../verify.groovy | 5 ++ .../invoker.properties | 1 + .../src/it/it-use-releases-issue-134/pom.xml | 22 ++++++ .../it-use-releases-issue-134/verify.groovy | 4 + .../mojo/versions/ForceReleasesMojo.java | 13 +++- .../mojo/versions/LockSnapshotsMojo.java | 30 ++++++-- .../mojo/versions/UnlockSnapshotsMojo.java | 19 ++++- .../mojo/versions/UseDepVersionMojo.java | 13 +++- .../mojo/versions/UseLatestReleasesMojo.java | 14 +++- .../mojo/versions/UseLatestSnapshotsMojo.java | 13 +++- .../mojo/versions/UseLatestVersionsMojo.java | 2 +- .../mojo/versions/UseNextReleasesMojo.java | 23 +++++- .../mojo/versions/UseNextSnapshotsMojo.java | 10 ++- .../mojo/versions/UseNextVersionsMojo.java | 13 +++- .../mojo/versions/UseReactorMojo.java | 13 +++- .../mojo/versions/UseReleasesMojo.java | 15 +++- 47 files changed, 452 insertions(+), 188 deletions(-) delete mode 100644 versions-common/src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.dependencyManagementBOMs.pom.xml create mode 100644 versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0-SNAPSHOT.pom create mode 100644 versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0.pom create mode 100644 versions-maven-plugin/src/it-repo/dummy-bom2-1.1.0.pom create mode 100644 versions-maven-plugin/src/it-repo/dummy-bom2-2.0.0.pom create mode 100644 versions-maven-plugin/src/it-repo/dummy-bom2-3.0.0-SNAPSHOT.pom create mode 100644 versions-maven-plugin/src/it/it-force-releases-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-force-releases-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-force-releases-issue-134/verify.groovy create mode 100644 versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/verify.groovy create mode 100644 versions-maven-plugin/src/it/it-use-dep-version-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-use-dep-version-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-use-dep-version-issue-134/verify.groovy create mode 100644 versions-maven-plugin/src/it/it-use-latest-releases-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-use-latest-releases-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-use-latest-releases-issue-134/verify.groovy create mode 100644 versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/verify.groovy create mode 100644 versions-maven-plugin/src/it/it-use-latest-versions-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-use-latest-versions-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-use-latest-versions-issue-134/verify.groovy create mode 100644 versions-maven-plugin/src/it/it-use-next-releases-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-use-next-releases-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-use-next-releases-issue-134/verify.groovy create mode 100644 versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/verify.groovy create mode 100644 versions-maven-plugin/src/it/it-use-releases-issue-134/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-use-releases-issue-134/pom.xml create mode 100644 versions-maven-plugin/src/it/it-use-releases-issue-134/verify.groovy diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java index bf9b8e9591..938ba9ee19 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PomHelper.java @@ -29,7 +29,6 @@ import java.io.Reader; import java.io.StringReader; import java.nio.file.Files; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -62,7 +61,6 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; -import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.RegexUtils; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; @@ -1689,77 +1687,4 @@ public static String getGAV( Model model ) { return getGroupId( model ) + ":" + getArtifactId( model ) + ":" + getVersion( model ); } - - /** - * Reads imported POMs from the dependency management section. - * - * @param pom POM - * @return a non-null list of {@link Dependency} for each imported POM - * @throws XMLStreamException XML stream exception - * @see bug #134 - * @since 2.4 - */ - public static List readImportedPOMsFromDependencyManagementSection( ModifiedPomXMLEventReader pom ) - throws XMLStreamException - { - List importedPOMs = new ArrayList<>(); - Stack stack = new Stack<>(); - - String groupIdElement = "groupId"; - String artifactIdElement = "artifactId"; - String versionElement = "version"; - String typeElement = "type"; - String scopeElement = "scope"; - Set recognizedElements = - new HashSet<>( Arrays.asList( groupIdElement, artifactIdElement, versionElement, typeElement, - scopeElement ) ); - Map depData = new HashMap<>(); - - pom.rewind(); - - String depMgmtDependencyPath = "/project/dependencyManagement/dependencies/dependency"; - - while ( pom.hasNext() ) - { - XMLEvent event = pom.nextEvent(); - - if ( event.isStartElement() ) - { - final String elementName = event.asStartElement().getName().getLocalPart(); - String parent = ""; - if ( !stack.isEmpty() ) - { - parent = stack.peek(); - } - String currentPath = parent + "/" + elementName; - stack.push( currentPath ); - - if ( currentPath.startsWith( depMgmtDependencyPath ) && recognizedElements.contains( elementName ) ) - { - final String elementText = pom.getElementText().trim(); - depData.put( elementName, elementText ); - stack.pop(); - } - } - if ( event.isEndElement() ) - { - String path = stack.pop(); - if ( depMgmtDependencyPath.equals( path ) ) - { - if ( "pom".equals( depData.get( typeElement ) ) && "import".equals( depData.get( scopeElement ) ) ) - { - importedPOMs.add( DependencyBuilder.newBuilder() - .withGroupId( depData.get( groupIdElement ) ) - .withArtifactId( depData.get( artifactIdElement ) ) - .withVersion( depData.get( versionElement ) ) - .withType( depData.get( typeElement ) ) - .withScope( depData.get( scopeElement ) ) - .build() ); - } - depData.clear(); - } - } - } - return importedPOMs; - } } diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java index 460883f855..4e50637ec6 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/api/PomHelperTest.java @@ -25,10 +25,8 @@ import java.io.File; import java.io.StringReader; import java.net.URL; -import java.util.List; import java.util.Map; -import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.logging.SystemStreamLog; @@ -64,39 +62,6 @@ public static void setUpClass() INPUT_FACTORY.setProperty( P_PRESERVE_LOCATION, Boolean.TRUE ); } - /** - * Tests if imported POMs are properly read from dependency management section. Such logic is required to resolve - * bug #134 - * - * @throws Exception if the test fails. - */ - @Test - public void testImportedPOMsRetrievedFromDependencyManagement() - throws Exception - { - URL url = getClass().getResource( "PomHelperTest.dependencyManagementBOMs.pom.xml" ); - assert url != null; - File file = new File( url.getPath() ); - StringBuilder input = PomHelper.readXmlFile( file ); - - XMLInputFactory inputFactory = XMLInputFactory2.newInstance(); - inputFactory.setProperty( P_PRESERVE_LOCATION, Boolean.TRUE ); - - ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader( input, inputFactory, file.getAbsolutePath() ); - - List dependencies = PomHelper.readImportedPOMsFromDependencyManagementSection( pom ); - - assertNotNull( dependencies ); - assertEquals( 1, dependencies.size() ); - - Dependency dependency = dependencies.get( 0 ); - assertEquals( "org.group1", dependency.getGroupId() ); - assertEquals( "artifact-pom", dependency.getArtifactId() ); - assertEquals( "1.0-SNAPSHOT", dependency.getVersion() ); - assertEquals( "import", dependency.getScope() ); - assertEquals( "pom", dependency.getType() ); - } - /** * Tests what happens when changing a long property substitution pattern, e.g. * MVERSIONS-44 diff --git a/versions-common/src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.dependencyManagementBOMs.pom.xml b/versions-common/src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.dependencyManagementBOMs.pom.xml deleted file mode 100644 index a3d776cb8e..0000000000 --- a/versions-common/src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.dependencyManagementBOMs.pom.xml +++ /dev/null @@ -1,37 +0,0 @@ - - 4.0.0 - - org.myorg - myorg-parent - 3.0-SNAPSHOT - - bug-79 - jar - extracts BOMs from dependency management - - - - org.group1 - artifact-pom - 1.0-SNAPSHOT - pom - import - - - org.group1 - artifact-jar - 1.0-SNAPSHOT - jar - import - - - org.group1 - artifact-pom-standard - 1.0-SNAPSHOT - pom - - - - diff --git a/versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0-SNAPSHOT.pom b/versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0-SNAPSHOT.pom new file mode 100644 index 0000000000..7df8fa659d --- /dev/null +++ b/versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0-SNAPSHOT.pom @@ -0,0 +1,12 @@ + + + 4.0.0 + + localhost + dummy-bom2 + 1.0.0-SNAPSHOT + pom + + diff --git a/versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0.pom b/versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0.pom new file mode 100644 index 0000000000..b255aaf959 --- /dev/null +++ b/versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0.pom @@ -0,0 +1,12 @@ + + + 4.0.0 + + localhost + dummy-bom2 + 1.0.0 + pom + + diff --git a/versions-maven-plugin/src/it-repo/dummy-bom2-1.1.0.pom b/versions-maven-plugin/src/it-repo/dummy-bom2-1.1.0.pom new file mode 100644 index 0000000000..f2742a8734 --- /dev/null +++ b/versions-maven-plugin/src/it-repo/dummy-bom2-1.1.0.pom @@ -0,0 +1,12 @@ + + + 4.0.0 + + localhost + dummy-bom2 + 1.1.0 + pom + + diff --git a/versions-maven-plugin/src/it-repo/dummy-bom2-2.0.0.pom b/versions-maven-plugin/src/it-repo/dummy-bom2-2.0.0.pom new file mode 100644 index 0000000000..ed99f6f7c2 --- /dev/null +++ b/versions-maven-plugin/src/it-repo/dummy-bom2-2.0.0.pom @@ -0,0 +1,12 @@ + + + 4.0.0 + + localhost + dummy-bom2 + 2.0.0 + pom + + diff --git a/versions-maven-plugin/src/it-repo/dummy-bom2-3.0.0-SNAPSHOT.pom b/versions-maven-plugin/src/it-repo/dummy-bom2-3.0.0-SNAPSHOT.pom new file mode 100644 index 0000000000..28b3d482fb --- /dev/null +++ b/versions-maven-plugin/src/it-repo/dummy-bom2-3.0.0-SNAPSHOT.pom @@ -0,0 +1,12 @@ + + + 4.0.0 + + localhost + dummy-bom2 + 3.0.0-SNAPSHOT + pom + + diff --git a/versions-maven-plugin/src/it/it-force-releases-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-force-releases-issue-134/invoker.properties new file mode 100644 index 0000000000..dc5a148e5f --- /dev/null +++ b/versions-maven-plugin/src/it/it-force-releases-issue-134/invoker.properties @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:force-releases diff --git a/versions-maven-plugin/src/it/it-force-releases-issue-134/pom.xml b/versions-maven-plugin/src/it/it-force-releases-issue-134/pom.xml new file mode 100644 index 0000000000..f65bc49375 --- /dev/null +++ b/versions-maven-plugin/src/it/it-force-releases-issue-134/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134-001 + 1.0 + pom + Check if boms are upated from snapshots + + + + + localhost + dummy-bom2 + 1.0.0-SNAPSHOT + import + + + + + diff --git a/versions-maven-plugin/src/it/it-force-releases-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-force-releases-issue-134/verify.groovy new file mode 100644 index 0000000000..3dd9dee67e --- /dev/null +++ b/versions-maven-plugin/src/it/it-force-releases-issue-134/verify.groovy @@ -0,0 +1,4 @@ +def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version == '1.0.0' diff --git a/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/invoker.properties new file mode 100644 index 0000000000..bcc6fac2b2 --- /dev/null +++ b/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/invoker.properties @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:unlock-snapshots diff --git a/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/pom.xml b/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/pom.xml new file mode 100644 index 0000000000..aa513086c2 --- /dev/null +++ b/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134 + 1.0 + pom + Check if boms are upated + + + + + org.codehaus.plexus + plexus-utils + 1.5.1-20090311.051742-1 + import + + + + + diff --git a/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/verify.groovy new file mode 100644 index 0000000000..0ed9307f57 --- /dev/null +++ b/versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/verify.groovy @@ -0,0 +1,4 @@ +def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version == '1.5.1-SNAPSHOT' diff --git a/versions-maven-plugin/src/it/it-use-dep-version-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-use-dep-version-issue-134/invoker.properties new file mode 100644 index 0000000000..0c1792b4c8 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-dep-version-issue-134/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-dep-version +invoker.mavenOpts = -DdepVersion=31 -Dincludes=org.apache.maven:maven-parent diff --git a/versions-maven-plugin/src/it/it-use-dep-version-issue-134/pom.xml b/versions-maven-plugin/src/it/it-use-dep-version-issue-134/pom.xml new file mode 100644 index 0000000000..297fbabc55 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-dep-version-issue-134/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134 + 1.0 + pom + Check if boms are upated + + + + + org.apache.maven + maven-parent + + 30 + pom + import + + + + + diff --git a/versions-maven-plugin/src/it/it-use-dep-version-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-use-dep-version-issue-134/verify.groovy new file mode 100644 index 0000000000..280bda407e --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-dep-version-issue-134/verify.groovy @@ -0,0 +1,4 @@ +def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version == 31 diff --git a/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/invoker.properties new file mode 100644 index 0000000000..4f292723b5 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/invoker.properties @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-latest-releases diff --git a/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/pom.xml b/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/pom.xml new file mode 100644 index 0000000000..297fbabc55 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134 + 1.0 + pom + Check if boms are upated + + + + + org.apache.maven + maven-parent + + 30 + pom + import + + + + + diff --git a/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/verify.groovy new file mode 100644 index 0000000000..390a92bf67 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/verify.groovy @@ -0,0 +1,4 @@ +def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version != '30-SNAPSHOT' diff --git a/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/invoker.properties new file mode 100644 index 0000000000..f08807aca2 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-latest-snapshots +invoker.mavenOpts = -DallowMajorUpdates=true -DallowMinorUpdates=true -DallowIncrementalUpdates=true diff --git a/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/pom.xml b/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/pom.xml new file mode 100644 index 0000000000..2a7f216136 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134-001 + 1.0 + pom + Check if boms are upated from snapshots + + + + + localhost + dummy-bom2 + 1.0.0 + import + + + + + diff --git a/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/verify.groovy new file mode 100644 index 0000000000..b3f3e21cb0 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-snapshots-issue-134/verify.groovy @@ -0,0 +1,4 @@ +def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version == '3.0.0-SNAPSHOT' diff --git a/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/invoker.properties new file mode 100644 index 0000000000..4f292723b5 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/invoker.properties @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-latest-releases diff --git a/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/pom.xml b/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/pom.xml new file mode 100644 index 0000000000..297fbabc55 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134 + 1.0 + pom + Check if boms are upated + + + + + org.apache.maven + maven-parent + + 30 + pom + import + + + + + diff --git a/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/verify.groovy new file mode 100644 index 0000000000..5502f88d99 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/verify.groovy @@ -0,0 +1,4 @@ +def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version != 30 diff --git a/versions-maven-plugin/src/it/it-use-next-releases-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-use-next-releases-issue-134/invoker.properties new file mode 100644 index 0000000000..91990633ca --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-next-releases-issue-134/invoker.properties @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-next-releases diff --git a/versions-maven-plugin/src/it/it-use-next-releases-issue-134/pom.xml b/versions-maven-plugin/src/it/it-use-next-releases-issue-134/pom.xml new file mode 100644 index 0000000000..e2c89e9f3b --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-next-releases-issue-134/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134-001 + 1.0 + pom + Check if boms are upated from snapshots + + + + + org.apache.maven + maven-parent + + 30 + pom + import + + + + + diff --git a/versions-maven-plugin/src/it/it-use-next-releases-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-use-next-releases-issue-134/verify.groovy new file mode 100644 index 0000000000..280bda407e --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-next-releases-issue-134/verify.groovy @@ -0,0 +1,4 @@ +def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version == 31 diff --git a/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/invoker.properties new file mode 100644 index 0000000000..16012c01fd --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-next-snapshots +invoker.mavenOpts = -DallowMajorUpdates=true -DallowMinorUpdates=true -DallowIncrementalUpdates=true diff --git a/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/pom.xml b/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/pom.xml new file mode 100644 index 0000000000..8c2f71d5af --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134-001 + 1.0 + pom + Check if boms are upated from snapshots + + + + + localhost + dummy-bom2 + 0.9.0 + import + + + + + diff --git a/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/verify.groovy new file mode 100644 index 0000000000..080a7ed855 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-next-snapshots-issue-134/verify.groovy @@ -0,0 +1,5 @@ +def project = new XmlSlurper() + .parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version == '1.0.0-SNAPSHOT' diff --git a/versions-maven-plugin/src/it/it-use-releases-issue-134/invoker.properties b/versions-maven-plugin/src/it/it-use-releases-issue-134/invoker.properties new file mode 100644 index 0000000000..dc5a148e5f --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-releases-issue-134/invoker.properties @@ -0,0 +1 @@ +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:force-releases diff --git a/versions-maven-plugin/src/it/it-use-releases-issue-134/pom.xml b/versions-maven-plugin/src/it/it-use-releases-issue-134/pom.xml new file mode 100644 index 0000000000..8907c2373d --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-releases-issue-134/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + + localhost + it-force-releases-issue-134-001 + 1.0 + pom + Check if boms are upated from snapshots + + + + + localhost + dummy-bom2 + 1.0.0-SNAPSHOT + import + + + + + diff --git a/versions-maven-plugin/src/it/it-use-releases-issue-134/verify.groovy b/versions-maven-plugin/src/it/it-use-releases-issue-134/verify.groovy new file mode 100644 index 0000000000..3dd9dee67e --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-releases-issue-134/verify.groovy @@ -0,0 +1,4 @@ +def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) ) + +assert project.dependencyManagement.dependencies.'*'.size() == 1 +assert project.dependencyManagement.dependencies.dependency.version == '1.0.0' diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java index 56c9812643..31e4a3351a 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -33,6 +34,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -84,16 +86,21 @@ protected void update( ModifiedPomXMLEventReader pom ) { try { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + if ( isProcessingDependencyManagement() ) { - useReleases( pom, getProject().getDependencyManagement().getDependencies() ); + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + useReleases( pom, dependencyManagement.getDependencies() ); + } } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useReleases( pom, getProject().getDependencies() ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java index 9e17a35942..45063bbb40 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -31,6 +32,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -83,17 +85,29 @@ public LockSnapshotsMojo( RepositorySystem repositorySystem, protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) - { - lockSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); - } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) + try { - lockSnapshots( pom, getProject().getDependencies() ); + if ( isProcessingDependencyManagement() ) + { + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + lockSnapshots( pom, dependencyManagement.getDependencies() ); + } + } + if ( getProject().getDependencies() != null && isProcessingDependencies() ) + { + lockSnapshots( pom, getProject().getDependencies() ); + } + if ( getProject().getParent() != null && isProcessingParent() ) + { + lockParentSnapshot( pom, getProject().getParent() ); + } } - if ( getProject().getParent() != null && isProcessingParent() ) + catch ( IOException e ) { - lockParentSnapshot( pom, getProject().getParent() ); + throw new MojoExecutionException( e.getMessage(), e ); } } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java index d338a53d34..b711f81576 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -31,6 +32,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -82,10 +84,16 @@ public UnlockSnapshotsMojo( RepositorySystem repositorySystem, protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { - - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + try + { + if ( isProcessingDependencyManagement() ) { - unlockSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + unlockSnapshots( pom, dependencyManagement.getDependencies() ); + } } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { @@ -95,6 +103,11 @@ protected void update( ModifiedPomXMLEventReader pom ) { unlockParentSnapshot( pom, getProject().getParent() ); } + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } } private void unlockSnapshots( ModifiedPomXMLEventReader pom, List dependencies ) diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java index ccd389e0ad..fd3f9e5424 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Collection; import org.apache.maven.artifact.Artifact; @@ -30,6 +31,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -98,9 +100,14 @@ protected void update( ModifiedPomXMLEventReader pom ) try { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + if ( isProcessingDependencyManagement() ) { - useDepVersion( pom, getProject().getDependencyManagement().getDependencies() ); + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + useDepVersion( pom, dependencyManagement.getDependencies() ); + } } if ( getProject().getDependencies() != null && isProcessingDependencies() ) @@ -108,7 +115,7 @@ protected void update( ModifiedPomXMLEventReader pom ) useDepVersion( pom, getProject().getDependencies() ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java index 8c248d1222..607e02c4da 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Optional; @@ -37,12 +38,14 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; 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.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; +import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -126,9 +129,14 @@ protected void update( ModifiedPomXMLEventReader pom ) { try { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + if ( isProcessingDependencyManagement() ) { - useLatestReleases( pom, getProject().getDependencyManagement().getDependencies() ); + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + useLatestReleases( pom, dependencyManagement.getDependencies() ); + } } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { @@ -144,7 +152,7 @@ protected void update( ModifiedPomXMLEventReader pom ) .build() ) ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java index 8e64ab4915..e263995413 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -38,6 +39,7 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.Restriction; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -124,9 +126,14 @@ protected void update( ModifiedPomXMLEventReader pom ) { try { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + if ( isProcessingDependencyManagement() ) { - useLatestSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + useLatestSnapshots( pom, dependencyManagement.getDependencies() ); + } } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { @@ -142,7 +149,7 @@ protected void update( ModifiedPomXMLEventReader pom ) .build() ) ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java index f5009dc2ee..d30179e6c8 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java @@ -130,7 +130,7 @@ protected void update( ModifiedPomXMLEventReader pom ) { try { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + if ( isProcessingDependencyManagement() ) { DependencyManagement dependencyManagement = PomHelper.getRawModel( getProject() ).getDependencyManagement(); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java index 149cc23f0f..39973a534f 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Collection; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -33,6 +34,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -82,13 +84,26 @@ public UseNextReleasesMojo( RepositorySystem repositorySystem, protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + try { - useNextReleases( pom, getProject().getDependencyManagement().getDependencies() ); + if ( isProcessingDependencyManagement() ) + { + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + useNextReleases( pom, dependencyManagement.getDependencies() ); + } + } + + if ( getProject().getDependencies() != null && isProcessingDependencies() ) + { + useNextReleases( pom, getProject().getDependencies() ); + } } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { - useNextReleases( pom, getProject().getDependencies() ); + throw new MojoExecutionException( e.getMessage(), e ); } } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java index b7482490ca..7bae6b7060 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.Optional; @@ -37,6 +38,7 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.Restriction; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -120,16 +122,18 @@ protected void update( ModifiedPomXMLEventReader pom ) { try { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) { - useNextSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); + useNextSnapshots( pom, dependencyManagement.getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useNextSnapshots( pom, getProject().getDependencies() ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java index ba0223cf98..eaf174b730 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Collection; import org.apache.maven.artifact.Artifact; @@ -31,6 +32,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -75,16 +77,21 @@ protected void update( ModifiedPomXMLEventReader pom ) { try { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + if ( isProcessingDependencyManagement() ) { - useNextVersions( pom, getProject().getDependencyManagement().getDependencies() ); + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + useNextVersions( pom, dependencyManagement.getDependencies() ); + } } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useNextVersions( pom, getProject().getDependencies() ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java index b4d2b91f81..a8333cb370 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Collection; import org.apache.commons.lang3.StringUtils; @@ -31,6 +32,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -79,16 +81,21 @@ protected void update( ModifiedPomXMLEventReader pom ) { useReactor( pom, getProject().getParent() ); } - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + if ( isProcessingDependencyManagement() ) { - useReactor( pom, getProject().getDependencyManagement().getDependencies() ); + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + useReactor( pom, dependencyManagement.getDependencies() ); + } } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useReactor( pom, getProject().getDependencies() ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java index 6e71ff0aaa..179a5116fb 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java @@ -22,6 +22,7 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.io.IOException; import java.util.Collection; import java.util.NoSuchElementException; import java.util.regex.Matcher; @@ -34,6 +35,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; +import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -109,17 +111,22 @@ protected void update( ModifiedPomXMLEventReader pom ) useReleases( pom, getProject().getParent() ); } - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + if ( isProcessingDependencyManagement() ) { - useReleases( pom, PomHelper.readImportedPOMsFromDependencyManagementSection( pom ) ); - useReleases( pom, getProject().getDependencyManagement().getDependencies() ); + DependencyManagement dependencyManagement = + PomHelper.getRawModel( getProject() ).getDependencyManagement(); + if ( dependencyManagement != null ) + { + useReleases( pom, dependencyManagement.getDependencies() ); + } } + if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useReleases( pom, getProject().getDependencies() ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); }