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