From 8fb889a4a3a47eab6c4a038e4cb68ad5a49fc765 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 --------- .../dummy-api-3.4.0-20090311.051742-1.pom | 49 ++++++++++++ .../src/it-repo/dummy-api-3.4.0-SNAPSHOT.pom | 2 +- .../src/it-repo/dummy-bom-pom-2.0.pom | 26 +++++++ .../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 | 23 ++++++ .../verify.groovy | 4 + .../invoker.properties | 1 + .../it-use-latest-releases-issue-134/pom.xml | 23 ++++++ .../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 | 23 ++++++ .../verify.groovy | 4 + .../invoker.properties | 1 + .../it/it-use-next-releases-issue-134/pom.xml | 23 ++++++ .../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 | 14 +++- .../mojo/versions/LockSnapshotsMojo.java | 30 ++++++-- .../mojo/versions/UnlockSnapshotsMojo.java | 19 ++++- .../mojo/versions/UseDepVersionMojo.java | 14 +++- .../mojo/versions/UseLatestReleasesMojo.java | 14 +++- .../mojo/versions/UseLatestSnapshotsMojo.java | 14 +++- .../mojo/versions/UseLatestVersionsMojo.java | 2 +- .../mojo/versions/UseNextReleasesMojo.java | 24 +++++- .../mojo/versions/UseNextSnapshotsMojo.java | 11 ++- .../mojo/versions/UseNextVersionsMojo.java | 14 +++- .../mojo/versions/UseReactorMojo.java | 13 +++- .../mojo/versions/UseReleasesMojo.java | 14 +++- .../mojo/versions/ForceReleasesMojoTest.java | 10 +++ .../versions/UseLatestReleasesMojoTest.java | 2 + .../mojo/versions/UseReleasesMojoTest.java | 6 ++ 53 files changed, 547 insertions(+), 189 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-api-3.4.0-20090311.051742-1.pom create mode 100644 versions-maven-plugin/src/it-repo/dummy-bom-pom-2.0.pom 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-api-3.4.0-20090311.051742-1.pom b/versions-maven-plugin/src/it-repo/dummy-api-3.4.0-20090311.051742-1.pom new file mode 100644 index 0000000000..42ca02dd5f --- /dev/null +++ b/versions-maven-plugin/src/it-repo/dummy-api-3.4.0-20090311.051742-1.pom @@ -0,0 +1,49 @@ + + 4.0.0 + + localhost + dummy-api + 3.4.0-20090311.051742-1 + jar + + + + + + maven-clean-plugin + 2.2 + + + maven-compiler-plugin + 2.0.2 + + + maven-deploy-plugin + 2.3 + + + maven-install-plugin + 2.2 + + + maven-jar-plugin + 2.2 + + + maven-resources-plugin + 2.2 + + + maven-site-plugin + 2.0 + + + maven-surefire-plugin + 2.4.2 + + + + + + diff --git a/versions-maven-plugin/src/it-repo/dummy-api-3.4.0-SNAPSHOT.pom b/versions-maven-plugin/src/it-repo/dummy-api-3.4.0-SNAPSHOT.pom index 6031608461..fe4859f8c2 100644 --- a/versions-maven-plugin/src/it-repo/dummy-api-3.4.0-SNAPSHOT.pom +++ b/versions-maven-plugin/src/it-repo/dummy-api-3.4.0-SNAPSHOT.pom @@ -4,7 +4,7 @@ localhost dummy-api - 3.1.5-SNAPSHOT + 3.4.0-SNAPSHOT jar diff --git a/versions-maven-plugin/src/it-repo/dummy-bom-pom-2.0.pom b/versions-maven-plugin/src/it-repo/dummy-bom-pom-2.0.pom new file mode 100644 index 0000000000..a8505b22b7 --- /dev/null +++ b/versions-maven-plugin/src/it-repo/dummy-bom-pom-2.0.pom @@ -0,0 +1,26 @@ + + 4.0.0 + + localhost + dummy-bom-pom + 2.0 + pom + + + + + org.apache.maven + maven-artifact + 2.0.9 + + + junit + junit + 4.1 + + + + + + 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..e05afd56c0 --- /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 + + + + + localhost + dummy-api + 3.4.0-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..08dd0bfdf7 --- /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 == '3.4.0-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..64df452751 --- /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=2.0.0 -Dincludes=localhost:dummy-bom2 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..722f1ed5ae --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-dep-version-issue-134/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134 + 1.0 + pom + Check if boms are upated + + + + + localhost + dummy-bom2 + 1.0.0 + 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..b45ebad17c --- /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 == '2.0.0' 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..722f1ed5ae --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-releases-issue-134/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134 + 1.0 + pom + Check if boms are upated + + + + + localhost + dummy-bom2 + 1.0.0 + 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..b45ebad17c --- /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 == '2.0.0' 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..722f1ed5ae --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-latest-versions-issue-134/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + localhost + it-use-releases-issue-134 + 1.0 + pom + Check if boms are upated + + + + + localhost + dummy-bom2 + 1.0.0 + 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..b45ebad17c --- /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 == '2.0.0' 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..b6cc63ad94 --- /dev/null +++ b/versions-maven-plugin/src/it/it-use-next-releases-issue-134/pom.xml @@ -0,0 +1,23 @@ + + 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 + 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..6bbc4ba6ab --- /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 == '1.1.0' 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 564817c333..abd249228b 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; @@ -33,6 +34,7 @@ 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; @@ -40,6 +42,7 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; +import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -86,9 +89,14 @@ 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() ) { @@ -99,7 +107,7 @@ protected void update( ModifiedPomXMLEventReader pom ) useReleases( pom, singletonList( getParentDependency() ) ); } } - 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 1e57f49ba2..2749037519 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 91c3635994..408cec4349 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 9c6b649c0e..bfbc42d9eb 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; @@ -37,6 +39,7 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; +import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -99,9 +102,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() ) @@ -114,7 +122,7 @@ protected void update( ModifiedPomXMLEventReader pom ) useDepVersion( pom, singletonList( getParentDependency() ) ); } } - 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 1394abce62..5c80e70909 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; @@ -36,12 +37,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; @@ -119,9 +122,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() ) { @@ -132,7 +140,7 @@ protected void update( ModifiedPomXMLEventReader pom ) useLatestReleases( pom, singletonList( getParentDependency() ) ); } } - 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 0e4249a178..33d1785553 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.Arrays; import java.util.Collection; import java.util.Comparator; @@ -32,12 +33,14 @@ 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; 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; @@ -108,9 +111,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() ) { @@ -121,7 +129,7 @@ protected void update( ModifiedPomXMLEventReader pom ) useLatestSnapshots( pom, singletonList( getParentDependency() ) ); } } - 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 d5fb92067a..57235889ca 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 @@ -129,7 +129,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 0045193de5..05705f90dc 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.Pattern; @@ -30,11 +31,13 @@ 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; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; +import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -80,13 +83,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 ); } if ( getProject().getParent() != null && isProcessingParent() ) { 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 3546193a89..afaf413029 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; @@ -31,12 +32,14 @@ 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; 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; @@ -109,9 +112,11 @@ 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() ) { @@ -122,7 +127,7 @@ protected void update( ModifiedPomXMLEventReader pom ) useNextSnapshots( pom, singletonList( getParentDependency() ) ); } } - 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 81c9fbaa50..529e983e40 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.manager.WagonManager; @@ -29,11 +30,13 @@ 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; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; +import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -74,9 +77,14 @@ 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() ) { @@ -87,7 +95,7 @@ protected void update( ModifiedPomXMLEventReader pom ) useNextVersions( pom, singletonList( getParentDependency() ) ); } } - 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 eac9aac15e..1a4704f8f2 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.Arrays; import java.util.Collection; import java.util.Optional; @@ -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; @@ -101,10 +103,14 @@ protected void update( ModifiedPomXMLEventReader pom ) { try { - 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() ) { @@ -115,7 +121,7 @@ protected void update( ModifiedPomXMLEventReader pom ) useReleases( pom, singletonList( getParentDependency() ) ); } } - catch ( ArtifactMetadataRetrievalException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java index e1af267f61..983fa90629 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java @@ -97,6 +97,8 @@ public void testProcessParent() { pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), anyString() ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } assertThat( changeRecorder.getChanges(), @@ -119,6 +121,8 @@ public void testReplaceSnapshotWithRelease() pomHelper.when( () -> PomHelper.setDependencyVersion( any(), anyString(), anyString(), anyString(), anyString(), any( Model.class ) ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } assertThat( changeRecorder.getChanges(), @@ -141,6 +145,8 @@ public void testUpgrade() pomHelper.when( () -> PomHelper.setDependencyVersion( any(), anyString(), anyString(), anyString(), anyString(), any( Model.class ) ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } assertThat( changeRecorder.getChanges(), @@ -163,6 +169,8 @@ public void testDowngrade() pomHelper.when( () -> PomHelper.setDependencyVersion( any(), anyString(), anyString(), anyString(), anyString(), any( Model.class ) ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } assertThat( changeRecorder.getChanges(), @@ -188,6 +196,8 @@ public void testFailIfNotReplaced() pomHelper.when( () -> PomHelper.setDependencyVersion( any(), anyString(), anyString(), anyString(), anyString(), any( Model.class ) ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); fail( "MojoExecutionException is expected" ); } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java index 5e880c70ed..72fd58f2d5 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java @@ -101,6 +101,8 @@ public void testDontUpgradeToBeta() { pomHelper.when( () -> PomHelper.setDependencyVersion( any(), any(), any(), any(), any(), any() ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } assertThat( changeRecorder.getChanges(), Matchers.empty() ); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java index d59da171ab..6e2b40bfbf 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java @@ -97,6 +97,8 @@ public void testProcessParent() { pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), anyString() ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } assertThat( changeRecorder.getChanges(), @@ -119,6 +121,8 @@ public void testReplaceSnapshotWithRelease() pomHelper.when( () -> PomHelper.setDependencyVersion( any(), anyString(), anyString(), anyString(), anyString(), any( Model.class ) ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); } assertThat( changeRecorder.getChanges(), @@ -144,6 +148,8 @@ public void testFailIfNotReplaced() pomHelper.when( () -> PomHelper.setDependencyVersion( any(), anyString(), anyString(), anyString(), anyString(), any( Model.class ) ) ) .thenReturn( true ); + pomHelper.when( () -> PomHelper.getRawModel( any( MavenProject.class ) ) ) + .thenReturn( mojo.getProject().getModel() ); mojo.update( null ); fail( "MojoExecutionException is expected" ); }