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 java.util.Set;
15  import org.apache.maven.api.annotations.Experimental;
16  import org.apache.maven.api.annotations.Generated;
17  import org.apache.maven.api.annotations.Immutable;
18  import org.apache.maven.api.annotations.Nonnull;
19  import org.apache.maven.api.annotations.NotThreadSafe;
20  import org.apache.maven.api.annotations.ThreadSafe;
21  import org.apache.maven.api.xml.XmlNode;
22  
23  /**
24   * The {@code <plugin>} element in {@code <reporting><plugins>} contains information required for a report plugin.
25   */
26  @Experimental
27  @Generated @ThreadSafe @Immutable
28  public class ReportPlugin
29      extends ConfigurationContainer
30      implements Serializable, InputLocationTracker
31  {
32      /**
33       * The group ID of the reporting plugin in the repository.
34       */
35      final String groupId;
36      /**
37       * The artifact ID of the reporting plugin in the repository.
38       */
39      final String artifactId;
40      /**
41       * The version of the reporting plugin to be used. Starting with Maven 3, if no version is defined explicitly,
42       * version is searched in {@code build/plugins} then in {@code build/pluginManagement}.
43       */
44      final String version;
45      /**
46       * Multiple specifications of a set of reports, each having (possibly) different
47       * configuration. This is the reporting parallel to an {@code execution} in the build.
48       */
49      final List<ReportSet> reportSets;
50      /** Locations (this potentially hides the same name field from the super class) */
51      final Map<Object, InputLocation> locations;
52  
53      /**
54        * Constructor for this class, to be called from its subclasses and {@link Builder}.
55        * @see Builder#build()
56        */
57      protected ReportPlugin(Builder builder) {
58          super(builder);
59          this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
60          this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
61          this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
62          this.reportSets = ImmutableCollections.copy(builder.reportSets != null ? builder.reportSets : (builder.base != null ? builder.base.reportSets : null));
63          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
64          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
65          Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
66          mutableLocations.put("groupId", newlocs.containsKey("groupId") ? newlocs.get("groupId") : oldlocs.get("groupId"));
67          mutableLocations.put("artifactId", newlocs.containsKey("artifactId") ? newlocs.get("artifactId") : oldlocs.get("artifactId"));
68          mutableLocations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
69          mutableLocations.put("reportSets", newlocs.containsKey("reportSets") ? newlocs.get("reportSets") : oldlocs.get("reportSets"));
70          this.locations = Collections.unmodifiableMap(mutableLocations);
71      }
72  
73      /**
74       * The group ID of the reporting plugin in the repository.
75       *
76       * @return a {@code String}
77       */
78      public String getGroupId() {
79          return this.groupId;
80      }
81  
82      /**
83       * The artifact ID of the reporting plugin in the repository.
84       *
85       * @return a {@code String}
86       */
87      public String getArtifactId() {
88          return this.artifactId;
89      }
90  
91      /**
92       * The version of the reporting plugin to be used. Starting with Maven 3, if no version is defined explicitly,
93       * version is searched in {@code build/plugins} then in {@code build/pluginManagement}.
94       *
95       * @return a {@code String}
96       */
97      public String getVersion() {
98          return this.version;
99      }
100 
101     /**
102      * Multiple specifications of a set of reports, each having (possibly) different
103      * configuration. This is the reporting parallel to an {@code execution} in the build.
104      *
105      * @return a {@code List<ReportSet>}
106      */
107     @Nonnull
108     public List<ReportSet> getReportSets() {
109         return this.reportSets;
110     }
111 
112     /**
113      * Gets the location of the specified field in the input source.
114      */
115     public InputLocation getLocation(Object key) {
116         return locations != null ? locations.get(key) : null;
117     }
118 
119     /**
120     * Gets the keys of the locations of the input source.
121     */
122     public Set<Object> getLocationKeys() {
123         return locations != null ? locations.keySet() : null;
124     }
125 
126     /**
127      * Creates a new builder with this object as the basis.
128      *
129      * @return a {@code Builder}
130      */
131     @Nonnull
132     public Builder with() {
133         return newBuilder(this);
134     }
135     /**
136      * Creates a new {@code ReportPlugin} instance using the specified inherited.
137      *
138      * @param inherited the new {@code String} to use
139      * @return a {@code ReportPlugin} with the specified inherited
140      */
141     @Nonnull
142     public ReportPlugin withInherited(String inherited) {
143         return newBuilder(this, true).inherited(inherited).build();
144     }
145     /**
146      * Creates a new {@code ReportPlugin} instance using the specified configuration.
147      *
148      * @param configuration the new {@code XmlNode} to use
149      * @return a {@code ReportPlugin} with the specified configuration
150      */
151     @Nonnull
152     public ReportPlugin withConfiguration(XmlNode configuration) {
153         return newBuilder(this, true).configuration(configuration).build();
154     }
155     /**
156      * Creates a new {@code ReportPlugin} instance using the specified groupId.
157      *
158      * @param groupId the new {@code String} to use
159      * @return a {@code ReportPlugin} with the specified groupId
160      */
161     @Nonnull
162     public ReportPlugin withGroupId(String groupId) {
163         return newBuilder(this, true).groupId(groupId).build();
164     }
165     /**
166      * Creates a new {@code ReportPlugin} instance using the specified artifactId.
167      *
168      * @param artifactId the new {@code String} to use
169      * @return a {@code ReportPlugin} with the specified artifactId
170      */
171     @Nonnull
172     public ReportPlugin withArtifactId(String artifactId) {
173         return newBuilder(this, true).artifactId(artifactId).build();
174     }
175     /**
176      * Creates a new {@code ReportPlugin} instance using the specified version.
177      *
178      * @param version the new {@code String} to use
179      * @return a {@code ReportPlugin} with the specified version
180      */
181     @Nonnull
182     public ReportPlugin withVersion(String version) {
183         return newBuilder(this, true).version(version).build();
184     }
185     /**
186      * Creates a new {@code ReportPlugin} instance using the specified reportSets.
187      *
188      * @param reportSets the new {@code Collection<ReportSet>} to use
189      * @return a {@code ReportPlugin} with the specified reportSets
190      */
191     @Nonnull
192     public ReportPlugin withReportSets(Collection<ReportSet> reportSets) {
193         return newBuilder(this, true).reportSets(reportSets).build();
194     }
195 
196     /**
197      * Creates a new {@code ReportPlugin} instance.
198      * Equivalent to {@code newInstance(true)}.
199      * @see #newInstance(boolean)
200      *
201      * @return a new {@code ReportPlugin}
202      */
203     @Nonnull
204     public static ReportPlugin newInstance() {
205         return newInstance(true);
206     }
207 
208     /**
209      * Creates a new {@code ReportPlugin} instance using default values or not.
210      * Equivalent to {@code newBuilder(withDefaults).build()}.
211      *
212      * @param withDefaults the boolean indicating whether default values should be used
213      * @return a new {@code ReportPlugin}
214      */
215     @Nonnull
216     public static ReportPlugin newInstance(boolean withDefaults) {
217         return newBuilder(withDefaults).build();
218     }
219 
220     /**
221      * Creates a new {@code ReportPlugin} builder instance.
222      * Equivalent to {@code newBuilder(true)}.
223      * @see #newBuilder(boolean)
224      *
225      * @return a new {@code Builder}
226      */
227     @Nonnull
228     public static Builder newBuilder() {
229         return newBuilder(true);
230     }
231 
232     /**
233      * Creates a new {@code ReportPlugin} builder instance using default values or not.
234      *
235      * @param withDefaults the boolean indicating whether default values should be used
236      * @return a new {@code Builder}
237      */
238     @Nonnull
239     public static Builder newBuilder(boolean withDefaults) {
240         return new Builder(withDefaults);
241     }
242 
243     /**
244      * Creates a new {@code ReportPlugin} builder instance using the specified object as a basis.
245      * Equivalent to {@code newBuilder(from, false)}.
246      *
247      * @param from the {@code ReportPlugin} instance to use as a basis
248      * @return a new {@code Builder}
249      */
250     @Nonnull
251     public static Builder newBuilder(ReportPlugin from) {
252         return newBuilder(from, false);
253     }
254 
255     /**
256      * Creates a new {@code ReportPlugin} builder instance using the specified object as a basis.
257      *
258      * @param from the {@code ReportPlugin} instance to use as a basis
259      * @param forceCopy the boolean indicating if a copy should be forced
260      * @return a new {@code Builder}
261      */
262     @Nonnull
263     public static Builder newBuilder(ReportPlugin from, boolean forceCopy) {
264         return new Builder(from, forceCopy);
265     }
266 
267     /**
268      * Builder class used to create ReportPlugin instances.
269      * @see #with()
270      * @see #newBuilder()
271      */
272     @NotThreadSafe
273     public static class Builder
274         extends ConfigurationContainer.Builder
275     {
276         ReportPlugin base;
277         String groupId;
278         String artifactId;
279         String version;
280         Collection<ReportSet> reportSets;
281 
282         protected Builder(boolean withDefaults) {
283             super(withDefaults);
284             if (withDefaults) {
285                 this.groupId = "org.apache.maven.plugins";
286             }
287         }
288 
289         protected Builder(ReportPlugin base, boolean forceCopy) {
290             super(base, forceCopy);
291             if (forceCopy) {
292                 this.groupId = base.groupId;
293                 this.artifactId = base.artifactId;
294                 this.version = base.version;
295                 this.reportSets = base.reportSets;
296                 this.locations = base.locations;
297                 this.importedFrom = base.importedFrom;
298             } else {
299                 this.base = base;
300             }
301         }
302 
303         @Nonnull
304         public Builder inherited(String inherited) {
305             this.inherited = inherited;
306             return this;
307         }
308 
309         @Nonnull
310         public Builder configuration(XmlNode configuration) {
311             this.configuration = configuration;
312             return this;
313         }
314 
315         @Nonnull
316         public Builder groupId(String groupId) {
317             this.groupId = groupId;
318             return this;
319         }
320 
321         @Nonnull
322         public Builder artifactId(String artifactId) {
323             this.artifactId = artifactId;
324             return this;
325         }
326 
327         @Nonnull
328         public Builder version(String version) {
329             this.version = version;
330             return this;
331         }
332 
333         @Nonnull
334         public Builder reportSets(Collection<ReportSet> reportSets) {
335             this.reportSets = reportSets;
336             return this;
337         }
338 
339 
340         @Nonnull
341         public Builder location(Object key, InputLocation location) {
342             if (location != null) {
343                 if (!(this.locations instanceof HashMap)) {
344                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
345                 }
346                 this.locations.put(key, location);
347             }
348             return this;
349         }
350 
351         @Nonnull
352         public Builder importedFrom(InputLocation importedFrom) {
353             this.importedFrom = importedFrom;
354             return this;
355         }
356 
357         @Nonnull
358         public ReportPlugin build() {
359             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
360             if (base != null
361                     && (inherited == null || inherited == base.inherited)
362                     && (configuration == null || configuration == base.configuration)
363                     && (groupId == null || groupId == base.groupId)
364                     && (artifactId == null || artifactId == base.artifactId)
365                     && (version == null || version == base.version)
366                     && (reportSets == null || reportSets == base.reportSets)
367             ) {
368                 return base;
369             }
370             return new ReportPlugin(this);
371         }
372     }
373 
374 
375             
376     private java.util.Map<String, ReportSet> reportSetMap = null;
377 
378     /**
379      * Reset the {@code reportSetMap} field to {@code null}
380      */
381     public void flushReportSetMap() {
382         this.reportSetMap = null;
383     }
384 
385     /**
386      * @return a Map of reportSets field with {@code ReportSet#getId()} as key
387      * @see ReportSet#getId()
388      */
389     public java.util.Map<String, ReportSet> getReportSetsAsMap() {
390         if (reportSetMap == null) {
391             reportSetMap = new java.util.LinkedHashMap<String, ReportSet>();
392             if (getReportSets() != null) {
393                 for (java.util.Iterator<ReportSet> i = getReportSets().iterator(); i.hasNext(); ) {
394                     ReportSet reportSet = (ReportSet) i.next();
395                     reportSetMap.put(reportSet.getId(), reportSet);
396                 }
397             }
398         }
399 
400         return reportSetMap;
401     }
402 
403     /**
404      * @return the key of the report plugin, ie {@code groupId:artifactId}
405      */
406     public String getKey() {
407         return constructKey(getGroupId(), getArtifactId());
408     }
409 
410     /**
411      * @param groupId The group ID of the plugin in the repository
412      * @param artifactId The artifact ID of the reporting plugin in the repository
413      * @return the key of the report plugin, ie {@code groupId:artifactId}
414      */
415     public static String constructKey(String groupId, String artifactId) {
416         return groupId + ":" + artifactId;
417     }
418             
419           
420 }