diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 8134287409..739ce3527c 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -22,11 +22,19 @@ is not compatible with project minimum version, not really a proposed upgrade - * [Fixed Issue 237][issue-237] + * [Fixed Issue 237][issue-237] and [Fixed Issue 288][issue-288] - Thanks to Julian Di Leonardo + Thanks to Julian Di Leonardo and [Adam Voss](https://github.com/adamvoss) - Adding parent processing to UseLatestVersion/UseLatestSnapshot/UseLatestRelease + Added parent processing to: + - UseLatestVersion + - UseLatestSnapshot + - UseLatestRelease + - ForceReleases + - UseDepVersion + - UseNextReleases + - UseNextSnapshots + - UseNextVersions * [Fixed Issue 190][issue-190] @@ -153,6 +161,7 @@ [issue-198]: https://github.com/mojohaus/versions-maven-plugin/issues/198 [issue-237]: https://github.com/mojohaus/versions-maven-plugin/issues/237 [issue-256]: https://github.com/mojohaus/versions-maven-plugin/issues/256 +[issue-288]: https://github.com/mojohaus/versions-maven-plugin/issues/288 [pull-189]: https://github.com/mojohaus/versions-maven-plugin/pull/189 [pull-252]: https://github.com/mojohaus/versions-maven-plugin/pull/252 diff --git a/src/it/it-use-next-releases-005/invoker.properties b/src/it/it-use-next-releases-005/invoker.properties new file mode 100644 index 0000000000..ee3e14b054 --- /dev/null +++ b/src/it/it-use-next-releases-005/invoker.properties @@ -0,0 +1 @@ +invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-next-releases diff --git a/src/it/it-use-next-releases-005/pom.xml b/src/it/it-use-next-releases-005/pom.xml new file mode 100644 index 0000000000..83ba229fe2 --- /dev/null +++ b/src/it/it-use-next-releases-005/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + localhost + dummy-parent + 1.0 + + + localhost + it-use-next-releases-005 + 1.0 + pom + Update a parent dependency + + + + + localhost + dummy-impl + 1.0 + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + true + + + + + + diff --git a/src/it/it-use-next-releases-005/verify.bsh b/src/it/it-use-next-releases-005/verify.bsh new file mode 100644 index 0000000000..7c158490d8 --- /dev/null +++ b/src/it/it-use-next-releases-005/verify.bsh @@ -0,0 +1,33 @@ +import java.io.*; +import java.util.regex.*; + +try +{ + File file = new File( basedir, "pom.xml" ); + + BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) ); + StringBuilder buf = new StringBuilder(); + String line = in.readLine(); + while ( line != null ) + { + buf.append( line ); + buf.append( " " ); + line = in.readLine(); + } + + Pattern p = Pattern.compile( "\\Q\\E.*\\Q\\E\\s*2\\.0\\s*\\Q\\E.*\\Q\\E" ); + Matcher m = p.matcher( buf.toString() ); + if ( !m.find() ) + { + System.out.println( "Did not update parent to version 2.0" ); + return false; + } + System.out.println( m.group( 0 ) ); +} +catch( Throwable t ) +{ + t.printStackTrace(); + return false; +} + +return true; diff --git a/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java b/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java index adc99f944f..0eb49371f1 100644 --- a/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java @@ -22,6 +22,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -44,7 +45,7 @@ */ @Mojo( name = "force-releases", requiresProject = true, requiresDirectInvocation = true, threadSafe = true ) public class ForceReleasesMojo - extends AbstractVersionsDependencyUpdaterMojo + extends ParentUpdatingDependencyUpdateMojo { // ------------------------------ FIELDS ------------------------------ @@ -56,31 +57,12 @@ public class ForceReleasesMojo // ------------------------------ METHODS -------------------------- - /** - * @param pom the pom to update. - * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong - * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way - * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming - * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) - */ - protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + + @Override + protected void setVersions(ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException { - try - { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) - { - useReleases( pom, getProject().getDependencyManagement().getDependencies() ); - } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) - { - useReleases( pom, getProject().getDependencies() ); - } - } - catch ( ArtifactMetadataRetrievalException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } + useReleases(pom, dependencies); } private void useReleases( ModifiedPomXMLEventReader pom, Collection dependencies ) @@ -113,11 +95,7 @@ private void useReleases( ModifiedPomXMLEventReader pom, Collection ArtifactVersions versions = getHelper().lookupArtifactVersions( artifact, false ); if ( versions.containsVersion( releaseVersion ) ) { - if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, - releaseVersion, getProject().getModel() ) ) - { - getLog().info( "Updated " + toString( dep ) + " to version " + releaseVersion ); - } + setVersion(pom, dep, version, artifact, new DefaultArtifactVersion(releaseVersion)); } else { @@ -126,10 +104,8 @@ releaseVersion, getProject().getModel() ) ) { getLog().info( "No release of " + toString( dep ) + " to force." ); } - else if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, - v[v.length - 1].toString(), getProject().getModel() ) ) - { - getLog().info( "Reverted " + toString( dep ) + " to version " + v[v.length - 1].toString() ); + else { + setVersion(pom, dep, version, artifact, v[v.length - 1]); } } } diff --git a/src/main/java/org/codehaus/mojo/versions/ParentUpdatingDependencyUpdateMojo.java b/src/main/java/org/codehaus/mojo/versions/ParentUpdatingDependencyUpdateMojo.java new file mode 100644 index 0000000000..472861710f --- /dev/null +++ b/src/main/java/org/codehaus/mojo/versions/ParentUpdatingDependencyUpdateMojo.java @@ -0,0 +1,78 @@ +package org.codehaus.mojo.versions; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; + +import javax.xml.stream.XMLStreamException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public abstract class ParentUpdatingDependencyUpdateMojo extends AbstractVersionsDependencyUpdaterMojo +{ + /** + * @param pom the pom to update. + * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong + * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way + * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming + * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) + */ + protected void update( ModifiedPomXMLEventReader pom ) + throws MojoExecutionException, MojoFailureException, XMLStreamException + { + try + { + if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + { + setVersions( pom, getProject().getDependencyManagement().getDependencies() ); + } + if ( getProject().getDependencies() != null && isProcessingDependencies() ) + { + setVersions( pom, getProject().getDependencies() ); + } + if ( getProject().getParent() != null && isProcessingParent() ) + { + final Dependency dependency = new Dependency(); + dependency.setArtifactId(getProject().getParent().getArtifactId()); + dependency.setGroupId(getProject().getParent().getGroupId()); + dependency.setVersion(getProject().getParent().getVersion()); + dependency.setType("pom"); + setVersions( pom, Collections.singleton(dependency)); + } + } + catch ( ArtifactMetadataRetrievalException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } + + protected abstract void setVersions(ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException; + + protected void setVersion(ModifiedPomXMLEventReader pom, Dependency dep, String version, Artifact artifact, ArtifactVersion artifactVersion) throws XMLStreamException + { + final String newVersion = artifactVersion.toString(); + if(getProject().getParent() != null){ + if(artifact.getId().equals(getProject().getParentArtifact().getId()) && isProcessingParent()) + { + if ( PomHelper.setProjectParentVersion( pom, newVersion.toString() ) ) + { + getLog().debug( "Made parent change from " + version + " to " + newVersion.toString() ); + } + } + } + + if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, + newVersion, getProject().getModel() ) ) + { + getLog().info( "Changed " + toString( dep ) + " to version " + newVersion ); + } + } +} diff --git a/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java b/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java index 1f2098eedc..d2573bcce1 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java @@ -26,13 +26,14 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.model.Dependency; 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.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -41,7 +42,7 @@ */ @Mojo( name = "use-dep-version", requiresProject = true, requiresDirectInvocation = true, threadSafe = true ) public class UseDepVersionMojo - extends AbstractVersionsDependencyUpdaterMojo + extends ParentUpdatingDependencyUpdateMojo { /** @@ -57,12 +58,10 @@ public class UseDepVersionMojo @Parameter( property = "forceVersion", defaultValue = "false" ) protected boolean forceVersion; - @SuppressWarnings( "unchecked" ) @Override - protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException + protected void update(ModifiedPomXMLEventReader pom) + throws MojoExecutionException, MojoFailureException, XMLStreamException { - if ( depVersion == null || depVersion.equals( "" ) ) { throw new IllegalArgumentException( "depVersion must be supplied with use-specific-version, and cannot be blank." ); @@ -73,22 +72,14 @@ protected void update( ModifiedPomXMLEventReader pom ) throw new IllegalArgumentException( "The use-specific-version goal is intended to be used with a single artifact. Please specify a value for the 'includes' parameter, or use -DforceVersion=true to override this check." ); } - try - { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) - { - useDepVersion( pom, getProject().getDependencyManagement().getDependencies() ); - } + super.update(pom); + } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) - { - useDepVersion( pom, getProject().getDependencies() ); - } - } - catch ( ArtifactMetadataRetrievalException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } + @Override + protected void setVersions(ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException + { + useDepVersion(pom, dependencies); } private void useDepVersion( ModifiedPomXMLEventReader pom, Collection dependencies ) @@ -123,12 +114,7 @@ private void useDepVersion( ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException { - try - { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) - { - useLatestReleases( pom, getProject().getDependencyManagement().getDependencies() ); - } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) - { - useLatestReleases( pom, getProject().getDependencies() ); - } - if ( getProject().getParent() != null && isProcessingParent() ) - { - Dependency dependency = new Dependency(); - dependency.setArtifactId(getProject().getParent().getArtifactId()); - dependency.setGroupId(getProject().getParent().getGroupId()); - dependency.setVersion(getProject().getParent().getVersion()); - dependency.setType("pom"); - List list = new ArrayList(); - list.add(dependency); - useLatestReleases( pom, list); - } - } - catch ( ArtifactMetadataRetrievalException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } + useLatestReleases(pom, dependencies); } private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection dependencies ) @@ -166,21 +132,7 @@ private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection 0 ) { - String newVersion = filteredVersions[filteredVersions.length - 1].toString(); - if(getProject().getParent() != null){ - if(artifact.getId().equals(getProject().getParentArtifact().getId()) && isProcessingParent()) - { - if ( PomHelper.setProjectParentVersion( pom, newVersion.toString() ) ) - { - getLog().debug( "Made parent update from " + version + " to " + newVersion.toString() ); - } - } - } - if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, - newVersion, getProject().getModel() ) ) - { - getLog().info( "Updated " + toString( dep ) + " to version " + newVersion ); - } + setVersion(pom, dep, version, artifact, filteredVersions[filteredVersions.length - 1]); } } } diff --git a/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java b/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java index a1833dda41..6777dd15ed 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java @@ -25,11 +25,9 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.model.Dependency; 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.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.ordering.MajorMinorIncrementalFilter; import org.codehaus.mojo.versions.ordering.VersionComparator; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -38,7 +36,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; -import java.util.List; import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -51,7 +48,7 @@ */ @Mojo( name = "use-latest-snapshots", requiresProject = true, requiresDirectInvocation = true, threadSafe = true ) public class UseLatestSnapshotsMojo - extends AbstractVersionsDependencyUpdaterMojo + extends ParentUpdatingDependencyUpdateMojo { /** @@ -87,42 +84,11 @@ public class UseLatestSnapshotsMojo // ------------------------------ METHODS -------------------------- - /** - * @param pom the pom to update. - * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong - * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way - * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming - * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) - */ - protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + @Override + protected void setVersions(ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException { - try - { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) - { - useLatestSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); - } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) - { - useLatestSnapshots( pom, getProject().getDependencies() ); - } - if ( getProject().getParent() != null && isProcessingParent() ) - { - Dependency dependency = new Dependency(); - dependency.setArtifactId(getProject().getParent().getArtifactId()); - dependency.setGroupId(getProject().getParent().getGroupId()); - dependency.setVersion(getProject().getParent().getVersion()); - dependency.setType("pom"); - List list = new ArrayList(); - list.add(dependency); - useLatestSnapshots( pom, list); - } - } - catch ( ArtifactMetadataRetrievalException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } + useLatestSnapshots(pom, dependencies); } private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection dependencies ) @@ -171,7 +137,6 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection 0 ) { - latestVersion = filteredVersions[filteredVersions.length - 1].toString(); - if(getProject().getParent() != null){ - if(artifact.getId().equals(getProject().getParentArtifact().getId()) && isProcessingParent()) - { - if ( PomHelper.setProjectParentVersion( pom, latestVersion.toString() ) ) - { - getLog().debug( "Made parent update from " + version + " to " + latestVersion.toString() ); - } - } - } - - if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, - latestVersion, getProject().getModel() ) ) - { - getLog().info( "Updated " + toString( dep ) + " to version " + latestVersion ); - } + setVersion(pom, dep, version, artifact, filteredVersions[filteredVersions.length - 1]); } } } diff --git a/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java b/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java index a0ea107d22..f375a36925 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java @@ -20,10 +20,8 @@ */ import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import java.util.List; import javax.xml.stream.XMLStreamException; @@ -50,7 +48,7 @@ */ @Mojo( name = "use-latest-versions", requiresProject = true, requiresDirectInvocation = true, threadSafe = true ) public class UseLatestVersionsMojo - extends AbstractVersionsDependencyUpdaterMojo + extends ParentUpdatingDependencyUpdateMojo { /** * Whether to allow the major version number to be changed. @@ -85,46 +83,36 @@ public class UseLatestVersionsMojo * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ - protected void update( ModifiedPomXMLEventReader pom ) + @Override + protected void update(ModifiedPomXMLEventReader pom) throws MojoExecutionException, MojoFailureException, XMLStreamException { - try - { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) + try { + if (getProject().getDependencyManagement() != null && isProcessingDependencyManagement()) { - DependencyManagement dependencyManagement = - PomHelper.getRawModel( getProject() ).getDependencyManagement(); - if ( dependencyManagement != null ) - { - useLatestVersions( pom, dependencyManagement.getDependencies() ); + DependencyManagement dependencyManagement = PomHelper.getRawModel(getProject()).getDependencyManagement(); + if (dependencyManagement != null) { + useLatestVersions(pom, dependencyManagement.getDependencies()); } } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) - { - useLatestVersions( pom, getProject().getDependencies() ); - } - if ( getProject().getParent() != null && isProcessingParent() ) + else { - Dependency dependency = new Dependency(); - dependency.setArtifactId(getProject().getParent().getArtifactId()); - dependency.setGroupId(getProject().getParent().getGroupId()); - dependency.setVersion(getProject().getParent().getVersion()); - dependency.setType("pom"); - List list = new ArrayList(); - list.add(dependency); - useLatestVersions( pom, list); + super.update(pom); } } - catch ( ArtifactMetadataRetrievalException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } - catch ( IOException e ) + catch ( ArtifactMetadataRetrievalException | IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } } + @Override + protected void setVersions(ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException + { + useLatestVersions(pom, dependencies); + } + private void useLatestVersions( ModifiedPomXMLEventReader pom, Collection dependencies ) throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException { @@ -161,22 +149,7 @@ private void useLatestVersions( ModifiedPomXMLEventReader pom, Collection 0 ) { - String newVersion = filteredVersions[filteredVersions.length - 1].toString(); - if(getProject().getParent() != null){ - if(artifact.getId().equals(getProject().getParentArtifact().getId()) && isProcessingParent()) - { - if ( PomHelper.setProjectParentVersion( pom, newVersion.toString() ) ) - { - getLog().debug( "Made parent update from " + version + " to " + newVersion.toString() ); - } - } - } - if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, newVersion, - getProject().getModel() ) ) - { - getLog().info( "Updated " + toString( dep ) + " to version " + newVersion ); - - } + setVersion(pom, dep, version, artifact, filteredVersions[filteredVersions.length - 1]); } } diff --git a/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java b/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java index e5f2b36774..e8d7633dd4 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java @@ -24,10 +24,8 @@ import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import javax.xml.stream.XMLStreamException; @@ -44,7 +42,7 @@ */ @Mojo( name = "use-next-releases", requiresProject = true, requiresDirectInvocation = true, threadSafe = true ) public class UseNextReleasesMojo - extends AbstractVersionsDependencyUpdaterMojo + extends ParentUpdatingDependencyUpdateMojo { // ------------------------------ FIELDS ------------------------------ @@ -56,24 +54,11 @@ public class UseNextReleasesMojo // ------------------------------ METHODS -------------------------- - /** - * @param pom the pom to update. - * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong - * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way - * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming - * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) - */ - protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException + @Override + protected void setVersions(ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) - { - useNextReleases( pom, getProject().getDependencyManagement().getDependencies() ); - } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) - { - useNextReleases( pom, getProject().getDependencies() ); - } + useNextReleases(pom, dependencies); } private void useNextReleases( ModifiedPomXMLEventReader pom, Collection dependencies ) @@ -106,12 +91,7 @@ private void useNextReleases( ModifiedPomXMLEventReader pom, Collection 0 ) { - String newVersion = newer[0].toString(); - if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, - newVersion, getProject().getModel() ) ) - { - getLog().info( "Updated " + toString( dep ) + " to version " + newVersion ); - } + setVersion(pom, dep, version, artifact, newer[0]); } } } diff --git a/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java b/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java index 308e795986..21c382f204 100644 --- a/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java +++ b/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java @@ -25,11 +25,9 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.model.Dependency; 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.codehaus.mojo.versions.api.ArtifactVersions; -import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.ordering.VersionComparator; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -48,7 +46,7 @@ */ @Mojo( name = "use-next-snapshots", requiresProject = true, requiresDirectInvocation = true, threadSafe = true ) public class UseNextSnapshotsMojo - extends AbstractVersionsDependencyUpdaterMojo + extends ParentUpdatingDependencyUpdateMojo { /** @@ -84,31 +82,12 @@ public class UseNextSnapshotsMojo // ------------------------------ METHODS -------------------------- - /** - * @param pom the pom to update. - * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong - * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way - * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming - * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) - */ - protected void update( ModifiedPomXMLEventReader pom ) - throws MojoExecutionException, MojoFailureException, XMLStreamException + + @Override + protected void setVersions(ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException { - try - { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) - { - useNextSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); - } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) - { - useNextSnapshots( pom, getProject().getDependencies() ); - } - } - catch ( ArtifactMetadataRetrievalException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } + useNextSnapshots(pom, dependencies); } private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection dependencies ) @@ -152,21 +131,24 @@ private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection dependencies) + throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException { - try - { - if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) - { - useNextVersions( pom, getProject().getDependencyManagement().getDependencies() ); - } - if ( getProject().getDependencies() != null && isProcessingDependencies() ) - { - useNextVersions( pom, getProject().getDependencies() ); - } - } - catch ( ArtifactMetadataRetrievalException e ) - { - throw new MojoExecutionException( e.getMessage(), e ); - } + useNextVersions(pom, dependencies); } private void useNextVersions( ModifiedPomXMLEventReader pom, Collection dependencies ) @@ -101,12 +80,7 @@ private void useNextVersions( ModifiedPomXMLEventReader pom, Collection 0 ) { - String newVersion = newer[0].toString(); - if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, newVersion, - getProject().getModel() ) ) - { - getLog().info( "Updated " + toString( dep ) + " to version " + newVersion ); - } + setVersion(pom, dep, version, artifact, newer[0]); } } }