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