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