1
2
3
4 package org.apache.maven.api.model;
5
6 import java.io.Serializable;
7 import java.util.ArrayList;
8 import java.util.Collection;
9 import java.util.Collections;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13 import org.apache.maven.api.annotations.Experimental;
14 import org.apache.maven.api.annotations.Generated;
15 import org.apache.maven.api.annotations.Immutable;
16 import org.apache.maven.api.annotations.Nonnull;
17 import org.apache.maven.api.annotations.NotThreadSafe;
18 import org.apache.maven.api.annotations.ThreadSafe;
19
20
21
22
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class Reporting
26 implements Serializable, InputLocationTracker
27 {
28
29
30
31
32
33
34 final String excludeDefaults;
35
36
37
38
39 final String outputDirectory;
40
41
42
43 final List<ReportPlugin> plugins;
44
45 final InputLocation location;
46
47 final InputLocation excludeDefaultsLocation;
48
49 final InputLocation outputDirectoryLocation;
50
51 final InputLocation pluginsLocation;
52
53 final Map<Object, InputLocation> locations;
54
55
56
57
58
59 Reporting(
60 String excludeDefaults,
61 String outputDirectory,
62 Collection<ReportPlugin> plugins,
63 Map<Object, InputLocation> locations,
64 InputLocation location,
65 InputLocation excludeDefaultsLocation,
66 InputLocation outputDirectoryLocation,
67 InputLocation pluginsLocation
68 )
69 {
70 this.excludeDefaults = excludeDefaults;
71 this.outputDirectory = outputDirectory;
72 this.plugins = ImmutableCollections.copy( plugins );
73 this.locations = ImmutableCollections.copy( locations );
74 this.location = location;
75 this.excludeDefaultsLocation = excludeDefaultsLocation;
76 this.outputDirectoryLocation = outputDirectoryLocation;
77 this.pluginsLocation = pluginsLocation;
78 }
79
80
81
82
83
84
85
86
87
88 public String getExcludeDefaults()
89 {
90 return this.excludeDefaults;
91 }
92
93
94
95
96
97
98
99 public String getOutputDirectory()
100 {
101 return this.outputDirectory;
102 }
103
104
105
106
107
108
109 @Nonnull
110 public List<ReportPlugin> getPlugins()
111 {
112 return this.plugins;
113 }
114
115
116
117
118 public InputLocation getLocation( Object key )
119 {
120 if ( key instanceof String )
121 {
122 switch ( ( String ) key )
123 {
124 case "":
125 return location;
126 case "excludeDefaults":
127 return excludeDefaultsLocation;
128 case "outputDirectory":
129 return outputDirectoryLocation;
130 case "plugins":
131 return pluginsLocation;
132 }
133 }
134 return locations != null ? locations.get( key ) : null;
135 }
136
137
138
139
140
141
142 @Nonnull
143 public Builder with()
144 {
145 return newBuilder( this );
146 }
147
148
149
150
151
152
153 @Nonnull
154 public Reporting withExcludeDefaults( String excludeDefaults )
155 {
156 return with().excludeDefaults( excludeDefaults ).build();
157 }
158
159
160
161
162
163
164 @Nonnull
165 public Reporting withOutputDirectory( String outputDirectory )
166 {
167 return with().outputDirectory( outputDirectory ).build();
168 }
169
170
171
172
173
174
175 @Nonnull
176 public Reporting withPlugins( Collection<ReportPlugin> plugins )
177 {
178 return with().plugins( plugins ).build();
179 }
180
181
182
183
184
185
186
187
188 @Nonnull
189 public static Reporting newInstance()
190 {
191 return newInstance( true );
192 }
193
194
195
196
197
198
199
200
201 @Nonnull
202 public static Reporting newInstance( boolean withDefaults )
203 {
204 return newBuilder( withDefaults ).build();
205 }
206
207
208
209
210
211
212
213
214 @Nonnull
215 public static Builder newBuilder()
216 {
217 return newBuilder( true );
218 }
219
220
221
222
223
224
225
226 @Nonnull
227 public static Builder newBuilder( boolean withDefaults )
228 {
229 return new Builder( withDefaults );
230 }
231
232
233
234
235
236
237
238
239 @Nonnull
240 public static Builder newBuilder( Reporting from )
241 {
242 return newBuilder( from, false );
243 }
244
245
246
247
248
249
250
251
252 @Nonnull
253 public static Builder newBuilder( Reporting from, boolean forceCopy )
254 {
255 return new Builder( from, forceCopy );
256 }
257
258
259
260
261
262
263 @NotThreadSafe
264 public static class Builder
265 {
266 Reporting base;
267 String excludeDefaults;
268 String outputDirectory;
269 Collection<ReportPlugin> plugins;
270 Map<Object, InputLocation> locations;
271
272 Builder( boolean withDefaults )
273 {
274 if ( withDefaults )
275 {
276 }
277 }
278
279 Builder( Reporting base, boolean forceCopy )
280 {
281 if ( forceCopy )
282 {
283 this.excludeDefaults = base.excludeDefaults;
284 this.outputDirectory = base.outputDirectory;
285 this.plugins = base.plugins;
286 }
287 else
288 {
289 this.base = base;
290 }
291 }
292
293 @Nonnull
294 public Builder excludeDefaults( String excludeDefaults )
295 {
296 this.excludeDefaults = excludeDefaults;
297 return this;
298 }
299
300 @Nonnull
301 public Builder outputDirectory( String outputDirectory )
302 {
303 this.outputDirectory = outputDirectory;
304 return this;
305 }
306
307 @Nonnull
308 public Builder plugins( Collection<ReportPlugin> plugins )
309 {
310 this.plugins = plugins;
311 return this;
312 }
313
314
315 @Nonnull
316 public Builder location( Object key, InputLocation location )
317 {
318 if ( location != null )
319 {
320 if ( this.locations == null )
321 {
322 this.locations = new HashMap<>();
323 }
324 this.locations.put( key, location );
325 }
326 return this;
327 }
328
329 @Nonnull
330 public Reporting build()
331 {
332 if ( base != null
333 && ( excludeDefaults == null || excludeDefaults == base.excludeDefaults )
334 && ( outputDirectory == null || outputDirectory == base.outputDirectory )
335 && ( plugins == null || plugins == base.plugins )
336 )
337 {
338 return base;
339 }
340 Map<Object, InputLocation> locations = null;
341 InputLocation location = null;
342 InputLocation excludeDefaultsLocation = null;
343 InputLocation outputDirectoryLocation = null;
344 InputLocation pluginsLocation = null;
345 if ( this.locations != null )
346 {
347 locations = this.locations;
348 location = locations.remove( "" );
349 excludeDefaultsLocation = locations.remove( "excludeDefaults" );
350 outputDirectoryLocation = locations.remove( "outputDirectory" );
351 pluginsLocation = locations.remove( "plugins" );
352 }
353 return new Reporting(
354 excludeDefaults != null ? excludeDefaults : ( base != null ? base.excludeDefaults : null ),
355 outputDirectory != null ? outputDirectory : ( base != null ? base.outputDirectory : null ),
356 plugins != null ? plugins : ( base != null ? base.plugins : null ),
357 locations != null ? locations : ( base != null ? base.locations : null ),
358 location != null ? location : ( base != null ? base.location : null ),
359 excludeDefaultsLocation != null ? excludeDefaultsLocation : ( base != null ? base.excludeDefaultsLocation : null ),
360 outputDirectoryLocation != null ? outputDirectoryLocation : ( base != null ? base.outputDirectoryLocation : null ),
361 pluginsLocation != null ? pluginsLocation : ( base != null ? base.pluginsLocation : null )
362 );
363 }
364 }
365
366
367
368 public boolean isExcludeDefaults()
369 {
370 return ( getExcludeDefaults() != null ) ? Boolean.parseBoolean( getExcludeDefaults() ) : false;
371 }
372
373
374
375 }