22
22
import org .apache .maven .artifact .Artifact ;
23
23
import org .apache .maven .artifact .metadata .ArtifactMetadataRetrievalException ;
24
24
import org .apache .maven .artifact .versioning .ArtifactVersion ;
25
+ import org .apache .maven .artifact .versioning .DefaultArtifactVersion ;
25
26
import org .apache .maven .model .Dependency ;
26
27
import org .apache .maven .plugin .MojoExecutionException ;
27
28
import org .apache .maven .plugin .MojoFailureException ;
44
45
*/
45
46
@ Mojo ( name = "force-releases" , requiresProject = true , requiresDirectInvocation = true , threadSafe = true )
46
47
public class ForceReleasesMojo
47
- extends AbstractVersionsDependencyUpdaterMojo
48
+ extends ParentUpdatingDependencyUpdateMojo
48
49
{
49
50
50
51
// ------------------------------ FIELDS ------------------------------
@@ -56,31 +57,12 @@ public class ForceReleasesMojo
56
57
57
58
// ------------------------------ METHODS --------------------------
58
59
59
- /**
60
- * @param pom the pom to update.
61
- * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
62
- * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
63
- * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
64
- * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
65
- */
66
- protected void update ( ModifiedPomXMLEventReader pom )
67
- throws MojoExecutionException , MojoFailureException , XMLStreamException
60
+
61
+ @ Override
62
+ protected void setVersions (ModifiedPomXMLEventReader pom , Collection <Dependency > dependencies )
63
+ throws ArtifactMetadataRetrievalException , XMLStreamException , MojoExecutionException
68
64
{
69
- try
70
- {
71
- if ( getProject ().getDependencyManagement () != null && isProcessingDependencyManagement () )
72
- {
73
- useReleases ( pom , getProject ().getDependencyManagement ().getDependencies () );
74
- }
75
- if ( getProject ().getDependencies () != null && isProcessingDependencies () )
76
- {
77
- useReleases ( pom , getProject ().getDependencies () );
78
- }
79
- }
80
- catch ( ArtifactMetadataRetrievalException e )
81
- {
82
- throw new MojoExecutionException ( e .getMessage (), e );
83
- }
65
+ useReleases (pom , dependencies );
84
66
}
85
67
86
68
private void useReleases ( ModifiedPomXMLEventReader pom , Collection <Dependency > dependencies )
@@ -113,11 +95,7 @@ private void useReleases( ModifiedPomXMLEventReader pom, Collection<Dependency>
113
95
ArtifactVersions versions = getHelper ().lookupArtifactVersions ( artifact , false );
114
96
if ( versions .containsVersion ( releaseVersion ) )
115
97
{
116
- if ( PomHelper .setDependencyVersion ( pom , dep .getGroupId (), dep .getArtifactId (), version ,
117
- releaseVersion , getProject ().getModel () ) )
118
- {
119
- getLog ().info ( "Updated " + toString ( dep ) + " to version " + releaseVersion );
120
- }
98
+ setVersion (pom , dep , version , artifact , new DefaultArtifactVersion (releaseVersion ));
121
99
}
122
100
else
123
101
{
@@ -126,10 +104,8 @@ releaseVersion, getProject().getModel() ) )
126
104
{
127
105
getLog ().info ( "No release of " + toString ( dep ) + " to force." );
128
106
}
129
- else if ( PomHelper .setDependencyVersion ( pom , dep .getGroupId (), dep .getArtifactId (), version ,
130
- v [v .length - 1 ].toString (), getProject ().getModel () ) )
131
- {
132
- getLog ().info ( "Reverted " + toString ( dep ) + " to version " + v [v .length - 1 ].toString () );
107
+ else {
108
+ setVersion (pom , dep , version , artifact , v [v .length - 1 ]);
133
109
}
134
110
}
135
111
}
0 commit comments