1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.repository.aether.internal; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.Collection; |
26 |
|
import java.util.Collections; |
27 |
|
import java.util.Iterator; |
28 |
|
import java.util.List; |
29 |
|
import java.util.Map; |
30 |
|
import java.util.Properties; |
31 |
|
|
32 |
|
import org.apache.maven.model.Model; |
33 |
|
import org.apache.maven.model.building.DefaultModelBuildingRequest; |
34 |
|
import org.apache.maven.model.building.ModelBuilder; |
35 |
|
import org.apache.maven.model.building.ModelBuildingException; |
36 |
|
import org.apache.maven.model.building.ModelBuildingRequest; |
37 |
|
import org.apache.maven.repository.internal.ArtifactDescriptorUtils; |
38 |
|
import org.apache.maven.repository.internal.PublicDefaultModelResolver; |
39 |
|
import org.codehaus.plexus.PlexusContainer; |
40 |
|
import org.eclipse.aether.RepositorySystem; |
41 |
|
import org.eclipse.aether.RepositorySystemSession; |
42 |
|
import org.eclipse.aether.artifact.Artifact; |
43 |
|
import org.eclipse.aether.artifact.ArtifactProperties; |
44 |
|
import org.eclipse.aether.artifact.ArtifactType; |
45 |
|
import org.eclipse.aether.artifact.ArtifactTypeRegistry; |
46 |
|
import org.eclipse.aether.artifact.DefaultArtifact; |
47 |
|
import org.eclipse.aether.artifact.DefaultArtifactType; |
48 |
|
import org.eclipse.aether.graph.Dependency; |
49 |
|
import org.eclipse.aether.graph.Exclusion; |
50 |
|
import org.eclipse.aether.impl.ArtifactDescriptorReader; |
51 |
|
import org.eclipse.aether.impl.ArtifactResolver; |
52 |
|
import org.eclipse.aether.impl.RemoteRepositoryManager; |
53 |
|
import org.eclipse.aether.impl.RepositoryConnectorProvider; |
54 |
|
import org.eclipse.aether.impl.VersionRangeResolver; |
55 |
|
import org.eclipse.aether.impl.VersionResolver; |
56 |
|
import org.eclipse.aether.repository.Proxy; |
57 |
|
import org.eclipse.aether.repository.RemoteRepository; |
58 |
|
import org.eclipse.aether.repository.RepositoryPolicy; |
59 |
|
import org.eclipse.aether.resolution.ArtifactRequest; |
60 |
|
import org.eclipse.aether.resolution.ArtifactResolutionException; |
61 |
|
import org.eclipse.aether.resolution.ArtifactResult; |
62 |
|
import org.eclipse.aether.resolution.VersionRangeRequest; |
63 |
|
import org.eclipse.aether.resolution.VersionRangeResolutionException; |
64 |
|
import org.eclipse.aether.resolution.VersionRangeResult; |
65 |
|
import org.eclipse.aether.resolution.VersionRequest; |
66 |
|
import org.eclipse.aether.resolution.VersionResolutionException; |
67 |
|
import org.eclipse.aether.resolution.VersionResult; |
68 |
|
import org.eclipse.aether.transfer.ArtifactNotFoundException; |
69 |
|
import org.eclipse.aether.util.repository.AuthenticationBuilder; |
70 |
|
import org.eclipse.aether.util.version.GenericVersionScheme; |
71 |
|
import org.eclipse.aether.version.InvalidVersionSpecificationException; |
72 |
|
import org.xwiki.component.manager.ComponentManager; |
73 |
|
import org.xwiki.extension.Extension; |
74 |
|
import org.xwiki.extension.ExtensionDependency; |
75 |
|
import org.xwiki.extension.ExtensionId; |
76 |
|
import org.xwiki.extension.ExtensionNotFoundException; |
77 |
|
import org.xwiki.extension.ResolveException; |
78 |
|
import org.xwiki.extension.internal.ExtensionFactory; |
79 |
|
import org.xwiki.extension.internal.maven.MavenExtensionDependency; |
80 |
|
import org.xwiki.extension.repository.AbstractExtensionRepository; |
81 |
|
import org.xwiki.extension.repository.ExtensionRepositoryDescriptor; |
82 |
|
import org.xwiki.extension.repository.result.CollectionIterableResult; |
83 |
|
import org.xwiki.extension.repository.result.IterableResult; |
84 |
|
import org.xwiki.extension.version.Version; |
85 |
|
import org.xwiki.extension.version.VersionConstraint; |
86 |
|
import org.xwiki.extension.version.VersionRange; |
87 |
|
import org.xwiki.extension.version.internal.DefaultVersion; |
88 |
|
import org.xwiki.properties.ConverterManager; |
89 |
|
|
90 |
|
|
91 |
|
@version |
92 |
|
@since |
93 |
|
|
|
|
| 81.6% |
Uncovered Elements: 49 (267) |
Complexity: 77 |
Complexity Density: 0.42 |
|
94 |
|
public class AetherExtensionRepository extends AbstractExtensionRepository |
95 |
|
{ |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
private static final GenericVersionScheme AETHERVERSIONSCHEME = new GenericVersionScheme(); |
100 |
|
|
101 |
|
private transient PlexusContainer plexusContainer; |
102 |
|
|
103 |
|
private transient RemoteRepository remoteRepository; |
104 |
|
|
105 |
|
private transient ArtifactDescriptorReader mavenDescriptorReader; |
106 |
|
|
107 |
|
private transient VersionRangeResolver versionRangeResolver; |
108 |
|
|
109 |
|
private transient VersionResolver versionResolver; |
110 |
|
|
111 |
|
private transient ModelBuilder modelBuilder; |
112 |
|
|
113 |
|
private transient ArtifactResolver artifactResolver; |
114 |
|
|
115 |
|
private transient RepositorySystem repositorySystem; |
116 |
|
|
117 |
|
private transient RepositoryConnectorProvider repositoryConnectorProvider; |
118 |
|
|
119 |
|
private transient RemoteRepositoryManager remoteRepositoryManager; |
120 |
|
|
121 |
|
private transient ConverterManager converter; |
122 |
|
|
123 |
|
private transient AetherExtensionRepositoryFactory repositoryFactory; |
124 |
|
|
125 |
|
private transient ExtensionFactory factory; |
126 |
|
|
|
|
| 80.8% |
Uncovered Elements: 5 (26) |
Complexity: 2 |
Complexity Density: 0.08 |
|
127 |
46 |
public AetherExtensionRepository(ExtensionRepositoryDescriptor repositoryDescriptor,... |
128 |
|
AetherExtensionRepositoryFactory repositoryFactory, PlexusContainer plexusContainer, |
129 |
|
ComponentManager componentManager) throws Exception |
130 |
|
{ |
131 |
46 |
super(repositoryDescriptor); |
132 |
|
|
133 |
46 |
this.repositoryFactory = repositoryFactory; |
134 |
46 |
this.plexusContainer = plexusContainer; |
135 |
|
|
136 |
46 |
RemoteRepository.Builder repositoryBuilder = new RemoteRepository.Builder(repositoryDescriptor.getId(), |
137 |
|
"default", repositoryDescriptor.getURI().toString()); |
138 |
|
|
139 |
|
|
140 |
46 |
repositoryBuilder.setPolicy( |
141 |
|
new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_ALWAYS, RepositoryPolicy.CHECKSUM_POLICY_WARN)); |
142 |
|
|
143 |
|
|
144 |
46 |
String username = getDescriptor().getProperty("auth.user"); |
145 |
46 |
if (username != null) { |
146 |
0 |
AuthenticationBuilder authenticationBuilder = new AuthenticationBuilder(); |
147 |
0 |
authenticationBuilder.addUsername(username); |
148 |
0 |
authenticationBuilder.addPassword(getDescriptor().getProperty("auth.password")); |
149 |
0 |
repositoryBuilder.setAuthentication(authenticationBuilder.build()); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
46 |
Proxy proxy = XWikiRepositorySystemSession.JREPROXYSELECTOR.getProxy(repositoryBuilder.build()); |
154 |
46 |
repositoryBuilder.setProxy(proxy); |
155 |
|
|
156 |
46 |
this.remoteRepository = repositoryBuilder.build(); |
157 |
|
|
158 |
46 |
this.converter = componentManager.getInstance(ConverterManager.class); |
159 |
46 |
this.factory = componentManager.getInstance(ExtensionFactory.class); |
160 |
|
|
161 |
46 |
this.versionRangeResolver = this.plexusContainer.lookup(VersionRangeResolver.class); |
162 |
46 |
this.versionResolver = this.plexusContainer.lookup(VersionResolver.class); |
163 |
46 |
this.modelBuilder = this.plexusContainer.lookup(ModelBuilder.class); |
164 |
46 |
this.artifactResolver = this.plexusContainer.lookup(ArtifactResolver.class); |
165 |
46 |
this.repositorySystem = this.plexusContainer.lookup(RepositorySystem.class); |
166 |
46 |
this.mavenDescriptorReader = this.plexusContainer.lookup(ArtifactDescriptorReader.class); |
167 |
46 |
this.repositoryConnectorProvider = this.plexusContainer.lookup(RepositoryConnectorProvider.class); |
168 |
46 |
this.remoteRepositoryManager = this.plexusContainer.lookup(RemoteRepositoryManager.class); |
169 |
|
} |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
90 |
public RemoteRepository getRemoteRepository()... |
172 |
|
{ |
173 |
90 |
return this.remoteRepository; |
174 |
|
} |
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
10 |
public RepositorySystem getRepositorySystem()... |
177 |
|
{ |
178 |
10 |
return this.repositorySystem; |
179 |
|
} |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
181 |
10 |
public RepositoryConnectorProvider getRepositoryConnectorProvider()... |
182 |
|
{ |
183 |
10 |
return this.repositoryConnectorProvider; |
184 |
|
} |
185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
186 |
126 |
protected XWikiRepositorySystemSession createRepositorySystemSession()... |
187 |
|
{ |
188 |
126 |
XWikiRepositorySystemSession session = this.repositoryFactory.createRepositorySystemSession(); |
189 |
|
|
190 |
126 |
session.addConfigurationProperties(getDescriptor().getProperties()); |
191 |
|
|
192 |
126 |
return session; |
193 |
|
} |
194 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
195 |
85 |
@Override... |
196 |
|
public Extension resolve(ExtensionId extensionId) throws ResolveException |
197 |
|
{ |
198 |
85 |
try { |
199 |
85 |
if (getDescriptor().getType().equals("maven") && this.mavenDescriptorReader != null) { |
200 |
85 |
return resolveMaven(extensionId); |
201 |
|
} else { |
202 |
|
|
203 |
0 |
throw new ResolveException("Unsupported"); |
204 |
|
} |
205 |
|
} catch (InvalidExtensionIdException e) { |
206 |
|
|
207 |
2 |
throw new ExtensionNotFoundException("Invalid extension id", e); |
208 |
|
} |
209 |
|
} |
210 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
211 |
12 |
@Override... |
212 |
|
public Extension resolve(ExtensionDependency extensionDependency) throws ResolveException |
213 |
|
{ |
214 |
12 |
try { |
215 |
12 |
if (getDescriptor().getType().equals("maven") && this.mavenDescriptorReader != null) { |
216 |
12 |
return resolveMaven(extensionDependency); |
217 |
|
} else { |
218 |
|
|
219 |
0 |
throw new ResolveException("Unsupported"); |
220 |
|
} |
221 |
|
} catch (InvalidExtensionIdException e) { |
222 |
|
|
223 |
1 |
throw new ExtensionNotFoundException("Invalid extension id", e); |
224 |
|
} |
225 |
|
} |
226 |
|
|
|
|
| 79.3% |
Uncovered Elements: 6 (29) |
Complexity: 12 |
Complexity Density: 0.63 |
|
227 |
10 |
@Override... |
228 |
|
public IterableResult<Version> resolveVersions(String id, int offset, int nb) throws ResolveException |
229 |
|
{ |
230 |
10 |
Artifact artifact; |
231 |
10 |
try { |
232 |
10 |
artifact = AetherUtils.createArtifact(id, "(,)"); |
233 |
|
} catch (InvalidExtensionIdException e) { |
234 |
|
|
235 |
0 |
throw new ExtensionNotFoundException("Invalid extension id", e); |
236 |
|
} |
237 |
|
|
238 |
10 |
List<org.eclipse.aether.version.Version> versions; |
239 |
10 |
try (XWikiRepositorySystemSession session = createRepositorySystemSession()) { |
240 |
10 |
versions = resolveVersions(artifact, session); |
241 |
|
} catch (Exception e) { |
242 |
0 |
throw new ResolveException("Failed to resolve versions for id [" + id + "]", e); |
243 |
|
} |
244 |
|
|
245 |
10 |
if (versions.isEmpty()) { |
246 |
5 |
throw new ExtensionNotFoundException("No versions available for id [" + id + "]"); |
247 |
|
} |
248 |
|
|
249 |
5 |
if (nb == 0 || offset >= versions.size()) { |
250 |
0 |
return new CollectionIterableResult<Version>(versions.size(), offset, Collections.<Version>emptyList()); |
251 |
|
} |
252 |
|
|
253 |
5 |
int fromId = offset < 0 ? 0 : offset; |
254 |
5 |
int toId = offset + nb > versions.size() || nb < 0 ? versions.size() : offset + nb; |
255 |
|
|
256 |
5 |
List<Version> result = new ArrayList<Version>(toId - fromId); |
257 |
15 |
for (int i = fromId; i < toId; ++i) { |
258 |
10 |
result.add(new DefaultVersion(versions.get(i).toString())); |
259 |
|
} |
260 |
|
|
261 |
5 |
return new CollectionIterableResult<Version>(versions.size(), offset, result); |
262 |
|
} |
263 |
|
|
|
|
| 42.9% |
Uncovered Elements: 16 (28) |
Complexity: 9 |
Complexity Density: 0.56 |
|
264 |
1 |
private org.eclipse.aether.version.Version resolveVersionConstraint(String id, VersionConstraint versionConstraint,... |
265 |
|
RepositorySystemSession session) throws ResolveException |
266 |
|
{ |
267 |
1 |
if (versionConstraint.getVersion() != null) { |
268 |
0 |
try { |
269 |
0 |
return AETHERVERSIONSCHEME.parseVersion(versionConstraint.getVersion().getValue()); |
270 |
|
} catch (InvalidVersionSpecificationException e) { |
271 |
0 |
throw new ResolveException("Invalid version [" + versionConstraint.getVersion() + "]", e); |
272 |
|
} |
273 |
|
} |
274 |
|
|
275 |
1 |
List<org.eclipse.aether.version.Version> commonVersions = null; |
276 |
|
|
277 |
1 |
for (VersionRange range : versionConstraint.getRanges()) { |
278 |
1 |
List<org.eclipse.aether.version.Version> versions = resolveVersionRange(id, range, session); |
279 |
|
|
280 |
1 |
if (commonVersions == null) { |
281 |
1 |
commonVersions = versionConstraint.getRanges().size() > 1 |
282 |
|
? new ArrayList<org.eclipse.aether.version.Version>(versions) : versions; |
283 |
|
} else { |
284 |
|
|
285 |
0 |
for (Iterator<org.eclipse.aether.version.Version> it = commonVersions.iterator(); it.hasNext();) { |
286 |
0 |
org.eclipse.aether.version.Version version = it.next(); |
287 |
0 |
if (!versions.contains(version)) { |
288 |
0 |
it.remove(); |
289 |
|
} |
290 |
|
} |
291 |
|
} |
292 |
|
} |
293 |
|
|
294 |
1 |
if (commonVersions == null || commonVersions.isEmpty()) { |
295 |
0 |
throw new ExtensionNotFoundException( |
296 |
|
"No versions available for id [" + id + "] and version constraint [" + versionConstraint + "]"); |
297 |
|
} |
298 |
|
|
299 |
1 |
return commonVersions.get(commonVersions.size() - 1); |
300 |
|
} |
301 |
|
|
|
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
302 |
1 |
private List<org.eclipse.aether.version.Version> resolveVersionRange(String id, VersionRange versionRange,... |
303 |
|
RepositorySystemSession session) throws ResolveException |
304 |
|
{ |
305 |
1 |
Artifact artifact = AetherUtils.createArtifact(id, versionRange.getValue()); |
306 |
|
|
307 |
1 |
try { |
308 |
1 |
List<org.eclipse.aether.version.Version> versions = resolveVersions(artifact, session); |
309 |
|
|
310 |
1 |
if (versions.isEmpty()) { |
311 |
0 |
throw new ExtensionNotFoundException( |
312 |
|
"No versions available for id [" + id + "] and version range [" + versionRange + "]"); |
313 |
|
} |
314 |
|
|
315 |
1 |
return versions; |
316 |
|
} catch (Exception e) { |
317 |
0 |
throw new ResolveException("Failed to resolve version range", e); |
318 |
|
} |
319 |
|
} |
320 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
321 |
2 |
private org.eclipse.aether.version.Version resolveVersionConstraint(Artifact artifact,... |
322 |
|
RepositorySystemSession session) throws ResolveException |
323 |
|
{ |
324 |
2 |
try { |
325 |
2 |
List<org.eclipse.aether.version.Version> versions = resolveVersions(artifact, session); |
326 |
|
|
327 |
2 |
if (versions.isEmpty()) { |
328 |
0 |
throw new ExtensionNotFoundException("No versions available for artifact [" + artifact + "]"); |
329 |
|
} |
330 |
|
|
331 |
2 |
return versions.get(versions.size() - 1); |
332 |
|
} catch (Exception e) { |
333 |
0 |
throw new ResolveException("Failed to resolve version range", e); |
334 |
|
} |
335 |
|
} |
336 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
337 |
13 |
List<org.eclipse.aether.version.Version> resolveVersions(Artifact artifact, RepositorySystemSession session)... |
338 |
|
throws VersionRangeResolutionException |
339 |
|
{ |
340 |
13 |
VersionRangeRequest rangeRequest = new VersionRangeRequest(); |
341 |
13 |
rangeRequest.setArtifact(artifact); |
342 |
13 |
rangeRequest.setRepositories(newResolutionRepositories(session)); |
343 |
|
|
344 |
13 |
VersionRangeResult rangeResult = this.versionRangeResolver.resolveVersionRange(session, rangeRequest); |
345 |
|
|
346 |
13 |
return rangeResult.getVersions(); |
347 |
|
} |
348 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 6 |
Complexity Density: 0.43 |
|
349 |
12 |
private AetherExtension resolveMaven(ExtensionDependency extensionDependency) throws ResolveException... |
350 |
|
{ |
351 |
12 |
Artifact artifact; |
352 |
12 |
String artifactExtension; |
353 |
12 |
try (XWikiRepositorySystemSession session = createRepositorySystemSession()) { |
354 |
12 |
if (extensionDependency instanceof AetherExtensionDependency) { |
355 |
5 |
artifact = ((AetherExtensionDependency) extensionDependency).getAetherDependency().getArtifact(); |
356 |
5 |
artifactExtension = ((AetherExtensionDependency) extensionDependency).getAetherDependency() |
357 |
|
.getArtifact().getExtension(); |
358 |
|
|
359 |
|
|
360 |
5 |
if (!extensionDependency.getVersionConstraint().getRanges().isEmpty()) { |
361 |
2 |
artifact = artifact.setVersion(resolveVersionConstraint(artifact, session).toString()); |
362 |
|
} |
363 |
|
} else { |
364 |
7 |
artifact = AetherUtils.createArtifact(extensionDependency.getId(), |
365 |
|
extensionDependency.getVersionConstraint().getValue()); |
366 |
6 |
artifactExtension = null; |
367 |
|
|
368 |
|
|
369 |
6 |
if (!extensionDependency.getVersionConstraint().getRanges().isEmpty()) { |
370 |
1 |
artifact = artifact.setVersion(resolveVersionConstraint(extensionDependency.getId(), |
371 |
|
extensionDependency.getVersionConstraint(), session).toString()); |
372 |
|
} |
373 |
|
} |
374 |
|
} |
375 |
|
|
376 |
11 |
return resolveMaven(artifact, artifactExtension); |
377 |
|
} |
378 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
379 |
85 |
private AetherExtension resolveMaven(ExtensionId extensionId) throws ResolveException... |
380 |
|
{ |
381 |
85 |
Artifact artifact = AetherUtils.createArtifact(extensionId.getId(), extensionId.getVersion().getValue()); |
382 |
|
|
383 |
83 |
return resolveMaven(artifact, null); |
384 |
|
} |
385 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 3 |
Complexity Density: 1 |
|
386 |
94 |
private AetherExtension resolveMaven(Artifact artifact, String artifactExtension) throws ResolveException... |
387 |
|
{ |
388 |
94 |
try (XWikiRepositorySystemSession session = createRepositorySystemSession()) { |
389 |
94 |
return resolveMaven(artifact, artifactExtension, session); |
390 |
|
} |
391 |
|
} |
392 |
|
|
|
|
| 82.1% |
Uncovered Elements: 5 (28) |
Complexity: 9 |
Complexity Density: 0.45 |
|
393 |
94 |
private AetherExtension resolveMaven(Artifact artifact, String artifactExtension, RepositorySystemSession session)... |
394 |
|
throws ResolveException |
395 |
|
{ |
396 |
|
|
397 |
|
|
398 |
94 |
Model model; |
399 |
94 |
try { |
400 |
94 |
model = loadPom(artifact, session); |
401 |
|
} catch (ArtifactResolutionException e1) { |
402 |
43 |
if (e1.getResult() != null && !e1.getResult().getExceptions().isEmpty() |
403 |
|
&& e1.getResult().getExceptions().get(0) instanceof ArtifactNotFoundException) { |
404 |
43 |
throw new ExtensionNotFoundException("Could not find artifact [" + artifact + "] descriptor", e1); |
405 |
|
} else { |
406 |
0 |
throw new ResolveException("Failed to resolve artifact [" + artifact + "] descriptor", e1); |
407 |
|
} |
408 |
|
} catch (Exception e2) { |
409 |
0 |
throw new ResolveException("Failed to resolve artifact [" + artifact + "] descriptor", e2); |
410 |
|
} |
411 |
|
|
412 |
51 |
if (model == null) { |
413 |
0 |
throw new ResolveException("Failed to resolve artifact [" + artifact + "] descriptor"); |
414 |
|
} |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
51 |
if (artifactExtension == null) { |
419 |
|
|
420 |
46 |
ArtifactType artifactType = session.getArtifactTypeRegistry().get(model.getPackaging()); |
421 |
46 |
if (artifactType != null) { |
422 |
32 |
artifactExtension = artifactType.getExtension(); |
423 |
|
} else { |
424 |
14 |
artifactExtension = model.getPackaging(); |
425 |
|
} |
426 |
|
} |
427 |
|
|
428 |
51 |
Extension mavenExtension = this.converter.convert(Extension.class, model); |
429 |
|
|
430 |
51 |
Artifact filerArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), |
431 |
|
artifact.getClassifier(), artifactExtension, artifact.getVersion()); |
432 |
|
|
433 |
51 |
AetherExtension extension = new AetherExtension(mavenExtension, filerArtifact, this, factory); |
434 |
|
|
435 |
|
|
436 |
51 |
extension.setDependencies(toAetherDependencies(mavenExtension.getDependencies(), session)); |
437 |
|
|
438 |
|
|
439 |
51 |
extension.setManagedDependencies(toAetherDependencies(mavenExtension.getManagedDependencies(), session)); |
440 |
|
|
441 |
51 |
return extension; |
442 |
|
} |
443 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
444 |
102 |
private List<ExtensionDependency> toAetherDependencies(Collection<ExtensionDependency> mavenDependencies,... |
445 |
|
RepositorySystemSession session) throws ResolveException |
446 |
|
{ |
447 |
102 |
List<ExtensionDependency> dependencies = new ArrayList<>(mavenDependencies.size()); |
448 |
|
|
449 |
102 |
try { |
450 |
102 |
ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry(); |
451 |
|
|
452 |
102 |
for (ExtensionDependency mavenDependency : mavenDependencies) { |
453 |
1029 |
dependencies.add(new AetherExtensionDependency(mavenDependency, |
454 |
|
convertToAether(((MavenExtensionDependency) mavenDependency).getMavenDependency(), stereotypes), |
455 |
|
this.getDescriptor())); |
456 |
|
} |
457 |
|
} catch (Exception e) { |
458 |
0 |
throw new ResolveException("Failed to resolve dependencies", e); |
459 |
|
} |
460 |
|
|
461 |
102 |
return dependencies; |
462 |
|
} |
463 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
464 |
1029 |
private Dependency convertToAether(org.apache.maven.model.Dependency dependency, ArtifactTypeRegistry stereotypes)... |
465 |
|
{ |
466 |
1029 |
ArtifactType stereotype = stereotypes.get(dependency.getType()); |
467 |
1029 |
if (stereotype == null) { |
468 |
15 |
stereotype = new DefaultArtifactType(dependency.getType()); |
469 |
|
} |
470 |
|
|
471 |
1029 |
boolean system = dependency.getSystemPath() != null && dependency.getSystemPath().length() > 0; |
472 |
|
|
473 |
1029 |
Map<String, String> props = null; |
474 |
1029 |
if (system) { |
475 |
0 |
props = Collections.singletonMap(ArtifactProperties.LOCAL_PATH, dependency.getSystemPath()); |
476 |
|
} |
477 |
|
|
478 |
1029 |
Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), |
479 |
|
dependency.getClassifier(), null, dependency.getVersion(), props, stereotype); |
480 |
|
|
481 |
1029 |
List<Exclusion> exclusions = new ArrayList<Exclusion>(dependency.getExclusions().size()); |
482 |
1029 |
for (org.apache.maven.model.Exclusion exclusion : dependency.getExclusions()) { |
483 |
249 |
exclusions.add(convert(exclusion)); |
484 |
|
} |
485 |
|
|
486 |
1029 |
Dependency result = new Dependency(artifact, dependency.getScope(), dependency.isOptional(), exclusions); |
487 |
|
|
488 |
1029 |
return result; |
489 |
|
} |
490 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
491 |
249 |
private Exclusion convert(org.apache.maven.model.Exclusion exclusion)... |
492 |
|
{ |
493 |
249 |
return new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*"); |
494 |
|
} |
495 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
496 |
94 |
private Artifact resolveVersion(Artifact artifact, List<RemoteRepository> repositories,... |
497 |
|
RepositorySystemSession session) throws VersionResolutionException |
498 |
|
{ |
499 |
94 |
Artifact pomArtifact = ArtifactDescriptorUtils.toPomArtifact(artifact); |
500 |
|
|
501 |
94 |
VersionRequest versionRequest = new VersionRequest(artifact, repositories, ""); |
502 |
94 |
VersionResult versionResult = this.versionResolver.resolveVersion(session, versionRequest); |
503 |
|
|
504 |
94 |
return pomArtifact.setVersion(versionResult.getVersion()); |
505 |
|
} |
506 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
507 |
94 |
private Model loadPom(Artifact artifact, RepositorySystemSession session)... |
508 |
|
throws VersionResolutionException, ArtifactResolutionException, ModelBuildingException |
509 |
|
{ |
510 |
94 |
List<RemoteRepository> repositories = newResolutionRepositories(session); |
511 |
|
|
512 |
94 |
Artifact pomArtifact = resolveVersion(artifact, repositories, session); |
513 |
|
|
514 |
|
|
515 |
|
|
516 |
94 |
ArtifactRequest resolveRequest = new ArtifactRequest(pomArtifact, repositories, ""); |
517 |
94 |
ArtifactResult resolveResult = this.artifactResolver.resolveArtifact(session, resolveRequest); |
518 |
51 |
pomArtifact = resolveResult.getArtifact(); |
519 |
|
|
520 |
|
|
521 |
|
|
522 |
51 |
return createModel(pomArtifact.getFile(), session); |
523 |
|
} |
524 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
525 |
51 |
private Model createModel(File pomFile, RepositorySystemSession session) throws ModelBuildingException... |
526 |
|
{ |
527 |
|
|
528 |
51 |
List<RemoteRepository> repositories = newResolutionRepositories(session, true); |
529 |
|
|
530 |
51 |
ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); |
531 |
51 |
modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); |
532 |
51 |
modelRequest.setProcessPlugins(false); |
533 |
51 |
modelRequest.setTwoPhaseBuilding(false); |
534 |
51 |
modelRequest.setSystemProperties(toProperties(session.getUserProperties(), session.getSystemProperties())); |
535 |
51 |
modelRequest.setModelResolver(new PublicDefaultModelResolver(session, null, "", this.artifactResolver, |
536 |
|
this.versionRangeResolver, this.remoteRepositoryManager, repositories)); |
537 |
51 |
modelRequest.setPomFile(pomFile); |
538 |
|
|
539 |
51 |
return this.modelBuilder.build(modelRequest).getEffectiveModel(); |
540 |
|
} |
541 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
542 |
51 |
private Properties toProperties(Map<String, String> dominant, Map<String, String> recessive)... |
543 |
|
{ |
544 |
51 |
Properties props = new Properties(); |
545 |
51 |
if (recessive != null) { |
546 |
51 |
props.putAll(recessive); |
547 |
|
} |
548 |
51 |
if (dominant != null) { |
549 |
51 |
props.putAll(dominant); |
550 |
|
} |
551 |
51 |
return props; |
552 |
|
} |
553 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
554 |
117 |
List<RemoteRepository> newResolutionRepositories(RepositorySystemSession session)... |
555 |
|
{ |
556 |
117 |
return newResolutionRepositories(session, false); |
557 |
|
} |
558 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
559 |
168 |
List<RemoteRepository> newResolutionRepositories(RepositorySystemSession session, boolean all)... |
560 |
|
{ |
561 |
168 |
List<RemoteRepository> repositories; |
562 |
|
|
563 |
168 |
if (all) { |
564 |
|
|
565 |
51 |
repositories = this.repositoryFactory.getAllMavenRepositories(this.remoteRepository); |
566 |
|
} else { |
567 |
117 |
repositories = Arrays.asList(this.remoteRepository); |
568 |
|
} |
569 |
|
|
570 |
168 |
return this.repositorySystem.newResolutionRepositories(session, repositories); |
571 |
|
} |
572 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
573 |
0 |
RemoteRepository newResolutionRepository(RepositorySystemSession session)... |
574 |
|
{ |
575 |
0 |
return newResolutionRepositories(session).get(0); |
576 |
|
} |
577 |
|
} |