1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.metadata;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import org.apache.maven.artifact.ArtifactScopeEnum;
26
27
28
29
30
31
32 @Deprecated
33 public class ClasspathContainer implements Iterable<ArtifactMetadata> {
34 private List<ArtifactMetadata> classpath;
35
36 private ArtifactScopeEnum scope;
37
38
39 public ClasspathContainer(ArtifactScopeEnum scope) {
40 this.scope = ArtifactScopeEnum.checkScope(scope);
41 }
42
43
44 public ClasspathContainer(List<ArtifactMetadata> classpath, ArtifactScopeEnum scope) {
45 this(scope);
46 this.classpath = classpath;
47 }
48
49
50 @Override
51 public Iterator<ArtifactMetadata> iterator() {
52 return classpath == null ? null : classpath.iterator();
53 }
54
55
56 public ClasspathContainer add(ArtifactMetadata md) {
57 if (classpath == null) {
58 classpath = new ArrayList<>(16);
59 }
60
61 classpath.add(md);
62
63 return this;
64 }
65
66
67 public List<ArtifactMetadata> getClasspath() {
68 return classpath;
69 }
70
71
72 public MetadataTreeNode getClasspathAsTree() throws MetadataResolutionException {
73 if (classpath == null || classpath.size() < 1) {
74 return null;
75 }
76
77 MetadataTreeNode tree = null;
78 MetadataTreeNode parent = null;
79
80 for (ArtifactMetadata md : classpath) {
81 MetadataTreeNode node = new MetadataTreeNode(md, parent, md.isResolved(), md.getArtifactScope());
82 if (tree == null) {
83 tree = node;
84 }
85
86 if (parent != null) {
87 parent.setNChildren(1);
88 parent.addChild(0, node);
89 }
90
91 parent = node;
92 }
93 return tree;
94 }
95
96 public void setClasspath(List<ArtifactMetadata> classpath) {
97 this.classpath = classpath;
98 }
99
100 public ArtifactScopeEnum getScope() {
101 return scope;
102 }
103
104 public void setScope(ArtifactScopeEnum scope) {
105 this.scope = scope;
106 }
107
108
109 @Override
110 public String toString() {
111 StringBuilder sb = new StringBuilder(256);
112 sb.append("[scope=").append(scope.getScope());
113 if (classpath != null) {
114 for (ArtifactMetadata md : classpath) {
115 sb.append(": ")
116 .append(md.toString())
117 .append('{')
118 .append(md.getArtifactUri())
119 .append('}');
120 }
121 }
122 sb.append(']');
123 return sb.toString();
124 }
125
126
127 }