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