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