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