21
21
import java .io .File ;
22
22
import java .io .IOException ;
23
23
import java .io .UncheckedIOException ;
24
- import java .util .ArrayList ;
25
- import java .util .Collection ;
26
24
import java .util .Collections ;
27
25
import java .util .LinkedHashMap ;
28
26
import java .util .List ;
68
66
import org .eclipse .aether .resolution .DependencyRequest ;
69
67
import org .eclipse .aether .resolution .DependencyResolutionException ;
70
68
import org .eclipse .aether .resolution .DependencyResult ;
69
+ import org .eclipse .aether .util .artifact .ArtifactIdUtils ;
71
70
import org .eclipse .aether .util .artifact .JavaScopes ;
72
71
import org .eclipse .aether .util .artifact .SubArtifact ;
73
72
import org .eclipse .aether .util .filter .DependencyFilterUtils ;
@@ -163,7 +162,7 @@ public void execute() throws MojoExecutionException {
163
162
return ;
164
163
}
165
164
166
- Collection < Artifact > resolvedArtifacts = new ArrayList <>();
165
+ Map < String , Artifact > resolvedArtifacts = new LinkedHashMap <>();
167
166
168
167
try {
169
168
@@ -181,19 +180,20 @@ public void execute() throws MojoExecutionException {
181
180
}
182
181
}
183
182
184
- private void resolveProjectArtifacts (Collection < Artifact > resolvedArtifacts ) {
183
+ private void resolveProjectArtifacts (Map < String , Artifact > resolvedArtifacts ) {
185
184
186
185
// pom packaging doesn't have a main artifact
187
186
if (project .getArtifact () != null && project .getArtifact ().getFile () != null ) {
188
- resolvedArtifacts .add (RepositoryUtils .toArtifact (project .getArtifact ()));
187
+ Artifact artifact = RepositoryUtils .toArtifact (project .getArtifact ());
188
+ resolvedArtifacts .put (ArtifactIdUtils .toId (artifact ), artifact );
189
189
}
190
190
191
- resolvedArtifacts . addAll ( project .getAttachedArtifacts ().stream ()
191
+ project .getAttachedArtifacts ().stream ()
192
192
.map (RepositoryUtils ::toArtifact )
193
- .collect ( Collectors . toList () ));
193
+ .forEach ( a -> resolvedArtifacts . put ( ArtifactIdUtils . toId ( a ), a ));
194
194
}
195
195
196
- private void resolveProjectPoms (MavenProject project , Collection < Artifact > resolvedArtifacts )
196
+ private void resolveProjectPoms (MavenProject project , Map < String , Artifact > resolvedArtifacts )
197
197
throws ArtifactResolutionException {
198
198
199
199
if (project == null ) {
@@ -202,15 +202,15 @@ private void resolveProjectPoms(MavenProject project, Collection<Artifact> resol
202
202
203
203
Artifact projectPom = RepositoryUtils .toArtifact (new ProjectArtifact (project ));
204
204
if (projectPom .getFile () != null ) {
205
- resolvedArtifacts .add ( projectPom );
205
+ resolvedArtifacts .put ( projectPom . toString (), projectPom );
206
206
} else {
207
207
Artifact artifact = resolveArtifact (projectPom , project .getRemoteProjectRepositories ());
208
- resolvedArtifacts .add ( artifact );
208
+ resolvedArtifacts .put ( ArtifactIdUtils . toId ( artifact ), artifact );
209
209
}
210
210
resolveProjectPoms (project .getParent (), resolvedArtifacts );
211
211
}
212
212
213
- private void resolveProjectDependencies (Collection < Artifact > resolvedArtifacts )
213
+ private void resolveProjectDependencies (Map < String , Artifact > resolvedArtifacts )
214
214
throws ArtifactResolutionException , MojoExecutionException , DependencyResolutionException {
215
215
216
216
DependencyFilter classpathFilter = DependencyFilterUtils .classpathFilter (scope );
@@ -245,7 +245,7 @@ private void resolveProjectDependencies(Collection<Artifact> resolvedArtifacts)
245
245
.map (ArtifactResult ::getArtifact )
246
246
.collect (Collectors .toList ());
247
247
248
- resolvedArtifacts .addAll ( artifacts );
248
+ artifacts . forEach ( a -> resolvedArtifacts .put ( ArtifactIdUtils . toId ( a ), a ) );
249
249
resolvePomsForArtifacts (artifacts , resolvedArtifacts , collectRequest .getRepositories ());
250
250
}
251
251
@@ -254,7 +254,7 @@ private void resolveProjectDependencies(Collection<Artifact> resolvedArtifacts)
254
254
*
255
255
* @return
256
256
*/
257
- private void resolveExtraArtifacts (Collection < Artifact > resolvedArtifacts )
257
+ private void resolveExtraArtifacts (Map < String , Artifact > resolvedArtifacts )
258
258
throws MojoExecutionException , DependencyResolutionException , ArtifactDescriptorException ,
259
259
ArtifactResolutionException {
260
260
@@ -309,13 +309,15 @@ private void resolveExtraArtifacts(Collection<Artifact> resolvedArtifacts)
309
309
.map (ArtifactResult ::getArtifact )
310
310
.collect (Collectors .toList ());
311
311
312
- resolvedArtifacts .addAll ( artifacts );
312
+ artifacts . forEach ( a -> resolvedArtifacts .put ( ArtifactIdUtils . toId ( a ), a ) );
313
313
resolvePomsForArtifacts (artifacts , resolvedArtifacts , collectRequest .getRepositories ());
314
314
}
315
315
}
316
316
317
317
private void resolvePomsForArtifacts (
318
- List <Artifact > artifacts , Collection <Artifact > resolvedArtifacts , List <RemoteRepository > remoteRepositories )
318
+ List <Artifact > artifacts ,
319
+ Map <String , Artifact > resolvedArtifacts ,
320
+ List <RemoteRepository > remoteRepositories )
319
321
throws ArtifactResolutionException , MojoExecutionException {
320
322
321
323
for (Artifact a : artifacts ) {
@@ -325,10 +327,10 @@ private void resolvePomsForArtifacts(
325
327
}
326
328
327
329
private void resolvePomWithParents (
328
- Artifact artifact , Collection < Artifact > resolvedArtifacts , List <RemoteRepository > remoteRepositories )
330
+ Artifact artifact , Map < String , Artifact > resolvedArtifacts , List <RemoteRepository > remoteRepositories )
329
331
throws MojoExecutionException , ArtifactResolutionException {
330
332
331
- if (resolvedArtifacts .contains ( artifact )) {
333
+ if (resolvedArtifacts .containsKey ( ArtifactIdUtils . toId ( artifact ) )) {
332
334
return ;
333
335
}
334
336
@@ -341,7 +343,7 @@ private void resolvePomWithParents(
341
343
resolvePomWithParents (resolvedPom , resolvedArtifacts , remoteRepositories );
342
344
}
343
345
344
- resolvedArtifacts .add ( artifact );
346
+ resolvedArtifacts .put ( ArtifactIdUtils . toId ( artifact ), artifact );
345
347
}
346
348
347
349
private Artifact resolveArtifact (Artifact artifact , List <RemoteRepository > remoteRepositories )
@@ -357,15 +359,15 @@ private Artifact resolveArtifact(Artifact artifact, List<RemoteRepository> remot
357
359
/**
358
360
* Install list of artifacts into local repository.
359
361
*/
360
- private void installArtifacts (Collection < Artifact > resolvedArtifacts ) throws InstallationException {
362
+ private void installArtifacts (Map < String , Artifact > resolvedArtifacts ) throws InstallationException {
361
363
362
364
RepositorySystemSession systemSessionForLocalRepo = createSystemSessionForLocalRepo ();
363
365
364
366
// we can have on dependency two artifacts with the same groupId:artifactId
365
367
// with different version, in such case when we install both in one request
366
368
// metadata will contain only one version
367
369
368
- Map <String , List <Artifact >> collect = resolvedArtifacts .stream ()
370
+ Map <String , List <Artifact >> collect = resolvedArtifacts .values (). stream ()
369
371
.filter (a -> !hasTheSamePathAsTarget (a , systemSessionForLocalRepo ))
370
372
.collect (Collectors .groupingBy (
371
373
a -> String .format ("%s:%s:%s" , a .getGroupId (), a .getArtifactId (), a .getVersion ()),
0 commit comments