1 package org.apache.maven.plugin.ant;
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.artifact.factory.ArtifactFactory;
24 import org.apache.maven.artifact.repository.ArtifactRepository;
25 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
26 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
27 import org.apache.maven.artifact.resolver.ArtifactResolver;
28
29 import java.io.IOException;
30 import java.util.List;
31
32
33
34
35
36
37
38 public class ArtifactResolverWrapper
39 {
40
41
42
43 private ArtifactResolver resolver;
44
45
46
47
48 private ArtifactFactory factory;
49
50
51
52
53 private ArtifactRepository localRepository;
54
55
56
57
58 private List remoteRepositories;
59
60
61
62
63
64
65
66 private ArtifactResolverWrapper( ArtifactResolver resolver, ArtifactFactory factory,
67 ArtifactRepository localRepository, List remoteRepositories )
68 {
69 this.resolver = resolver;
70 this.factory = factory;
71 this.localRepository = localRepository;
72 this.remoteRepositories = remoteRepositories;
73 }
74
75
76
77
78
79
80
81
82 public static ArtifactResolverWrapper getInstance( ArtifactResolver resolver, ArtifactFactory factory,
83 ArtifactRepository localRepository, List remoteRepositories )
84 {
85 return new ArtifactResolverWrapper( resolver, factory, localRepository, remoteRepositories );
86 }
87
88
89
90
91 protected ArtifactFactory getFactory()
92 {
93 return factory;
94 }
95
96
97
98
99 protected void setFactory( ArtifactFactory factory )
100 {
101 this.factory = factory;
102 }
103
104
105
106
107 protected ArtifactRepository getLocalRepository()
108 {
109 return localRepository;
110 }
111
112
113
114
115 protected void setLocalRepository( ArtifactRepository localRepository )
116 {
117 this.localRepository = localRepository;
118 }
119
120
121
122
123 protected List getRemoteRepositories()
124 {
125 return remoteRepositories;
126 }
127
128
129
130
131 protected void setRemoteRepositories( List remoteRepositories )
132 {
133 this.remoteRepositories = remoteRepositories;
134 }
135
136
137
138
139 protected ArtifactResolver getResolver()
140 {
141 return resolver;
142 }
143
144
145
146
147 protected void setResolver( ArtifactResolver resolver )
148 {
149 this.resolver = resolver;
150 }
151
152
153
154
155
156
157
158
159
160
161
162 public String getArtifactAbsolutePath( String groupId, String artifactId, String version )
163 throws IOException
164 {
165 Artifact artifact = factory.createArtifact( groupId, artifactId, version, "compile", "jar" );
166 try
167 {
168 resolver.resolve( artifact, remoteRepositories, localRepository );
169
170 return artifact.getFile().getAbsolutePath();
171 }
172 catch ( ArtifactResolutionException e )
173 {
174 throw new IOException( "Unable to resolve artifact: " + groupId + ":" + artifactId + ":" + version );
175 }
176 catch ( ArtifactNotFoundException e )
177 {
178 throw new IOException( "Unable to find artifact: " + groupId + ":" + artifactId + ":" + version );
179 }
180 }
181
182
183
184
185
186
187
188
189
190 public String getLocalArtifactPath( Artifact artifact )
191 {
192
193
194
195
196
197 return localRepository.pathOf( artifact );
198 }
199
200 }