View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
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   * The {@code <plugin>} element in {@code <reporting><plugins>} contains informations required for a report plugin.
23   */
24  @Experimental
25  @Generated @ThreadSafe @Immutable
26  public class ReportPlugin
27      extends ConfigurationContainer
28      implements Serializable, InputLocationTracker
29  {
30      /**
31       * The group ID of the reporting plugin in the repository.
32       */
33      final String groupId;
34      /**
35       * The artifact ID of the reporting plugin in the repository.
36       */
37      final String artifactId;
38      /**
39       * The version of the reporting plugin to be used. Starting with Maven 3, if no version is defined explicitly,
40       * version is searched in {@code build/plugins} then in {@code build/pluginManagement}.
41       */
42      final String version;
43      /**
44       * Multiple specifications of a set of reports, each having (possibly) different
45       * configuration. This is the reporting parallel to an {@code execution} in the build.
46       */
47      final List<ReportSet> reportSets;
48      /** Location of the xml element for the field groupId. */
49      final InputLocation groupIdLocation;
50      /** Location of the xml element for the field artifactId. */
51      final InputLocation artifactIdLocation;
52      /** Location of the xml element for the field version. */
53      final InputLocation versionLocation;
54      /** Location of the xml element for the field reportSets. */
55      final InputLocation reportSetsLocation;
56  
57      /**
58        * Constructor for this class, package protected.
59        * @see Builder#build()
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       * The group ID of the reporting plugin in the repository.
98       *
99       * @return a {@code String}
100      */
101     public String getGroupId()
102     {
103         return this.groupId;
104     }
105 
106     /**
107      * The artifact ID of the reporting plugin in the repository.
108      *
109      * @return a {@code String}
110      */
111     public String getArtifactId()
112     {
113         return this.artifactId;
114     }
115 
116     /**
117      * The version of the reporting plugin to be used. Starting with Maven 3, if no version is defined explicitly,
118      * version is searched in {@code build/plugins} then in {@code build/pluginManagement}.
119      *
120      * @return a {@code String}
121      */
122     public String getVersion()
123     {
124         return this.version;
125     }
126 
127     /**
128      * Multiple specifications of a set of reports, each having (possibly) different
129      * configuration. This is the reporting parallel to an {@code execution} in the build.
130      *
131      * @return a {@code List<ReportSet>}
132      */
133     @Nonnull
134     public List<ReportSet> getReportSets()
135     {
136         return this.reportSets;
137     }
138 
139     /**
140      * Gets the location of the specified field in the input source.
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      * Creates a new builder with this object as the basis.
163      *
164      * @return a {@code Builder}
165      */
166     @Nonnull
167     public Builder with()
168     {
169         return newBuilder( this );
170     }
171     /**
172      * Creates a new {@code ReportPlugin} instance using the specified inherited.
173      *
174      * @param inherited the new {@code String} to use
175      * @return a {@code ReportPlugin} with the specified inherited
176      */
177     @Nonnull
178     public ReportPlugin withInherited( String inherited )
179     {
180         return with().inherited( inherited ).build();
181     }
182     /**
183      * Creates a new {@code ReportPlugin} instance using the specified configuration.
184      *
185      * @param configuration the new {@code Dom} to use
186      * @return a {@code ReportPlugin} with the specified configuration
187      */
188     @Nonnull
189     public ReportPlugin withConfiguration( Dom configuration )
190     {
191         return with().configuration( configuration ).build();
192     }
193     /**
194      * Creates a new {@code ReportPlugin} instance using the specified groupId.
195      *
196      * @param groupId the new {@code String} to use
197      * @return a {@code ReportPlugin} with the specified groupId
198      */
199     @Nonnull
200     public ReportPlugin withGroupId( String groupId )
201     {
202         return with().groupId( groupId ).build();
203     }
204     /**
205      * Creates a new {@code ReportPlugin} instance using the specified artifactId.
206      *
207      * @param artifactId the new {@code String} to use
208      * @return a {@code ReportPlugin} with the specified artifactId
209      */
210     @Nonnull
211     public ReportPlugin withArtifactId( String artifactId )
212     {
213         return with().artifactId( artifactId ).build();
214     }
215     /**
216      * Creates a new {@code ReportPlugin} instance using the specified version.
217      *
218      * @param version the new {@code String} to use
219      * @return a {@code ReportPlugin} with the specified version
220      */
221     @Nonnull
222     public ReportPlugin withVersion( String version )
223     {
224         return with().version( version ).build();
225     }
226     /**
227      * Creates a new {@code ReportPlugin} instance using the specified reportSets.
228      *
229      * @param reportSets the new {@code Collection<ReportSet>} to use
230      * @return a {@code ReportPlugin} with the specified reportSets
231      */
232     @Nonnull
233     public ReportPlugin withReportSets( Collection<ReportSet> reportSets )
234     {
235         return with().reportSets( reportSets ).build();
236     }
237 
238     /**
239      * Creates a new {@code ReportPlugin} instance.
240      * Equivalent to {@code newInstance( true )}.
241      * @see #newInstance(boolean)
242      *
243      * @return a new {@code ReportPlugin}
244      */
245     @Nonnull
246     public static ReportPlugin newInstance()
247     {
248         return newInstance( true );
249     }
250 
251     /**
252      * Creates a new {@code ReportPlugin} instance using default values or not.
253      * Equivalent to {@code newBuilder( withDefaults ).build()}.
254      *
255      * @param withDefaults the boolean indicating whether default values should be used
256      * @return a new {@code ReportPlugin}
257      */
258     @Nonnull
259     public static ReportPlugin newInstance( boolean withDefaults )
260     {
261         return newBuilder( withDefaults ).build();
262     }
263 
264     /**
265      * Creates a new {@code ReportPlugin} builder instance.
266      * Equivalent to {@code newBuilder( true )}.
267      * @see #newBuilder(boolean)
268      *
269      * @return a new {@code Builder}
270      */
271     @Nonnull
272     public static Builder newBuilder()
273     {
274         return newBuilder( true );
275     }
276 
277     /**
278      * Creates a new {@code ReportPlugin} builder instance using default values or not.
279      *
280      * @param withDefaults the boolean indicating whether default values should be used
281      * @return a new {@code Builder}
282      */
283     @Nonnull
284     public static Builder newBuilder( boolean withDefaults )
285     {
286         return new Builder( withDefaults );
287     }
288 
289     /**
290      * Creates a new {@code ReportPlugin} builder instance using the specified object as a basis.
291      * Equivalent to {@code newBuilder( from, false )}.
292      *
293      * @param from the {@code ReportPlugin} instance to use as a basis
294      * @return a new {@code Builder}
295      */
296     @Nonnull
297     public static Builder newBuilder( ReportPlugin from )
298     {
299         return newBuilder( from, false );
300     }
301 
302     /**
303      * Creates a new {@code ReportPlugin} builder instance using the specified object as a basis.
304      *
305      * @param from the {@code ReportPlugin} instance to use as a basis
306      * @param forceCopy the boolean indicating if a copy should be forced
307      * @return a new {@code Builder}
308      */
309     @Nonnull
310     public static Builder newBuilder( ReportPlugin from, boolean forceCopy )
311     {
312         return new Builder( from, forceCopy );
313     }
314 
315     /**
316      * Builder class used to create ReportPlugin instances.
317      * @see #with()
318      * @see #newBuilder()
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      * Reset the {@code reportSetMap} field to {@code null}
470      */
471     public void flushReportSetMap()
472     {
473         this.reportSetMap = null;
474     }
475 
476     /**
477      * @return a Map of reportSets field with {@code ReportSet#getId()} as key
478      * @see ReportSet#getId()
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      * @return the key of the report plugin, ie {@code groupId:artifactId}
500      */
501     public String getKey()
502     {
503         return constructKey( getGroupId(), getArtifactId() );
504     }
505 
506     /**
507      * @param groupId The group ID of the plugin in the repository
508      * @param artifactId The artifact ID of the reporting plugin in the repository
509      * @return the key of the report plugin, ie {@code groupId:artifactId}
510      */
511     public static String constructKey( String groupId, String artifactId )
512     {
513         return groupId + ":" + artifactId;
514     }
515             
516           
517 }