2424
2525package io .jenkins .tools .incrementals .maven ;
2626
27+ import static org .twdata .maven .mojoexecutor .MojoExecutor .configuration ;
28+ import static org .twdata .maven .mojoexecutor .MojoExecutor .element ;
29+ import static org .twdata .maven .mojoexecutor .MojoExecutor .executeMojo ;
30+ import static org .twdata .maven .mojoexecutor .MojoExecutor .executionEnvironment ;
31+ import static org .twdata .maven .mojoexecutor .MojoExecutor .plugin ;
32+
2733import java .io .File ;
2834import java .io .IOException ;
2935import java .io .InputStream ;
3743import java .util .regex .Pattern ;
3844import javax .inject .Inject ;
3945import javax .xml .stream .XMLStreamException ;
40-
4146import org .apache .maven .artifact .Artifact ;
42- import org .apache .maven .artifact .handler .manager .ArtifactHandlerManager ;
4347import org .apache .maven .artifact .versioning .ArtifactVersion ;
4448import org .apache .maven .artifact .versioning .ComparableVersion ;
4549import org .apache .maven .artifact .versioning .InvalidVersionSpecificationException ;
4650import org .apache .maven .artifact .versioning .VersionRange ;
4751import org .apache .maven .plugin .BuildPluginManager ;
4852import org .apache .maven .plugin .MojoExecutionException ;
4953import org .apache .maven .plugin .MojoFailureException ;
50- import org .apache .maven .plugins .annotations .Component ;
5154import org .apache .maven .plugins .annotations .Mojo ;
55+ import org .apache .maven .plugins .annotations .Parameter ;
5256import org .apache .maven .wagon .Wagon ;
5357import org .codehaus .mojo .versions .AbstractVersionsUpdaterMojo ;
5458import org .codehaus .mojo .versions .api .ArtifactVersions ;
5559import org .codehaus .mojo .versions .api .PomHelper ;
5660import org .codehaus .mojo .versions .api .VersionRetrievalException ;
57- import org .codehaus .mojo .versions .api .VersionsHelper ;
5861import org .codehaus .mojo .versions .api .recording .ChangeRecorder ;
5962import org .codehaus .mojo .versions .rewriting .MutableXMLStreamReader ;
63+ import org .codehaus .mojo .versions .utils .ArtifactFactory ;
6064import org .eclipse .aether .RepositorySystem ;
61- import static org .twdata .maven .mojoexecutor .MojoExecutor .*;
6265
6366/**
6467 * Sets a project up for Incrementals.
@@ -72,11 +75,24 @@ public class IncrementalifyMojo extends AbstractVersionsUpdaterMojo {
7275 public static final String PLUGIN_POM = "org.jenkins-ci.plugins:plugin:pom" ;
7376 private static final Set <String > PARENT_DEPENDENCIES = Set .of (JENKINS_POM , PLUGIN_POM );
7477
75- @ Component
78+ /**
79+ * Whether to allow snapshots when searching for the latest version of an artifact.
80+ * @since 1.11
81+ */
82+ @ Parameter (property = "allowSnapshots" , defaultValue = "false" )
83+ protected boolean allowSnapshots ;
84+
85+ @ Inject
7686 private BuildPluginManager pluginManager ;
7787
78- @ Inject public IncrementalifyMojo (ArtifactHandlerManager artifactHandlerManager , RepositorySystem repositorySystem , Map <String , Wagon > wagonMap , Map <String , ChangeRecorder > changeRecorders ) {
79- super (artifactHandlerManager , repositorySystem , wagonMap , changeRecorders );
88+ @ Inject public IncrementalifyMojo (ArtifactFactory artifactFactory , RepositorySystem repositorySystem , Map <String , Wagon > wagonMap , Map <String , ChangeRecorder > changeRecorders )
89+ throws MojoExecutionException {
90+ super (artifactFactory , repositorySystem , wagonMap , changeRecorders );
91+ }
92+
93+ @ Override
94+ protected boolean getAllowSnapshots () {
95+ return allowSnapshots ;
8096 }
8197
8298 @ Override public void execute () throws MojoExecutionException , MojoFailureException {
@@ -87,7 +103,9 @@ public class IncrementalifyMojo extends AbstractVersionsUpdaterMojo {
87103 }
88104 ArtifactVersions gclmeVersions ;
89105 try {
90- gclmeVersions = getHelper ().lookupArtifactVersions (getHelper ().createDependencyArtifact ("io.jenkins.tools.incrementals" , "git-changelist-maven-extension" , "[0,)" , "type" , null , null , false ), true );
106+ Artifact artifact = artifactFactory .createArtifact ("io.jenkins.tools.incrementals" ,
107+ "git-changelist-maven-extension" , "[0,)" , "type" , null , null , false );
108+ gclmeVersions = getHelper ().lookupArtifactVersions (artifact , true );
91109 } catch (VersionRetrievalException x ) {
92110 throw new MojoExecutionException (x .getMessage (), x );
93111 }
@@ -128,7 +146,7 @@ public class IncrementalifyMojo extends AbstractVersionsUpdaterMojo {
128146 if (!origTag .equals ("HEAD" )) {
129147 throw new MojoFailureException ("Unexpected tag: " + origTag );
130148 }
131- Artifact parent = getProjectParent (pom , getHelper () );
149+ Artifact parent = getProjectParent (pom );
132150 if (parent == null ) {
133151 throw new MojoFailureException ("No <parent> found" );
134152 }
@@ -169,11 +187,10 @@ public class IncrementalifyMojo extends AbstractVersionsUpdaterMojo {
169187 * Gets the parent artifact from the pom.
170188 *
171189 * @param pom The pom.
172- * @param helper The helper (used to create the artifact).
173190 * @return The parent artifact or <code>null</code> if no parent is specified.
174191 * @throws XMLStreamException if something went wrong.
175192 */
176- private static Artifact getProjectParent ( final MutableXMLStreamReader pom , VersionsHelper helper )
193+ private Artifact getProjectParent (final MutableXMLStreamReader pom )
177194 throws XMLStreamException
178195 {
179196 Stack <String > stack = new Stack <>();
@@ -222,8 +239,7 @@ else if ( "version".equals( elementName ) )
222239 {
223240 return null ;
224241 }
225- return helper .createDependencyArtifact ( groupId , artifactId , version , "pom" ,
226- null , null , false );
242+ return artifactFactory .createArtifact ( groupId , artifactId , version , "pom" , null , null , false );
227243 }
228244
229245 private static final class ReplaceGitHubRepo {
0 commit comments