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     public InputLocation getLocation(Object key) {
103         return locations.get(key);
104     }
105 
106     /**
107      * Gets the keys of the locations of the input source.
108      */
109     public Set<Object> getLocationKeys() {
110         return locations.keySet();
111     }
112 
113     protected Stream<Object> getLocationKeyStream() {
114         return locations.keySet().stream();
115     }
116 
117     /**
118      * Gets the input location that caused this model to be read.
119      */
120     public InputLocation getImportedFrom()
121     {
122         return importedFrom;
123     }
124 
125     /**
126      * Creates a new builder with this object as the basis.
127      *
128      * @return a {@code Builder}
129      */
130     @Nonnull
131     public Builder with() {
132         return newBuilder(this);
133     }
134     /**
135      * Creates a new {@code Reporting} instance using the specified excludeDefaults.
136      *
137      * @param excludeDefaults the new {@code String} to use
138      * @return a {@code Reporting} with the specified excludeDefaults
139      */
140     @Nonnull
141     public Reporting withExcludeDefaults(String excludeDefaults) {
142         return newBuilder(this, true).excludeDefaults(excludeDefaults).build();
143     }
144     /**
145      * Creates a new {@code Reporting} instance using the specified outputDirectory.
146      *
147      * @param outputDirectory the new {@code String} to use
148      * @return a {@code Reporting} with the specified outputDirectory
149      */
150     @Nonnull
151     public Reporting withOutputDirectory(String outputDirectory) {
152         return newBuilder(this, true).outputDirectory(outputDirectory).build();
153     }
154     /**
155      * Creates a new {@code Reporting} instance using the specified plugins.
156      *
157      * @param plugins the new {@code Collection<ReportPlugin>} to use
158      * @return a {@code Reporting} with the specified plugins
159      */
160     @Nonnull
161     public Reporting withPlugins(Collection<ReportPlugin> plugins) {
162         return newBuilder(this, true).plugins(plugins).build();
163     }
164 
165     /**
166      * Creates a new {@code Reporting} instance.
167      * Equivalent to {@code newInstance(true)}.
168      * @see #newInstance(boolean)
169      *
170      * @return a new {@code Reporting}
171      */
172     @Nonnull
173     public static Reporting newInstance() {
174         return newInstance(true);
175     }
176 
177     /**
178      * Creates a new {@code Reporting} instance using default values or not.
179      * Equivalent to {@code newBuilder(withDefaults).build()}.
180      *
181      * @param withDefaults the boolean indicating whether default values should be used
182      * @return a new {@code Reporting}
183      */
184     @Nonnull
185     public static Reporting newInstance(boolean withDefaults) {
186         return newBuilder(withDefaults).build();
187     }
188 
189     /**
190      * Creates a new {@code Reporting} builder instance.
191      * Equivalent to {@code newBuilder(true)}.
192      * @see #newBuilder(boolean)
193      *
194      * @return a new {@code Builder}
195      */
196     @Nonnull
197     public static Builder newBuilder() {
198         return newBuilder(true);
199     }
200 
201     /**
202      * Creates a new {@code Reporting} builder instance using default values or not.
203      *
204      * @param withDefaults the boolean indicating whether default values should be used
205      * @return a new {@code Builder}
206      */
207     @Nonnull
208     public static Builder newBuilder(boolean withDefaults) {
209         return new Builder(withDefaults);
210     }
211 
212     /**
213      * Creates a new {@code Reporting} builder instance using the specified object as a basis.
214      * Equivalent to {@code newBuilder(from, false)}.
215      *
216      * @param from the {@code Reporting} instance to use as a basis
217      * @return a new {@code Builder}
218      */
219     @Nonnull
220     public static Builder newBuilder(Reporting from) {
221         return newBuilder(from, false);
222     }
223 
224     /**
225      * Creates a new {@code Reporting} builder instance using the specified object as a basis.
226      *
227      * @param from the {@code Reporting} instance to use as a basis
228      * @param forceCopy the boolean indicating if a copy should be forced
229      * @return a new {@code Builder}
230      */
231     @Nonnull
232     public static Builder newBuilder(Reporting from, boolean forceCopy) {
233         return new Builder(from, forceCopy);
234     }
235 
236     /**
237      * Builder class used to create Reporting instances.
238      * @see #with()
239      * @see #newBuilder()
240      */
241     @NotThreadSafe
242     public static class Builder
243     {
244         Reporting base;
245         String excludeDefaults;
246         String outputDirectory;
247         Collection<ReportPlugin> plugins;
248         Map<Object, InputLocation> locations;
249         InputLocation importedFrom;
250 
251         protected Builder(boolean withDefaults) {
252             if (withDefaults) {
253             }
254         }
255 
256         protected Builder(Reporting base, boolean forceCopy) {
257             if (forceCopy) {
258                 this.excludeDefaults = base.excludeDefaults;
259                 this.outputDirectory = base.outputDirectory;
260                 this.plugins = base.plugins;
261                 this.locations = base.locations;
262                 this.importedFrom = base.importedFrom;
263             } else {
264                 this.base = base;
265             }
266         }
267 
268         @Nonnull
269         public Builder excludeDefaults(String excludeDefaults) {
270             this.excludeDefaults = excludeDefaults;
271             return this;
272         }
273 
274         @Nonnull
275         public Builder outputDirectory(String outputDirectory) {
276             this.outputDirectory = outputDirectory;
277             return this;
278         }
279 
280         @Nonnull
281         public Builder plugins(Collection<ReportPlugin> plugins) {
282             this.plugins = plugins;
283             return this;
284         }
285 
286 
287         @Nonnull
288         public Builder location(Object key, InputLocation location) {
289             if (location != null) {
290                 if (!(this.locations instanceof HashMap)) {
291                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
292                 }
293                 this.locations.put(key, location);
294             }
295             return this;
296         }
297 
298         @Nonnull
299         public Builder importedFrom(InputLocation importedFrom) {
300             this.importedFrom = importedFrom;
301             return this;
302         }
303 
304         @Nonnull
305         public Reporting build() {
306             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
307             if (base != null
308                     && (excludeDefaults == null || excludeDefaults == base.excludeDefaults)
309                     && (outputDirectory == null || outputDirectory == base.outputDirectory)
310                     && (plugins == null || plugins == base.plugins)
311             ) {
312                 return base;
313             }
314             return new Reporting(this);
315         }
316 
317         Map<Object, InputLocation> computeLocations() {
318             Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
319             Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
320             if (newlocs.isEmpty()) {
321                 return Map.copyOf(oldlocs);
322             }
323             if (oldlocs.isEmpty()) {
324                 return Map.copyOf(newlocs);
325             }
326             return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
327                     // Keep value from newlocs in case of duplicates
328                     .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
329         }
330     }
331 
332 
333             
334     public boolean isExcludeDefaults() {
335         return (getExcludeDefaults() != null) ? Boolean.parseBoolean(getExcludeDefaults()) : false;
336     }
337 
338             
339           
340 }