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