20
20
*/
21
21
22
22
import java .io .BufferedInputStream ;
23
+ import java .io .File ;
23
24
import java .io .IOException ;
24
25
import java .net .URISyntaxException ;
25
26
import java .net .URL ;
51
52
import org .apache .commons .lang3 .tuple .Pair ;
52
53
import org .apache .maven .artifact .Artifact ;
53
54
import org .apache .maven .artifact .ArtifactUtils ;
55
+ import org .apache .maven .artifact .DefaultArtifact ;
56
+ import org .apache .maven .artifact .handler .manager .ArtifactHandlerManager ;
54
57
import org .apache .maven .artifact .resolver .ArtifactResolutionException ;
55
58
import org .apache .maven .artifact .versioning .ArtifactVersion ;
56
59
import org .apache .maven .artifact .versioning .InvalidVersionSpecificationException ;
63
66
import org .apache .maven .plugin .MojoExecutionException ;
64
67
import org .apache .maven .plugin .logging .Log ;
65
68
import org .apache .maven .project .MavenProject ;
66
- import org .apache .maven .repository .RepositorySystem ;
67
69
import org .apache .maven .wagon .Wagon ;
68
70
import org .apache .maven .wagon .authentication .AuthenticationInfo ;
69
71
import org .apache .maven .wagon .observers .Debug ;
75
77
import org .codehaus .mojo .versions .ordering .VersionComparator ;
76
78
import org .codehaus .mojo .versions .ordering .VersionComparators ;
77
79
import org .codehaus .mojo .versions .utils .DefaultArtifactVersionCache ;
78
- import org .codehaus .mojo .versions .utils .DependencyBuilder ;
79
80
import org .codehaus .mojo .versions .utils .DependencyComparator ;
80
81
import org .codehaus .mojo .versions .utils .PluginComparator ;
81
82
import org .codehaus .mojo .versions .utils .RegexUtils ;
84
85
import org .codehaus .plexus .component .configurator .expression .ExpressionEvaluator ;
85
86
import org .codehaus .plexus .util .StringUtils ;
86
87
import org .codehaus .plexus .util .xml .pull .XmlPullParserException ;
88
+ import org .eclipse .aether .RepositorySystem ;
87
89
import org .eclipse .aether .repository .AuthenticationContext ;
88
90
import org .eclipse .aether .repository .RemoteRepository ;
89
91
import org .eclipse .aether .repository .RepositoryPolicy ;
@@ -122,9 +124,9 @@ RuleSet getRuleSet() {
122
124
*/
123
125
private RuleSet ruleSet ;
124
126
125
- private final RepositorySystem repositorySystem ;
127
+ private final ArtifactHandlerManager artifactHandlerManager ;
126
128
127
- private final org . eclipse . aether . RepositorySystem aetherRepositorySystem ;
129
+ private final RepositorySystem repositorySystem ;
128
130
129
131
/**
130
132
* The {@link Log} to send log messages to.
@@ -160,13 +162,13 @@ RuleSet getRuleSet() {
160
162
* Private constructor used by the builder
161
163
*/
162
164
private DefaultVersionsHelper (
165
+ ArtifactHandlerManager artifactHandlerManager ,
163
166
RepositorySystem repositorySystem ,
164
- org .eclipse .aether .RepositorySystem aetherRepositorySystem ,
165
167
MavenSession mavenSession ,
166
168
MojoExecution mojoExecution ,
167
169
Log log ) {
170
+ this .artifactHandlerManager = artifactHandlerManager ;
168
171
this .repositorySystem = repositorySystem ;
169
- this .aetherRepositorySystem = aetherRepositorySystem ;
170
172
this .mavenSession = mavenSession ;
171
173
this .mojoExecution = mojoExecution ;
172
174
this .log = log ;
@@ -276,7 +278,7 @@ public ArtifactVersions lookupArtifactVersions(
276
278
277
279
return new ArtifactVersions (
278
280
artifact ,
279
- aetherRepositorySystem
281
+ repositorySystem
280
282
.resolveVersionRange (
281
283
mavenSession .getRepositorySession (),
282
284
new VersionRangeRequest (
@@ -356,7 +358,7 @@ private List<IgnoreVersion> getIgnoredVersions(Artifact artifact) {
356
358
@ Override
357
359
public void resolveArtifact (Artifact artifact , boolean usePluginRepositories ) throws ArtifactResolutionException {
358
360
try {
359
- ArtifactResult artifactResult = aetherRepositorySystem .resolveArtifact (
361
+ ArtifactResult artifactResult = repositorySystem .resolveArtifact (
360
362
mavenSession .getRepositorySession (),
361
363
new ArtifactRequest (
362
364
toArtifact (artifact ),
@@ -445,11 +447,7 @@ protected Rule getBestFitRule(String groupId, String artifactId) {
445
447
446
448
@ Override
447
449
public Artifact createPluginArtifact (String groupId , String artifactId , String version ) {
448
- Plugin plugin = new Plugin ();
449
- plugin .setGroupId (groupId );
450
- plugin .setArtifactId (artifactId );
451
- plugin .setVersion (StringUtils .isNotBlank (version ) ? version : "[0,]" );
452
- return repositorySystem .createPluginArtifact (plugin );
450
+ return createDependencyArtifact (groupId , artifactId , version , "maven-plugin" , null , "runtime" , false );
453
451
}
454
452
455
453
@ Override
@@ -461,31 +459,37 @@ public Artifact createDependencyArtifact(
461
459
String classifier ,
462
460
String scope ,
463
461
boolean optional ) {
464
- return repositorySystem .createDependencyArtifact (DependencyBuilder .newBuilder ()
465
- .withGroupId (groupId )
466
- .withArtifactId (artifactId )
467
- .withType (type )
468
- .withClassifier (classifier )
469
- .withScope (scope )
470
- .withOptional (optional )
471
- .withVersion (StringUtils .isNotBlank (version ) ? version : "[0,]" )
472
- .build ());
473
- }
474
-
475
- @ Override
476
- public Artifact createDependencyArtifact (
477
- String groupId , String artifactId , String version , String type , String classifier , String scope ) {
478
- return createDependencyArtifact (groupId , artifactId , version , type , classifier , scope , false );
462
+ try {
463
+ return new DefaultArtifact (
464
+ groupId ,
465
+ artifactId ,
466
+ VersionRange .createFromVersionSpec (StringUtils .isNotBlank (version ) ? version : "[0,]" ),
467
+ scope ,
468
+ type ,
469
+ classifier ,
470
+ artifactHandlerManager .getArtifactHandler (type ),
471
+ optional );
472
+ } catch (InvalidVersionSpecificationException e ) {
473
+ // version should have a proper format
474
+ throw new RuntimeException (e );
475
+ }
479
476
}
480
477
481
478
@ Override
482
479
public Artifact createDependencyArtifact (Dependency dependency ) {
483
- if (StringUtils .isBlank (dependency .getVersion ())) {
484
- dependency = dependency .clone ();
485
- dependency .setVersion ("[,0]" );
486
- }
487
-
488
- return repositorySystem .createDependencyArtifact (dependency );
480
+ Artifact artifact = createDependencyArtifact (
481
+ dependency .getGroupId (),
482
+ dependency .getArtifactId (),
483
+ dependency .getVersion (),
484
+ dependency .getType (),
485
+ dependency .getClassifier (),
486
+ dependency .getScope (),
487
+ false );
488
+
489
+ if (Artifact .SCOPE_SYSTEM .equals (dependency .getScope ()) && dependency .getSystemPath () != null ) {
490
+ artifact .setFile (new File (dependency .getSystemPath ()));
491
+ }
492
+ return artifact ;
489
493
}
490
494
491
495
@ Override
@@ -710,15 +714,16 @@ public Map<Property, PropertyVersions> getVersionPropertiesMap(VersionProperties
710
714
* Builder class for {@linkplain DefaultVersionsHelper}
711
715
*/
712
716
public static class Builder {
713
- private RepositorySystem repositorySystem ;
717
+ private ArtifactHandlerManager artifactHandlerManager ;
714
718
private Collection <String > ignoredVersions ;
715
719
private RuleSet ruleSet ;
716
720
private String serverId ;
717
721
private String rulesUri ;
718
722
private Log log ;
719
723
private MavenSession mavenSession ;
720
724
private MojoExecution mojoExecution ;
721
- private org .eclipse .aether .RepositorySystem aetherRepositorySystem ;
725
+ private RepositorySystem repositorySystem ;
726
+
722
727
private Map <String , Wagon > wagonMap ;
723
728
724
729
public Builder () {}
@@ -919,8 +924,8 @@ public static Optional<String> protocol(final String url) {
919
924
return pos == -1 ? empty () : of (url .substring (0 , pos ).trim ());
920
925
}
921
926
922
- public Builder withRepositorySystem ( RepositorySystem repositorySystem ) {
923
- this .repositorySystem = repositorySystem ;
927
+ public Builder withArtifactHandlerManager ( ArtifactHandlerManager artifactHandlerManager ) {
928
+ this .artifactHandlerManager = artifactHandlerManager ;
924
929
return this ;
925
930
}
926
931
@@ -959,8 +964,8 @@ public Builder withMojoExecution(MojoExecution mojoExecution) {
959
964
return this ;
960
965
}
961
966
962
- public Builder withAetherRepositorySystem ( org . eclipse . aether . RepositorySystem aetherRepositorySystem ) {
963
- this .aetherRepositorySystem = aetherRepositorySystem ;
967
+ public Builder withRepositorySystem ( RepositorySystem repositorySystem ) {
968
+ this .repositorySystem = repositorySystem ;
964
969
return this ;
965
970
}
966
971
@@ -976,7 +981,7 @@ public Builder withWagonMap(Map<String, Wagon> wagonMap) {
976
981
*/
977
982
public DefaultVersionsHelper build () throws MojoExecutionException {
978
983
DefaultVersionsHelper instance = new DefaultVersionsHelper (
979
- repositorySystem , aetherRepositorySystem , mavenSession , mojoExecution , log );
984
+ artifactHandlerManager , repositorySystem , mavenSession , mojoExecution , log );
980
985
if (ruleSet != null ) {
981
986
if (!isBlank (rulesUri )) {
982
987
log .warn ("rulesUri is ignored if rules are specified in pom or as parameters" );
0 commit comments