Debian Codegraph @

src/main/java/capsule/Dependencies.java

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