1 package org.apache.maven.shared.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 org.apache.maven.artifact.Artifact;
23 import org.apache.maven.project.ProjectBuildingRequest;
24 import org.apache.maven.shared.artifact.ArtifactCoordinate;
25 import org.apache.maven.shared.artifact.resolve.ArtifactResolver;
26 import org.apache.maven.shared.artifact.resolve.ArtifactResolverException;
27 import org.apache.maven.shared.artifact.resolve.ArtifactResult;
28 import org.codehaus.plexus.PlexusConstants;
29 import org.codehaus.plexus.PlexusContainer;
30 import org.codehaus.plexus.component.annotations.Component;
31 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
32 import org.codehaus.plexus.context.Context;
33 import org.codehaus.plexus.context.ContextException;
34 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
35
36
37
38
39 @Component( role = ArtifactResolver.class, hint = "default" )
40 public class DefaultArtifactResolver
41 implements ArtifactResolver, Contextualizable
42 {
43 private PlexusContainer container;
44
45 @Override
46 public ArtifactResult resolveArtifact( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact )
47 throws ArtifactResolverException
48 {
49 try
50 {
51 String hint = isMaven31() ? "maven31" : "maven3";
52
53 ArtifactResolver effectiveArtifactResolver = container.lookup( ArtifactResolver.class, hint );
54
55 return effectiveArtifactResolver.resolveArtifact( buildingRequest, mavenArtifact );
56 }
57 catch ( ComponentLookupException e )
58 {
59 throw new ArtifactResolverException( e.getMessage(), e );
60 }
61 }
62
63 @Override
64 public ArtifactResult resolveArtifact( ProjectBuildingRequest buildingRequest, ArtifactCoordinate coordinate )
65 throws ArtifactResolverException
66 {
67 try
68 {
69 String hint = isMaven31() ? "maven31" : "maven3";
70
71 ArtifactResolver effectiveArtifactResolver = container.lookup( ArtifactResolver.class, hint );
72
73 return effectiveArtifactResolver.resolveArtifact( buildingRequest, coordinate );
74 }
75 catch ( ComponentLookupException e )
76 {
77 throw new ArtifactResolverException( e.getMessage(), e );
78 }
79 }
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 protected static boolean isMaven31()
125 {
126 return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" );
127 }
128
129 private static boolean canFindCoreClass( String className )
130 {
131 try
132 {
133 Thread.currentThread().getContextClassLoader().loadClass( className );
134
135 return true;
136 }
137 catch ( ClassNotFoundException e )
138 {
139 return false;
140 }
141 }
142
143
144
145
146
147
148
149 public void contextualize( Context context )
150 throws ContextException
151 {
152 container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
153 }
154 }