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