1
2
3
4
5 package org.apache.maven.model;
6
7 import java.io.Serializable;
8 import java.util.AbstractList;
9 import java.util.ArrayList;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Objects;
15 import java.util.Set;
16 import java.util.stream.Collectors;
17 import java.util.stream.Stream;
18 import org.apache.maven.api.annotations.Generated;
19 import org.apache.maven.api.annotations.Nonnull;
20
21 @Generated
22 public class Dependency
23 extends BaseObject
24 {
25
26 public Dependency() {
27 this(org.apache.maven.api.model.Dependency.newInstance());
28 }
29
30 public Dependency(org.apache.maven.api.model.Dependency delegate) {
31 this(delegate, null);
32 }
33
34 public Dependency(org.apache.maven.api.model.Dependency delegate, BaseObject parent) {
35 super(delegate, parent);
36 }
37
38 public Dependency clone(){
39 return new Dependency(getDelegate());
40 }
41
42 public org.apache.maven.api.model.Dependency getDelegate() {
43 return (org.apache.maven.api.model.Dependency) super.getDelegate();
44 }
45
46 @Override
47 public boolean equals(Object o) {
48 if (this == o) {
49 return true;
50 }
51 if (o == null || !(o instanceof Dependency)) {
52 return false;
53 }
54 Dependency that = (Dependency) o;
55 return Objects.equals(this.delegate, that.delegate);
56 }
57
58 @Override
59 public int hashCode() {
60 return getDelegate().hashCode();
61 }
62
63 public String getGroupId() {
64 return getDelegate().getGroupId();
65 }
66
67 public void setGroupId(String groupId) {
68 if (!Objects.equals(groupId, getGroupId())) {
69 update(getDelegate().withGroupId(groupId));
70 }
71 }
72
73 public String getArtifactId() {
74 return getDelegate().getArtifactId();
75 }
76
77 public void setArtifactId(String artifactId) {
78 if (!Objects.equals(artifactId, getArtifactId())) {
79 update(getDelegate().withArtifactId(artifactId));
80 }
81 }
82
83 public String getVersion() {
84 return getDelegate().getVersion();
85 }
86
87 public void setVersion(String version) {
88 if (!Objects.equals(version, getVersion())) {
89 update(getDelegate().withVersion(version));
90 }
91 }
92
93 public String getType() {
94 return getDelegate().getType();
95 }
96
97 public void setType(String type) {
98 if (!Objects.equals(type, getType())) {
99 update(getDelegate().withType(type));
100 }
101 }
102
103 public String getClassifier() {
104 return getDelegate().getClassifier();
105 }
106
107 public void setClassifier(String classifier) {
108 if (!Objects.equals(classifier, getClassifier())) {
109 update(getDelegate().withClassifier(classifier));
110 }
111 }
112
113 public String getScope() {
114 return getDelegate().getScope();
115 }
116
117 public void setScope(String scope) {
118 if (!Objects.equals(scope, getScope())) {
119 update(getDelegate().withScope(scope));
120 }
121 }
122
123 public String getSystemPath() {
124 return getDelegate().getSystemPath();
125 }
126
127 public void setSystemPath(String systemPath) {
128 if (!Objects.equals(systemPath, getSystemPath())) {
129 update(getDelegate().withSystemPath(systemPath));
130 }
131 }
132
133 @Nonnull
134 public List<Exclusion> getExclusions() {
135 return new WrapperList<Exclusion, org.apache.maven.api.model.Exclusion>(
136 () -> getDelegate().getExclusions(), l -> update(getDelegate().withExclusions(l)),
137 d -> new Exclusion(d, this), Exclusion::getDelegate);
138 }
139
140 public void setExclusions(List<Exclusion> exclusions) {
141 if (exclusions == null) {
142 exclusions = Collections.emptyList();
143 }
144 if (!Objects.equals(exclusions, getExclusions())) {
145 update(getDelegate().withExclusions(
146 exclusions.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
147 exclusions.forEach(e -> e.childrenTracking = this::replace);
148 }
149 }
150
151 public void addExclusion(Exclusion exclusion) {
152 update(getDelegate().withExclusions(
153 Stream.concat(getDelegate().getExclusions().stream(), Stream.of(exclusion.getDelegate()))
154 .collect(Collectors.toList())));
155 exclusion.childrenTracking = this::replace;
156 }
157
158 public void removeExclusion(Exclusion exclusion) {
159 update(getDelegate().withExclusions(
160 getDelegate().getExclusions().stream()
161 .filter(e -> !Objects.equals(e, exclusion))
162 .collect(Collectors.toList())));
163 exclusion.childrenTracking = null;
164 }
165
166 public String getOptional() {
167 return getDelegate().getOptional();
168 }
169
170 public void setOptional(String optional) {
171 if (!Objects.equals(optional, getOptional())) {
172 update(getDelegate().withOptional(optional));
173 }
174 }
175
176 public InputLocation getLocation(Object key) {
177 org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
178 return loc != null ? new InputLocation(loc) : null;
179 }
180
181 public void setLocation(Object key, InputLocation location) {
182 update(org.apache.maven.api.model.Dependency.newBuilder(getDelegate(), true)
183 .location(key, location.toApiLocation()).build());
184 }
185
186 public InputLocation getImportedFrom() {
187 org.apache.maven.api.model.InputLocation loc = getDelegate().getImportedFrom();
188 return loc != null ? new InputLocation(loc) : null;
189 }
190
191 public void setImportedFrom(InputLocation location) {
192 update(org.apache.maven.api.model.Dependency.newBuilder(getDelegate(), true)
193 .importedFrom(location.toApiLocation()).build());
194 }
195
196 public Set<Object> getLocationKeys() {
197 return getDelegate().getLocationKeys();
198 }
199
200 protected boolean replace(Object oldDelegate, Object newDelegate) {
201 if (super.replace(oldDelegate, newDelegate)) {
202 return true;
203 }
204 if (getDelegate().getExclusions().contains(oldDelegate)) {
205 List<org.apache.maven.api.model.Exclusion> list = new ArrayList<>(getDelegate().getExclusions());
206 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Exclusion) newDelegate : d);
207 update(getDelegate().withExclusions(list));
208 return true;
209 }
210 return false;
211 }
212
213 public static List<org.apache.maven.api.model.Dependency> dependencyToApiV4(List<Dependency> list) {
214 return list != null ? new WrapperList<>(list, Dependency::getDelegate, Dependency::new) : null;
215 }
216
217 public static List<Dependency> dependencyToApiV3(List<org.apache.maven.api.model.Dependency> list) {
218 return list != null ? new WrapperList<>(list, Dependency::new, Dependency::getDelegate) : null;
219 }
220
221
222
223 public boolean isOptional() {
224 return (getOptional() != null) ? Boolean.parseBoolean(getOptional()) : false;
225 }
226
227
228
229
230
231 public void setOptional(boolean optional) {
232 setOptional(String.valueOf(optional));
233 }
234
235
236
237
238
239
240
241
242 public String toString() {
243 return "Dependency {groupId=" + getGroupId() + ", artifactId=" + getArtifactId() + ", version=" + getVersion() + ", type=" + getType() + "}";
244 }
245
246
247
248
249 private volatile String managementKey;
250
251
252
253
254 public String getManagementKey() {
255 if (managementKey == null) {
256 managementKey = getGroupId() + ":" + getArtifactId() + ":" + getType() + (getClassifier() != null ? ":" + getClassifier() : "");
257 }
258 return managementKey;
259 }
260
261
262 }