1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15 import org.apache.maven.api.annotations.Experimental;
16 import org.apache.maven.api.annotations.Generated;
17 import org.apache.maven.api.annotations.Immutable;
18 import org.apache.maven.api.annotations.Nonnull;
19 import org.apache.maven.api.annotations.NotThreadSafe;
20 import org.apache.maven.api.annotations.ThreadSafe;
21 import org.apache.maven.api.xml.XmlNode;
22
23
24
25
26 @Experimental
27 @Generated @ThreadSafe @Immutable
28 public class ReportPlugin
29 extends ConfigurationContainer
30 implements Serializable, InputLocationTracker
31 {
32
33
34
35 final String groupId;
36
37
38
39 final String artifactId;
40
41
42
43
44 final String version;
45
46
47
48
49 final List<ReportSet> reportSets;
50
51 final Map<Object, InputLocation> locations;
52
53
54
55
56
57 protected ReportPlugin(Builder builder) {
58 super(builder);
59 this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
60 this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
61 this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
62 this.reportSets = ImmutableCollections.copy(builder.reportSets != null ? builder.reportSets : (builder.base != null ? builder.base.reportSets : null));
63 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
64 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
65 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
66 mutableLocations.put("groupId", newlocs.containsKey("groupId") ? newlocs.get("groupId") : oldlocs.get("groupId"));
67 mutableLocations.put("artifactId", newlocs.containsKey("artifactId") ? newlocs.get("artifactId") : oldlocs.get("artifactId"));
68 mutableLocations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
69 mutableLocations.put("reportSets", newlocs.containsKey("reportSets") ? newlocs.get("reportSets") : oldlocs.get("reportSets"));
70 this.locations = Collections.unmodifiableMap(mutableLocations);
71 }
72
73
74
75
76
77
78 public String getGroupId() {
79 return this.groupId;
80 }
81
82
83
84
85
86
87 public String getArtifactId() {
88 return this.artifactId;
89 }
90
91
92
93
94
95
96
97 public String getVersion() {
98 return this.version;
99 }
100
101
102
103
104
105
106
107 @Nonnull
108 public List<ReportSet> getReportSets() {
109 return this.reportSets;
110 }
111
112
113
114
115 public InputLocation getLocation(Object key) {
116 return locations != null ? locations.get(key) : null;
117 }
118
119
120
121
122 public Set<Object> getLocationKeys() {
123 return locations != null ? locations.keySet() : null;
124 }
125
126
127
128
129
130
131 @Nonnull
132 public Builder with() {
133 return newBuilder(this);
134 }
135
136
137
138
139
140
141 @Nonnull
142 public ReportPlugin withInherited(String inherited) {
143 return newBuilder(this, true).inherited(inherited).build();
144 }
145
146
147
148
149
150
151 @Nonnull
152 public ReportPlugin withConfiguration(XmlNode configuration) {
153 return newBuilder(this, true).configuration(configuration).build();
154 }
155
156
157
158
159
160
161 @Nonnull
162 public ReportPlugin withGroupId(String groupId) {
163 return newBuilder(this, true).groupId(groupId).build();
164 }
165
166
167
168
169
170
171 @Nonnull
172 public ReportPlugin withArtifactId(String artifactId) {
173 return newBuilder(this, true).artifactId(artifactId).build();
174 }
175
176
177
178
179
180
181 @Nonnull
182 public ReportPlugin withVersion(String version) {
183 return newBuilder(this, true).version(version).build();
184 }
185
186
187
188
189
190
191 @Nonnull
192 public ReportPlugin withReportSets(Collection<ReportSet> reportSets) {
193 return newBuilder(this, true).reportSets(reportSets).build();
194 }
195
196
197
198
199
200
201
202
203 @Nonnull
204 public static ReportPlugin newInstance() {
205 return newInstance(true);
206 }
207
208
209
210
211
212
213
214
215 @Nonnull
216 public static ReportPlugin newInstance(boolean withDefaults) {
217 return newBuilder(withDefaults).build();
218 }
219
220
221
222
223
224
225
226
227 @Nonnull
228 public static Builder newBuilder() {
229 return newBuilder(true);
230 }
231
232
233
234
235
236
237
238 @Nonnull
239 public static Builder newBuilder(boolean withDefaults) {
240 return new Builder(withDefaults);
241 }
242
243
244
245
246
247
248
249
250 @Nonnull
251 public static Builder newBuilder(ReportPlugin from) {
252 return newBuilder(from, false);
253 }
254
255
256
257
258
259
260
261
262 @Nonnull
263 public static Builder newBuilder(ReportPlugin from, boolean forceCopy) {
264 return new Builder(from, forceCopy);
265 }
266
267
268
269
270
271
272 @NotThreadSafe
273 public static class Builder
274 extends ConfigurationContainer.Builder
275 {
276 ReportPlugin base;
277 String groupId;
278 String artifactId;
279 String version;
280 Collection<ReportSet> reportSets;
281
282 protected Builder(boolean withDefaults) {
283 super(withDefaults);
284 if (withDefaults) {
285 this.groupId = "org.apache.maven.plugins";
286 }
287 }
288
289 protected Builder(ReportPlugin base, boolean forceCopy) {
290 super(base, forceCopy);
291 if (forceCopy) {
292 this.groupId = base.groupId;
293 this.artifactId = base.artifactId;
294 this.version = base.version;
295 this.reportSets = base.reportSets;
296 this.locations = base.locations;
297 this.importedFrom = base.importedFrom;
298 } else {
299 this.base = base;
300 }
301 }
302
303 @Nonnull
304 public Builder inherited(String inherited) {
305 this.inherited = inherited;
306 return this;
307 }
308
309 @Nonnull
310 public Builder configuration(XmlNode configuration) {
311 this.configuration = configuration;
312 return this;
313 }
314
315 @Nonnull
316 public Builder groupId(String groupId) {
317 this.groupId = groupId;
318 return this;
319 }
320
321 @Nonnull
322 public Builder artifactId(String artifactId) {
323 this.artifactId = artifactId;
324 return this;
325 }
326
327 @Nonnull
328 public Builder version(String version) {
329 this.version = version;
330 return this;
331 }
332
333 @Nonnull
334 public Builder reportSets(Collection<ReportSet> reportSets) {
335 this.reportSets = reportSets;
336 return this;
337 }
338
339
340 @Nonnull
341 public Builder location(Object key, InputLocation location) {
342 if (location != null) {
343 if (!(this.locations instanceof HashMap)) {
344 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
345 }
346 this.locations.put(key, location);
347 }
348 return this;
349 }
350
351 @Nonnull
352 public Builder importedFrom(InputLocation importedFrom) {
353 this.importedFrom = importedFrom;
354 return this;
355 }
356
357 @Nonnull
358 public ReportPlugin build() {
359
360 if (base != null
361 && (inherited == null || inherited == base.inherited)
362 && (configuration == null || configuration == base.configuration)
363 && (groupId == null || groupId == base.groupId)
364 && (artifactId == null || artifactId == base.artifactId)
365 && (version == null || version == base.version)
366 && (reportSets == null || reportSets == base.reportSets)
367 ) {
368 return base;
369 }
370 return new ReportPlugin(this);
371 }
372 }
373
374
375
376 private java.util.Map<String, ReportSet> reportSetMap = null;
377
378
379
380
381 public void flushReportSetMap() {
382 this.reportSetMap = null;
383 }
384
385
386
387
388
389 public java.util.Map<String, ReportSet> getReportSetsAsMap() {
390 if (reportSetMap == null) {
391 reportSetMap = new java.util.LinkedHashMap<String, ReportSet>();
392 if (getReportSets() != null) {
393 for (java.util.Iterator<ReportSet> i = getReportSets().iterator(); i.hasNext(); ) {
394 ReportSet reportSet = (ReportSet) i.next();
395 reportSetMap.put(reportSet.getId(), reportSet);
396 }
397 }
398 }
399
400 return reportSetMap;
401 }
402
403
404
405
406 public String getKey() {
407 return constructKey(getGroupId(), getArtifactId());
408 }
409
410
411
412
413
414
415 public static String constructKey(String groupId, String artifactId) {
416 return groupId + ":" + artifactId;
417 }
418
419
420 }