-
Notifications
You must be signed in to change notification settings - Fork 9
/
Dependencies.java
73 lines (61 loc) · 2.14 KB
/
Dependencies.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Capsule
* Copyright (c) 2014-2016, Parallel Universe Software Co. and Contributors. All rights reserved.
*
* This program and the accompanying materials are licensed under the terms
* of the Eclipse Public License v1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package capsule;
import java.util.Collection;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.graph.Dependency;
import org.eclipse.aether.graph.Exclusion;
import org.eclipse.aether.repository.RemoteRepository;
/**
* Used by build tool plugins
* @author circlespainter
*/
public class Dependencies {
/**
* Builds the Capsule string representation of an Aether RemoteRepository object
*
* @param rr The remote repository
*/
public static String toCapsuleRepositoryString(RemoteRepository rr) {
return DependencyManager.WELL_KNOWN_REPOS.keySet().contains(rr.getId())
? rr.getId() : rr.getUrl();
}
/**
* Builds the Capsule string representation of an Aether Dependency object
*
* @param d The dependency
*/
public static String toCapsuleDependencyString(Dependency d) {
return toCapsuleArtifactString(d.getArtifact()) + toCapsuleExclusionsString(d.getExclusions());
}
private static String toCapsuleArtifactString(Artifact a) {
return DependencyManager.artifactToCoords(a);
}
private static String toCapsuleExclusionsString(Collection<Exclusion> exclusions) {
final StringBuilder res = new StringBuilder();
if (!exclusions.isEmpty()) {
res.append("(");
boolean starting = true;
for (Exclusion e : exclusions) {
if (!starting)
res.append(",");
else
starting = false;
res.append(e.getGroupId());
res.append(":");
if (e.getArtifactId() != null && e.getArtifactId().length() > 0)
res.append(e.getArtifactId());
else
res.append("*");
}
res.append(")");
}
return res.toString();
}
}