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 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
28
29 @Experimental
30 @Generated @ThreadSafe @Immutable
31 public class Reporting
32 implements Serializable, InputLocationTracker
33 {
34
35
36
37
38
39
40 final String excludeDefaults;
41
42
43
44
45 final String outputDirectory;
46
47
48
49 final List<ReportPlugin> plugins;
50
51 final Map<Object, InputLocation> locations;
52
53 final InputLocation importedFrom;
54
55
56
57
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
69
70
71
72
73
74
75 public String getExcludeDefaults() {
76 return this.excludeDefaults;
77 }
78
79
80
81
82
83
84
85 public String getOutputDirectory() {
86 return this.outputDirectory;
87 }
88
89
90
91
92
93
94 @Nonnull
95 public List<ReportPlugin> getPlugins() {
96 return this.plugins;
97 }
98
99
100
101
102 public InputLocation getLocation(Object key) {
103 return locations.get(key);
104 }
105
106
107
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
119
120 public InputLocation getImportedFrom() {
121 return importedFrom;
122 }
123
124
125
126
127
128
129 @Nonnull
130 public Builder with() {
131 return newBuilder(this);
132 }
133
134
135
136
137
138
139 @Nonnull
140 public Reporting withExcludeDefaults(String excludeDefaults) {
141 return newBuilder(this, true).excludeDefaults(excludeDefaults).build();
142 }
143
144
145
146
147
148
149 @Nonnull
150 public Reporting withOutputDirectory(String outputDirectory) {
151 return newBuilder(this, true).outputDirectory(outputDirectory).build();
152 }
153
154
155
156
157
158
159 @Nonnull
160 public Reporting withPlugins(Collection<ReportPlugin> plugins) {
161 return newBuilder(this, true).plugins(plugins).build();
162 }
163
164
165
166
167
168
169
170
171 @Nonnull
172 public static Reporting newInstance() {
173 return newInstance(true);
174 }
175
176
177
178
179
180
181
182
183 @Nonnull
184 public static Reporting newInstance(boolean withDefaults) {
185 return newBuilder(withDefaults).build();
186 }
187
188
189
190
191
192
193
194
195 @Nonnull
196 public static Builder newBuilder() {
197 return newBuilder(true);
198 }
199
200
201
202
203
204
205
206 @Nonnull
207 public static Builder newBuilder(boolean withDefaults) {
208 return new Builder(withDefaults);
209 }
210
211
212
213
214
215
216
217
218 @Nonnull
219 public static Builder newBuilder(Reporting from) {
220 return newBuilder(from, false);
221 }
222
223
224
225
226
227
228
229
230 @Nonnull
231 public static Builder newBuilder(Reporting from, boolean forceCopy) {
232 return new Builder(from, forceCopy);
233 }
234
235
236
237
238
239
240 @NotThreadSafe
241 public static class Builder
242 {
243 Reporting base;
244 String excludeDefaults;
245 String outputDirectory;
246 Collection<ReportPlugin> plugins;
247 Map<Object, InputLocation> locations;
248 InputLocation importedFrom;
249
250 protected Builder(boolean withDefaults) {
251 if (withDefaults) {
252 }
253 }
254
255 protected Builder(Reporting base, boolean forceCopy) {
256 if (forceCopy) {
257 this.excludeDefaults = base.excludeDefaults;
258 this.outputDirectory = base.outputDirectory;
259 this.plugins = base.plugins;
260 this.locations = base.locations;
261 this.importedFrom = base.importedFrom;
262 } else {
263 this.base = base;
264 }
265 }
266
267 @Nonnull
268 public Builder excludeDefaults(String excludeDefaults) {
269 this.excludeDefaults = excludeDefaults;
270 return this;
271 }
272
273 @Nonnull
274 public Builder outputDirectory(String outputDirectory) {
275 this.outputDirectory = outputDirectory;
276 return this;
277 }
278
279 @Nonnull
280 public Builder plugins(Collection<ReportPlugin> plugins) {
281 this.plugins = plugins;
282 return this;
283 }
284
285
286 @Nonnull
287 public Builder location(Object key, InputLocation location) {
288 if (location != null) {
289 if (!(this.locations instanceof HashMap)) {
290 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
291 }
292 this.locations.put(key, location);
293 }
294 return this;
295 }
296
297 @Nonnull
298 public Builder importedFrom(InputLocation importedFrom) {
299 this.importedFrom = importedFrom;
300 return this;
301 }
302
303 @Nonnull
304 public Reporting build() {
305
306 if (base != null
307 && (excludeDefaults == null || excludeDefaults == base.excludeDefaults)
308 && (outputDirectory == null || outputDirectory == base.outputDirectory)
309 && (plugins == null || plugins == base.plugins)
310 ) {
311 return base;
312 }
313 return new Reporting(this);
314 }
315
316 Map<Object, InputLocation> computeLocations() {
317 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
318 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
319 if (newlocs.isEmpty()) {
320 return Map.copyOf(oldlocs);
321 }
322 if (oldlocs.isEmpty()) {
323 return Map.copyOf(newlocs);
324 }
325 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
326
327 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
328 }
329 }
330
331
332
333 public boolean isExcludeDefaults() {
334 return (getExcludeDefaults() != null) ? Boolean.parseBoolean(getExcludeDefaults()) : false;
335 }
336
337
338
339 }