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 import org.codehaus.plexus.util.xml.Xpp3Dom;
21
22 @Generated
23 public class Plugin
24 extends ConfigurationContainer
25 implements Serializable, Cloneable
26 {
27
28 public Plugin() {
29 this(org.apache.maven.api.model.Plugin.newInstance());
30 }
31
32 public Plugin(org.apache.maven.api.model.Plugin delegate) {
33 this(delegate, null);
34 }
35
36 public Plugin(org.apache.maven.api.model.Plugin delegate, BaseObject parent) {
37 super(delegate, parent);
38 }
39
40 public Plugin clone(){
41 return new Plugin(getDelegate());
42 }
43
44 @Override
45 public org.apache.maven.api.model.Plugin getDelegate() {
46 return (org.apache.maven.api.model.Plugin) super.getDelegate();
47 }
48
49 @Override
50 public boolean equals(Object o) {
51 if (this == o) {
52 return true;
53 }
54 if (o == null || !(o instanceof Plugin)) {
55 return false;
56 }
57 Plugin that = (Plugin) o;
58 return Objects.equals(this.delegate, that.delegate);
59 }
60
61 @Override
62 public int hashCode() {
63 return getDelegate().hashCode();
64 }
65
66 public String getGroupId() {
67 return getDelegate().getGroupId();
68 }
69
70 public void setGroupId(String groupId) {
71 if (!Objects.equals(groupId, getGroupId())) {
72 update(getDelegate().withGroupId(groupId));
73 }
74 }
75
76 public String getArtifactId() {
77 return getDelegate().getArtifactId();
78 }
79
80 public void setArtifactId(String artifactId) {
81 if (!Objects.equals(artifactId, getArtifactId())) {
82 update(getDelegate().withArtifactId(artifactId));
83 }
84 }
85
86 public String getVersion() {
87 return getDelegate().getVersion();
88 }
89
90 public void setVersion(String version) {
91 if (!Objects.equals(version, getVersion())) {
92 update(getDelegate().withVersion(version));
93 }
94 }
95
96 public String getExtensions() {
97 return getDelegate().getExtensions();
98 }
99
100 public void setExtensions(String extensions) {
101 if (!Objects.equals(extensions, getExtensions())) {
102 update(getDelegate().withExtensions(extensions));
103 }
104 }
105
106 @Nonnull
107 public List<PluginExecution> getExecutions() {
108 return new WrapperList<PluginExecution, org.apache.maven.api.model.PluginExecution>(
109 () -> getDelegate().getExecutions(), l -> update(getDelegate().withExecutions(l)),
110 d -> new PluginExecution(d, this), PluginExecution::getDelegate);
111 }
112
113 public void setExecutions(List<PluginExecution> executions) {
114 if (executions == null) {
115 executions = Collections.emptyList();
116 }
117 if (!Objects.equals(executions, getExecutions())) {
118 update(getDelegate().withExecutions(
119 executions.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
120 executions.forEach(e -> e.childrenTracking = this::replace);
121 }
122 }
123
124 public void addExecution(PluginExecution execution) {
125 update(getDelegate().withExecutions(
126 Stream.concat(getDelegate().getExecutions().stream(), Stream.of(execution.getDelegate()))
127 .collect(Collectors.toList())));
128 execution.childrenTracking = this::replace;
129 }
130
131 public void removeExecution(PluginExecution execution) {
132 update(getDelegate().withExecutions(
133 getDelegate().getExecutions().stream()
134 .filter(e -> !Objects.equals(e, execution))
135 .collect(Collectors.toList())));
136 execution.childrenTracking = null;
137 }
138
139 @Nonnull
140 public List<Dependency> getDependencies() {
141 return new WrapperList<Dependency, org.apache.maven.api.model.Dependency>(
142 () -> getDelegate().getDependencies(), l -> update(getDelegate().withDependencies(l)),
143 d -> new Dependency(d, this), Dependency::getDelegate);
144 }
145
146 public void setDependencies(List<Dependency> dependencies) {
147 if (dependencies == null) {
148 dependencies = Collections.emptyList();
149 }
150 if (!Objects.equals(dependencies, getDependencies())) {
151 update(getDelegate().withDependencies(
152 dependencies.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
153 dependencies.forEach(e -> e.childrenTracking = this::replace);
154 }
155 }
156
157 public void addDependency(Dependency dependency) {
158 update(getDelegate().withDependencies(
159 Stream.concat(getDelegate().getDependencies().stream(), Stream.of(dependency.getDelegate()))
160 .collect(Collectors.toList())));
161 dependency.childrenTracking = this::replace;
162 }
163
164 public void removeDependency(Dependency dependency) {
165 update(getDelegate().withDependencies(
166 getDelegate().getDependencies().stream()
167 .filter(e -> !Objects.equals(e, dependency))
168 .collect(Collectors.toList())));
169 dependency.childrenTracking = null;
170 }
171
172 public InputLocation getLocation(Object key) {
173 org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
174 return loc != null ? new InputLocation(loc) : null;
175 }
176
177 public void setLocation(Object key, InputLocation location) {
178 update(org.apache.maven.api.model.Plugin.newBuilder(getDelegate(), true)
179 .location(key, location.toApiLocation()).build());
180 }
181
182 public InputLocation getImportedFrom() {
183 org.apache.maven.api.model.InputLocation loc = getDelegate().getImportedFrom();
184 return loc != null ? new InputLocation(loc) : null;
185 }
186
187 public void setImportedFrom(InputLocation location) {
188 update(org.apache.maven.api.model.Plugin.newBuilder(getDelegate(), true)
189 .importedFrom(location.toApiLocation()).build());
190 }
191
192 public Set<Object> getLocationKeys() {
193 return getDelegate().getLocationKeys();
194 }
195
196 protected boolean replace(Object oldDelegate, Object newDelegate) {
197 if (super.replace(oldDelegate, newDelegate)) {
198 return true;
199 }
200 if (getDelegate().getExecutions().contains(oldDelegate)) {
201 List<org.apache.maven.api.model.PluginExecution> list = new ArrayList<>(getDelegate().getExecutions());
202 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.PluginExecution) newDelegate : d);
203 update(getDelegate().withExecutions(list));
204 return true;
205 }
206 if (getDelegate().getDependencies().contains(oldDelegate)) {
207 List<org.apache.maven.api.model.Dependency> list = new ArrayList<>(getDelegate().getDependencies());
208 list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Dependency) newDelegate : d);
209 update(getDelegate().withDependencies(list));
210 return true;
211 }
212 return false;
213 }
214
215 public static List<org.apache.maven.api.model.Plugin> pluginToApiV4(List<Plugin> list) {
216 return list != null ? new WrapperList<>(list, Plugin::getDelegate, Plugin::new) : null;
217 }
218
219 public static List<Plugin> pluginToApiV3(List<org.apache.maven.api.model.Plugin> list) {
220 return list != null ? new WrapperList<>(list, Plugin::new, Plugin::getDelegate) : null;
221 }
222
223
224
225 public boolean isExtensions() {
226 return (getExtensions() != null) ? Boolean.parseBoolean(getExtensions()) : false;
227 }
228
229
230
231
232 public void setExtensions(boolean extensions) {
233 setExtensions(String.valueOf(extensions));
234 }
235
236
237
238
239 @Deprecated
240 public void flushExecutionMap() {
241 }
242
243
244
245
246
247 public Map<String, PluginExecution> getExecutionsAsMap() {
248 return getExecutions().stream().collect(Collectors.toMap(exec -> exec.getId(), exec -> exec));
249 }
250
251
252
253
254
255
256
257
258
259 public String getId() {
260 return new StringBuilder(128)
261 .append((getGroupId() == null) ? "[unknown-group-id]" : getGroupId())
262 .append(":")
263 .append((getArtifactId() == null) ? "[unknown-artifact-id]" : getArtifactId())
264 .append(":")
265 .append((getVersion() == null) ? "[unknown-version]" : getVersion())
266 .toString();
267 }
268
269
270
271
272 public String getKey() {
273 return constructKey(getGroupId(), getArtifactId());
274 }
275
276
277
278
279
280
281 public static String constructKey(String groupId, String artifactId) {
282 return groupId + ":" + artifactId;
283 }
284
285
286
287 }