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  
26  /**
27   * Section for management of reports and their configuration.
28   */
29  @Experimental
30  @Generated @ThreadSafe @Immutable
31  public class Reporting
32      implements Serializable, InputLocationTracker
33  {
34      /**
35       * If true, then the default reports are not included in the site generation.
36       * This includes the reports in the "Project Info" menu. Note: While the type
37       * of this field is {@code String} for technical reasons, the semantic type is actually
38       * {@code Boolean}. Default value is {@code false}.
39       */
40      final String excludeDefaults;
41      /**
42       * Where to store all the generated reports. The default is
43       * {@code ${project.build.directory}/site}.
44       */
45      final String outputDirectory;
46      /**
47       * The reporting plugins to use and their configuration.
48       */
49      final List<ReportPlugin> plugins;
50      /** Locations */
51      final Map<Object, InputLocation> locations;
52      /** Location tracking */
53      final InputLocation importedFrom;
54  
55      /**
56        * Constructor for this class, to be called from its subclasses and {@link Builder}.
57        * @see Builder#build()
58        */
59      protected Reporting(Builder builder) {
60          this.excludeDefaults = builder.excludeDefaults != null ? builder.excludeDefaults : (builder.base != null ? builder.base.excludeDefaults : null);
61          this.outputDirectory = builder.outputDirectory != null ? builder.outputDirectory : (builder.base != null ? builder.base.outputDirectory : null);
62          this.plugins = ImmutableCollections.copy(builder.plugins != null ? builder.plugins : (builder.base != null ? builder.base.plugins : null));
63          this.locations = builder.computeLocations();
64          this.importedFrom = builder.importedFrom;
65      }
66  
67      /**
68       * If true, then the default reports are not included in the site generation.
69       * This includes the reports in the "Project Info" menu. Note: While the type
70       * of this field is {@code String} for technical reasons, the semantic type is actually
71       * {@code Boolean}. Default value is {@code false}.
72       *
73       * @return a {@code String}
74       */
75      public String getExcludeDefaults() {
76          return this.excludeDefaults;
77      }
78  
79      /**
80       * Where to store all the generated reports. The default is
81       * {@code ${project.build.directory}/site}.
82       *
83       * @return a {@code String}
84       */
85      public String getOutputDirectory() {
86          return this.outputDirectory;
87      }
88  
89      /**
90       * The reporting plugins to use and their configuration.
91       *
92       * @return a {@code List<ReportPlugin>}
93       */
94      @Nonnull
95      public List<ReportPlugin> getPlugins() {
96          return this.plugins;
97      }
98  
99      /**
100      * Gets the location of the specified field in the input source.
101      *
102      * @param key the key of the field, must not be {@code null}
103      * @return the location of the field in the input source or {@code null} if unknown
104      * @throws NullPointerException if {@code key} is {@code null}
105      */
106     public InputLocation getLocation(Object key) {
107         Objects.requireNonNull(key, "key");
108         return locations.get(key);
109     }
110 
111     /**
112      * Gets the keys of the locations of the input source.
113      */
114     public Set<Object> getLocationKeys() {
115         return locations.keySet();
116     }
117 
118     protected Stream<Object> getLocationKeyStream() {
119         return locations.keySet().stream();
120     }
121 
122     /**
123      * Gets the input location that caused this model to be read.
124      */
125     public InputLocation getImportedFrom() {
126         return importedFrom;
127     }
128 
129     /**
130      * Creates a new builder with this object as the basis.
131      *
132      * @return a {@code Builder}
133      */
134     @Nonnull
135     public Builder with() {
136         return newBuilder(this);
137     }
138     /**
139      * Creates a new {@code Reporting} instance using the specified excludeDefaults.
140      *
141      * @param excludeDefaults the new {@code String} to use
142      * @return a {@code Reporting} with the specified excludeDefaults
143      */
144     @Nonnull
145     public Reporting withExcludeDefaults(String excludeDefaults) {
146         return newBuilder(this, true).excludeDefaults(excludeDefaults).build();
147     }
148     /**
149      * Creates a new {@code Reporting} instance using the specified outputDirectory.
150      *
151      * @param outputDirectory the new {@code String} to use
152      * @return a {@code Reporting} with the specified outputDirectory
153      */
154     @Nonnull
155     public Reporting withOutputDirectory(String outputDirectory) {
156         return newBuilder(this, true).outputDirectory(outputDirectory).build();
157     }
158     /**
159      * Creates a new {@code Reporting} instance using the specified plugins.
160      *
161      * @param plugins the new {@code Collection<ReportPlugin>} to use
162      * @return a {@code Reporting} with the specified plugins
163      */
164     @Nonnull
165     public Reporting withPlugins(Collection<ReportPlugin> plugins) {
166         return newBuilder(this, true).plugins(plugins).build();
167     }
168 
169     /**
170      * Creates a new {@code Reporting} instance.
171      * Equivalent to {@code newInstance(true)}.
172      * @see #newInstance(boolean)
173      *
174      * @return a new {@code Reporting}
175      */
176     @Nonnull
177     public static Reporting newInstance() {
178         return newInstance(true);
179     }
180 
181     /**
182      * Creates a new {@code Reporting} instance using default values or not.
183      * Equivalent to {@code newBuilder(withDefaults).build()}.
184      *
185      * @param withDefaults the boolean indicating whether default values should be used
186      * @return a new {@code Reporting}
187      */
188     @Nonnull
189     public static Reporting newInstance(boolean withDefaults) {
190         return newBuilder(withDefaults).build();
191     }
192 
193     /**
194      * Creates a new {@code Reporting} builder instance.
195      * Equivalent to {@code newBuilder(true)}.
196      * @see #newBuilder(boolean)
197      *
198      * @return a new {@code Builder}
199      */
200     @Nonnull
201     public static Builder newBuilder() {
202         return newBuilder(true);
203     }
204 
205     /**
206      * Creates a new {@code Reporting} builder instance using default values or not.
207      *
208      * @param withDefaults the boolean indicating whether default values should be used
209      * @return a new {@code Builder}
210      */
211     @Nonnull
212     public static Builder newBuilder(boolean withDefaults) {
213         return new Builder(withDefaults);
214     }
215 
216     /**
217      * Creates a new {@code Reporting} builder instance using the specified object as a basis.
218      * Equivalent to {@code newBuilder(from, false)}.
219      *
220      * @param from the {@code Reporting} instance to use as a basis
221      * @return a new {@code Builder}
222      */
223     @Nonnull
224     public static Builder newBuilder(Reporting from) {
225         return newBuilder(from, false);
226     }
227 
228     /**
229      * Creates a new {@code Reporting} builder instance using the specified object as a basis.
230      *
231      * @param from the {@code Reporting} instance to use as a basis
232      * @param forceCopy the boolean indicating if a copy should be forced
233      * @return a new {@code Builder}
234      */
235     @Nonnull
236     public static Builder newBuilder(Reporting from, boolean forceCopy) {
237         return new Builder(from, forceCopy);
238     }
239 
240     /**
241      * Builder class used to create Reporting instances.
242      * @see #with()
243      * @see #newBuilder()
244      */
245     @NotThreadSafe
246     public static class Builder
247     {
248         Reporting base;
249         String excludeDefaults;
250         String outputDirectory;
251         Collection<ReportPlugin> plugins;
252         Map<Object, InputLocation> locations;
253         InputLocation importedFrom;
254 
255         protected Builder(boolean withDefaults) {
256             if (withDefaults) {
257             }
258         }
259 
260         protected Builder(Reporting base, boolean forceCopy) {
261             if (forceCopy) {
262                 this.excludeDefaults = base.excludeDefaults;
263                 this.outputDirectory = base.outputDirectory;
264                 this.plugins = base.plugins;
265                 this.locations = base.locations;
266                 this.importedFrom = base.importedFrom;
267             } else {
268                 this.base = base;
269             }
270         }
271 
272         @Nonnull
273         public Builder excludeDefaults(String excludeDefaults) {
274             this.excludeDefaults = excludeDefaults;
275             return this;
276         }
277 
278         @Nonnull
279         public Builder outputDirectory(String outputDirectory) {
280             this.outputDirectory = outputDirectory;
281             return this;
282         }
283 
284         @Nonnull
285         public Builder plugins(Collection<ReportPlugin> plugins) {
286             this.plugins = plugins;
287             return this;
288         }
289 
290 
291         @Nonnull
292         public Builder location(Object key, InputLocation location) {
293             if (location != null) {
294                 if (!(this.locations instanceof HashMap)) {
295                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
296                 }
297                 this.locations.put(key, location);
298             }
299             return this;
300         }
301 
302         @Nonnull
303         public Builder importedFrom(InputLocation importedFrom) {
304             this.importedFrom = importedFrom;
305             return this;
306         }
307 
308         @Nonnull
309         public Reporting build() {
310             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
311             if (base != null
312                     && (excludeDefaults == null || excludeDefaults == base.excludeDefaults)
313                     && (outputDirectory == null || outputDirectory == base.outputDirectory)
314                     && (plugins == null || plugins == base.plugins)
315             ) {
316                 return base;
317             }
318             return new Reporting(this);
319         }
320 
321         Map<Object, InputLocation> computeLocations() {
322             Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
323             Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
324             if (newlocs.isEmpty()) {
325                 return Map.copyOf(oldlocs);
326             }
327             if (oldlocs.isEmpty()) {
328                 return Map.copyOf(newlocs);
329             }
330             return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
331                     // Keep value from newlocs in case of duplicates
332                     .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
333         }
334     }
335 
336 
337             
338     public boolean isExcludeDefaults() {
339         return (getExcludeDefaults() != null) ? Boolean.parseBoolean(getExcludeDefaults()) : false;
340     }
341 
342             
343           
344 }