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  
50      /**
51        * Constructor for this class, package protected.
52        * @see Builder#build()
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       * The group ID of the reporting plugin in the repository.
76       *
77       * @return a {@code String}
78       */
79      public String getGroupId() {
80          return this.groupId;
81      }
82  
83      /**
84       * The artifact ID of the reporting plugin in the repository.
85       *
86       * @return a {@code String}
87       */
88      public String getArtifactId() {
89          return this.artifactId;
90      }
91  
92      /**
93       * The version of the reporting plugin to be used. Starting with Maven 3, if no version is defined explicitly,
94       * version is searched in {@code build/plugins} then in {@code build/pluginManagement}.
95       *
96       * @return a {@code String}
97       */
98      public String getVersion() {
99          return this.version;
100     }
101 
102     /**
103      * Multiple specifications of a set of reports, each having (possibly) different
104      * configuration. This is the reporting parallel to an {@code execution} in the build.
105      *
106      * @return a {@code List<ReportSet>}
107      */
108     @Nonnull
109     public List<ReportSet> getReportSets() {
110         return this.reportSets;
111     }
112 
113     /**
114      * Creates a new builder with this object as the basis.
115      *
116      * @return a {@code Builder}
117      */
118     @Nonnull
119     public Builder with() {
120         return newBuilder(this);
121     }
122     /**
123      * Creates a new {@code ReportPlugin} instance using the specified inherited.
124      *
125      * @param inherited the new {@code String} to use
126      * @return a {@code ReportPlugin} with the specified inherited
127      */
128     @Nonnull
129     public ReportPlugin withInherited(String inherited) {
130         return newBuilder(this, true).inherited(inherited).build();
131     }
132     /**
133      * Creates a new {@code ReportPlugin} instance using the specified configuration.
134      *
135      * @param configuration the new {@code XmlNode} to use
136      * @return a {@code ReportPlugin} with the specified configuration
137      */
138     @Nonnull
139     public ReportPlugin withConfiguration(XmlNode configuration) {
140         return newBuilder(this, true).configuration(configuration).build();
141     }
142     /**
143      * Creates a new {@code ReportPlugin} instance using the specified groupId.
144      *
145      * @param groupId the new {@code String} to use
146      * @return a {@code ReportPlugin} with the specified groupId
147      */
148     @Nonnull
149     public ReportPlugin withGroupId(String groupId) {
150         return newBuilder(this, true).groupId(groupId).build();
151     }
152     /**
153      * Creates a new {@code ReportPlugin} instance using the specified artifactId.
154      *
155      * @param artifactId the new {@code String} to use
156      * @return a {@code ReportPlugin} with the specified artifactId
157      */
158     @Nonnull
159     public ReportPlugin withArtifactId(String artifactId) {
160         return newBuilder(this, true).artifactId(artifactId).build();
161     }
162     /**
163      * Creates a new {@code ReportPlugin} instance using the specified version.
164      *
165      * @param version the new {@code String} to use
166      * @return a {@code ReportPlugin} with the specified version
167      */
168     @Nonnull
169     public ReportPlugin withVersion(String version) {
170         return newBuilder(this, true).version(version).build();
171     }
172     /**
173      * Creates a new {@code ReportPlugin} instance using the specified reportSets.
174      *
175      * @param reportSets the new {@code Collection<ReportSet>} to use
176      * @return a {@code ReportPlugin} with the specified reportSets
177      */
178     @Nonnull
179     public ReportPlugin withReportSets(Collection<ReportSet> reportSets) {
180         return newBuilder(this, true).reportSets(reportSets).build();
181     }
182 
183     /**
184      * Creates a new {@code ReportPlugin} instance.
185      * Equivalent to {@code newInstance(true)}.
186      * @see #newInstance(boolean)
187      *
188      * @return a new {@code ReportPlugin}
189      */
190     @Nonnull
191     public static ReportPlugin newInstance() {
192         return newInstance(true);
193     }
194 
195     /**
196      * Creates a new {@code ReportPlugin} instance using default values or not.
197      * Equivalent to {@code newBuilder(withDefaults).build()}.
198      *
199      * @param withDefaults the boolean indicating whether default values should be used
200      * @return a new {@code ReportPlugin}
201      */
202     @Nonnull
203     public static ReportPlugin newInstance(boolean withDefaults) {
204         return newBuilder(withDefaults).build();
205     }
206 
207     /**
208      * Creates a new {@code ReportPlugin} builder instance.
209      * Equivalent to {@code newBuilder(true)}.
210      * @see #newBuilder(boolean)
211      *
212      * @return a new {@code Builder}
213      */
214     @Nonnull
215     public static Builder newBuilder() {
216         return newBuilder(true);
217     }
218 
219     /**
220      * Creates a new {@code ReportPlugin} builder instance using default values or not.
221      *
222      * @param withDefaults the boolean indicating whether default values should be used
223      * @return a new {@code Builder}
224      */
225     @Nonnull
226     public static Builder newBuilder(boolean withDefaults) {
227         return new Builder(withDefaults);
228     }
229 
230     /**
231      * Creates a new {@code ReportPlugin} builder instance using the specified object as a basis.
232      * Equivalent to {@code newBuilder(from, false)}.
233      *
234      * @param from the {@code ReportPlugin} instance to use as a basis
235      * @return a new {@code Builder}
236      */
237     @Nonnull
238     public static Builder newBuilder(ReportPlugin from) {
239         return newBuilder(from, false);
240     }
241 
242     /**
243      * Creates a new {@code ReportPlugin} builder instance using the specified object as a basis.
244      *
245      * @param from the {@code ReportPlugin} instance to use as a basis
246      * @param forceCopy the boolean indicating if a copy should be forced
247      * @return a new {@code Builder}
248      */
249     @Nonnull
250     public static Builder newBuilder(ReportPlugin from, boolean forceCopy) {
251         return new Builder(from, forceCopy);
252     }
253 
254     /**
255      * Builder class used to create ReportPlugin instances.
256      * @see #with()
257      * @see #newBuilder()
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      * Reset the {@code reportSetMap} field to {@code null}
377      */
378     public void flushReportSetMap()
379     {
380         this.reportSetMap = null;
381     }
382 
383     /**
384      * @return a Map of reportSets field with {@code ReportSet#getId()} as key
385      * @see ReportSet#getId()
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      * @return the key of the report plugin, ie {@code groupId:artifactId}
407      */
408     public String getKey()
409     {
410         return constructKey( getGroupId(), getArtifactId() );
411     }
412 
413     /**
414      * @param groupId The group ID of the plugin in the repository
415      * @param artifactId The artifact ID of the reporting plugin in the repository
416      * @return the key of the report plugin, ie {@code groupId:artifactId}
417      */
418     public static String constructKey( String groupId, String artifactId )
419     {
420         return groupId + ":" + artifactId;
421     }
422             
423           
424 }