1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.shared.dependency.graph.internal;
20
21 import java.util.List;
22
23 import org.apache.maven.artifact.Artifact;
24 import org.apache.maven.model.Exclusion;
25 import org.apache.maven.shared.dependency.graph.DependencyNode;
26 import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
27
28
29
30
31 public class DefaultDependencyNode implements DependencyNode {
32 private final Artifact artifact;
33
34 private final DependencyNode parent;
35
36 private final String premanagedVersion;
37
38 private final String premanagedScope;
39
40 private final String versionConstraint;
41
42 private List<DependencyNode> children;
43
44 private Boolean optional;
45
46 private List<Exclusion> exclusions;
47
48
49
50
51
52
53
54
55
56
57 public DefaultDependencyNode(
58 DependencyNode parent,
59 Artifact artifact,
60 String premanagedVersion,
61 String premanagedScope,
62 String versionConstraint) {
63 this.parent = parent;
64 this.artifact = artifact;
65 this.premanagedVersion = premanagedVersion;
66 this.premanagedScope = premanagedScope;
67 this.versionConstraint = versionConstraint;
68 }
69
70 public DefaultDependencyNode(
71 DependencyNode parent,
72 Artifact artifact,
73 String premanagedVersion,
74 String premanagedScope,
75 String versionConstraint,
76 Boolean optional,
77 List<Exclusion> exclusions) {
78 this.parent = parent;
79 this.artifact = artifact;
80 this.premanagedVersion = premanagedVersion;
81 this.premanagedScope = premanagedScope;
82 this.versionConstraint = versionConstraint;
83 this.optional = optional;
84 this.exclusions = exclusions;
85 }
86
87
88 public DefaultDependencyNode(Artifact artifact) {
89 this.artifact = artifact;
90 this.parent = null;
91 this.premanagedScope = null;
92 this.premanagedVersion = null;
93 this.versionConstraint = null;
94 }
95
96
97
98
99
100
101
102
103 @Override
104 public boolean accept(DependencyNodeVisitor visitor) {
105 if (visitor.visit(this)) {
106 for (DependencyNode child : getChildren()) {
107 if (!child.accept(visitor)) {
108 break;
109 }
110 }
111 }
112
113 return visitor.endVisit(this);
114 }
115
116
117
118
119 @Override
120 public Artifact getArtifact() {
121 return artifact;
122 }
123
124
125
126
127
128 public void setChildren(List<DependencyNode> children) {
129 this.children = children;
130 }
131
132
133
134
135 @Override
136 public List<DependencyNode> getChildren() {
137 return children;
138 }
139
140
141
142
143 @Override
144 public DependencyNode getParent() {
145 return parent;
146 }
147
148 @Override
149 public String getPremanagedVersion() {
150 return premanagedVersion;
151 }
152
153 @Override
154 public String getPremanagedScope() {
155 return premanagedScope;
156 }
157
158 @Override
159 public String getVersionConstraint() {
160 return versionConstraint;
161 }
162
163 @Override
164 public Boolean getOptional() {
165 return optional;
166 }
167
168 @Override
169 public List<Exclusion> getExclusions() {
170 return exclusions;
171 }
172
173
174
175
176 @Override
177 public String toNodeString() {
178 return artifact + (Boolean.TRUE.equals(optional) ? " (optional)" : "");
179 }
180 }