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