1 package org.apache.maven.shared.transfer.artifact.resolve.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.RepositoryUtils;
25 import org.apache.maven.shared.transfer.artifact.ArtifactCoordinate;
26 import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
27 import org.sonatype.aether.RepositorySystem;
28 import org.sonatype.aether.RepositorySystemSession;
29 import org.sonatype.aether.artifact.Artifact;
30 import org.sonatype.aether.repository.RemoteRepository;
31 import org.sonatype.aether.resolution.ArtifactDescriptorException;
32 import org.sonatype.aether.resolution.ArtifactDescriptorRequest;
33 import org.sonatype.aether.resolution.ArtifactDescriptorResult;
34 import org.sonatype.aether.resolution.ArtifactRequest;
35 import org.sonatype.aether.resolution.ArtifactResolutionException;
36 import org.sonatype.aether.util.artifact.DefaultArtifact;
37
38
39
40
41 class Maven30ArtifactResolver
42 implements MavenArtifactResolver
43 {
44 private final RepositorySystem repositorySystem;
45
46 private final List<RemoteRepository> aetherRepositories;
47
48 private final RepositorySystemSession session;
49
50 Maven30ArtifactResolver( RepositorySystem repositorySystem, List<RemoteRepository> aetherRepositories,
51 RepositorySystemSession session )
52 {
53 this.repositorySystem = repositorySystem;
54 this.aetherRepositories = aetherRepositories;
55 this.session = session;
56 }
57
58 @Override
59
60 public org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult resolveArtifact( org.apache.maven.artifact.Artifact mavenArtifact )
61 throws ArtifactResolverException
62
63 {
64 Artifact aetherArtifact = Invoker.invoke( RepositoryUtils.class, "toArtifact",
65 org.apache.maven.artifact.Artifact.class, mavenArtifact );
66
67 return resolveArtifact( aetherArtifact );
68 }
69
70 @Override
71
72 public org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult resolveArtifact( ArtifactCoordinate coordinate )
73 throws ArtifactResolverException
74
75 {
76 Artifact aetherArtifact =
77 new DefaultArtifact( coordinate.getGroupId(), coordinate.getArtifactId(), coordinate.getClassifier(),
78 coordinate.getExtension(), coordinate.getVersion() );
79
80 return resolveArtifact( aetherArtifact );
81 }
82
83
84 private org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult resolveArtifact( Artifact aetherArtifact )
85 throws ArtifactResolverException
86
87 {
88 try
89 {
90
91 ArtifactDescriptorRequest descriptorRequest =
92 new ArtifactDescriptorRequest( aetherArtifact, aetherRepositories, null );
93
94 ArtifactDescriptorResult descriptorResult =
95 repositorySystem.readArtifactDescriptor( session, descriptorRequest );
96
97 ArtifactRequest request = new ArtifactRequest( descriptorResult.getArtifact(), aetherRepositories, null );
98
99 return new Maven30ArtifactResult( repositorySystem.resolveArtifact( session, request ) );
100 }
101 catch ( ArtifactDescriptorException | ArtifactResolutionException e )
102 {
103 throw new ArtifactResolverException( e.getMessage(), e );
104 }
105 }
106
107 }