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 final InputLocation groupIdLocation;
51
52 final InputLocation artifactIdLocation;
53
54 final InputLocation versionLocation;
55
56 final InputLocation reportSetsLocation;
57
58
59
60
61
62 ReportPlugin(
63 String inherited,
64 XmlNode configuration,
65 String groupId,
66 String artifactId,
67 String version,
68 Collection<ReportSet> reportSets,
69 Map<Object, InputLocation> locations,
70 InputLocation location,
71 InputLocation inheritedLocation,
72 InputLocation configurationLocation,
73 InputLocation groupIdLocation,
74 InputLocation artifactIdLocation,
75 InputLocation versionLocation,
76 InputLocation reportSetsLocation
77 )
78 {
79 super(
80 inherited,
81 configuration,
82 locations,
83 location,
84 inheritedLocation,
85 configurationLocation
86 );
87 this.groupId = groupId;
88 this.artifactId = artifactId;
89 this.version = version;
90 this.reportSets = ImmutableCollections.copy( reportSets );
91 this.groupIdLocation = groupIdLocation;
92 this.artifactIdLocation = artifactIdLocation;
93 this.versionLocation = versionLocation;
94 this.reportSetsLocation = reportSetsLocation;
95 }
96
97
98
99
100
101
102 public String getGroupId()
103 {
104 return this.groupId;
105 }
106
107
108
109
110
111
112 public String getArtifactId()
113 {
114 return this.artifactId;
115 }
116
117
118
119
120
121
122
123 public String getVersion()
124 {
125 return this.version;
126 }
127
128
129
130
131
132
133
134 @Nonnull
135 public List<ReportSet> getReportSets()
136 {
137 return this.reportSets;
138 }
139
140
141
142
143 public InputLocation getLocation( Object key )
144 {
145 if ( key instanceof String )
146 {
147 switch ( ( String ) key )
148 {
149 case "groupId":
150 return groupIdLocation;
151 case "artifactId":
152 return artifactIdLocation;
153 case "version":
154 return versionLocation;
155 case "reportSets":
156 return reportSetsLocation;
157 }
158 }
159 return super.getLocation( key );
160 }
161
162
163
164
165
166
167 @Nonnull
168 public Builder with()
169 {
170 return newBuilder( this );
171 }
172
173
174
175
176
177
178 @Nonnull
179 public ReportPlugin withInherited( String inherited )
180 {
181 return with().inherited( inherited ).build();
182 }
183
184
185
186
187
188
189 @Nonnull
190 public ReportPlugin withConfiguration( XmlNode configuration )
191 {
192 return with().configuration( configuration ).build();
193 }
194
195
196
197
198
199
200 @Nonnull
201 public ReportPlugin withGroupId( String groupId )
202 {
203 return with().groupId( groupId ).build();
204 }
205
206
207
208
209
210
211 @Nonnull
212 public ReportPlugin withArtifactId( String artifactId )
213 {
214 return with().artifactId( artifactId ).build();
215 }
216
217
218
219
220
221
222 @Nonnull
223 public ReportPlugin withVersion( String version )
224 {
225 return with().version( version ).build();
226 }
227
228
229
230
231
232
233 @Nonnull
234 public ReportPlugin withReportSets( Collection<ReportSet> reportSets )
235 {
236 return with().reportSets( reportSets ).build();
237 }
238
239
240
241
242
243
244
245
246 @Nonnull
247 public static ReportPlugin newInstance()
248 {
249 return newInstance( true );
250 }
251
252
253
254
255
256
257
258
259 @Nonnull
260 public static ReportPlugin newInstance( boolean withDefaults )
261 {
262 return newBuilder( withDefaults ).build();
263 }
264
265
266
267
268
269
270
271
272 @Nonnull
273 public static Builder newBuilder()
274 {
275 return newBuilder( true );
276 }
277
278
279
280
281
282
283
284 @Nonnull
285 public static Builder newBuilder( boolean withDefaults )
286 {
287 return new Builder( withDefaults );
288 }
289
290
291
292
293
294
295
296
297 @Nonnull
298 public static Builder newBuilder( ReportPlugin from )
299 {
300 return newBuilder( from, false );
301 }
302
303
304
305
306
307
308
309
310 @Nonnull
311 public static Builder newBuilder( ReportPlugin from, boolean forceCopy )
312 {
313 return new Builder( from, forceCopy );
314 }
315
316
317
318
319
320
321 @NotThreadSafe
322 public static class Builder
323 extends ConfigurationContainer.Builder
324 {
325 ReportPlugin base;
326 String groupId;
327 String artifactId;
328 String version;
329 Collection<ReportSet> reportSets;
330
331 Builder( boolean withDefaults )
332 {
333 super( withDefaults );
334 if ( withDefaults )
335 {
336 this.groupId = "org.apache.maven.plugins";
337 }
338 }
339
340 Builder( ReportPlugin base, boolean forceCopy )
341 {
342 super( base, forceCopy );
343 if ( forceCopy )
344 {
345 this.groupId = base.groupId;
346 this.artifactId = base.artifactId;
347 this.version = base.version;
348 this.reportSets = base.reportSets;
349 }
350 else
351 {
352 this.base = base;
353 }
354 }
355
356 @Nonnull
357 public Builder inherited( String inherited )
358 {
359 this.inherited = inherited;
360 return this;
361 }
362
363 @Nonnull
364 public Builder configuration( XmlNode configuration )
365 {
366 this.configuration = configuration;
367 return this;
368 }
369
370 @Nonnull
371 public Builder groupId( String groupId )
372 {
373 this.groupId = groupId;
374 return this;
375 }
376
377 @Nonnull
378 public Builder artifactId( String artifactId )
379 {
380 this.artifactId = artifactId;
381 return this;
382 }
383
384 @Nonnull
385 public Builder version( String version )
386 {
387 this.version = version;
388 return this;
389 }
390
391 @Nonnull
392 public Builder reportSets( Collection<ReportSet> reportSets )
393 {
394 this.reportSets = reportSets;
395 return this;
396 }
397
398
399 @Nonnull
400 public Builder location( Object key, InputLocation location )
401 {
402 if ( location != null )
403 {
404 if ( this.locations == null )
405 {
406 this.locations = new HashMap<>();
407 }
408 this.locations.put( key, location );
409 }
410 return this;
411 }
412
413 @Nonnull
414 public ReportPlugin build()
415 {
416 if ( base != null
417 && ( inherited == null || inherited == base.inherited )
418 && ( configuration == null || configuration == base.configuration )
419 && ( groupId == null || groupId == base.groupId )
420 && ( artifactId == null || artifactId == base.artifactId )
421 && ( version == null || version == base.version )
422 && ( reportSets == null || reportSets == base.reportSets )
423 )
424 {
425 return base;
426 }
427 Map<Object, InputLocation> locations = null;
428 InputLocation location = null;
429 InputLocation inheritedLocation = null;
430 InputLocation configurationLocation = null;
431 InputLocation groupIdLocation = null;
432 InputLocation artifactIdLocation = null;
433 InputLocation versionLocation = null;
434 InputLocation reportSetsLocation = null;
435 if ( this.locations != null )
436 {
437 locations = this.locations;
438 location = locations.remove( "" );
439 inheritedLocation = locations.remove( "inherited" );
440 configurationLocation = locations.remove( "configuration" );
441 groupIdLocation = locations.remove( "groupId" );
442 artifactIdLocation = locations.remove( "artifactId" );
443 versionLocation = locations.remove( "version" );
444 reportSetsLocation = locations.remove( "reportSets" );
445 }
446 return new ReportPlugin(
447 inherited != null ? inherited : ( base != null ? base.inherited : null ),
448 configuration != null ? configuration : ( base != null ? base.configuration : null ),
449 groupId != null ? groupId : ( base != null ? base.groupId : null ),
450 artifactId != null ? artifactId : ( base != null ? base.artifactId : null ),
451 version != null ? version : ( base != null ? base.version : null ),
452 reportSets != null ? reportSets : ( base != null ? base.reportSets : null ),
453 locations != null ? locations : ( base != null ? base.locations : null ),
454 location != null ? location : ( base != null ? base.location : null ),
455 inheritedLocation != null ? inheritedLocation : ( base != null ? base.inheritedLocation : null ),
456 configurationLocation != null ? configurationLocation : ( base != null ? base.configurationLocation : null ),
457 groupIdLocation != null ? groupIdLocation : ( base != null ? base.groupIdLocation : null ),
458 artifactIdLocation != null ? artifactIdLocation : ( base != null ? base.artifactIdLocation : null ),
459 versionLocation != null ? versionLocation : ( base != null ? base.versionLocation : null ),
460 reportSetsLocation != null ? reportSetsLocation : ( base != null ? base.reportSetsLocation : null )
461 );
462 }
463 }
464
465
466
467 private java.util.Map<String, ReportSet> reportSetMap = null;
468
469
470
471
472 public void flushReportSetMap()
473 {
474 this.reportSetMap = null;
475 }
476
477
478
479
480
481 public java.util.Map<String, ReportSet> getReportSetsAsMap()
482 {
483 if ( reportSetMap == null )
484 {
485 reportSetMap = new java.util.LinkedHashMap<String, ReportSet>();
486 if ( getReportSets() != null )
487 {
488 for ( java.util.Iterator<ReportSet> i = getReportSets().iterator(); i.hasNext(); )
489 {
490 ReportSet reportSet = (ReportSet) i.next();
491 reportSetMap.put( reportSet.getId(), reportSet );
492 }
493 }
494 }
495
496 return reportSetMap;
497 }
498
499
500
501
502 public String getKey()
503 {
504 return constructKey( getGroupId(), getArtifactId() );
505 }
506
507
508
509
510
511
512 public static String constructKey( String groupId, String artifactId )
513 {
514 return groupId + ":" + artifactId;
515 }
516
517
518 }