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 Map<Object, InputLocation> locations;
47
48
49
50
51
52 Reporting(
53 String excludeDefaults,
54 String outputDirectory,
55 Collection<ReportPlugin> plugins,
56 Map<Object, InputLocation> locations
57 ) {
58 this.excludeDefaults = excludeDefaults;
59 this.outputDirectory = outputDirectory;
60 this.plugins = ImmutableCollections.copy(plugins);
61 this.locations = ImmutableCollections.copy(locations);
62 }
63
64
65
66
67
68
69
70
71
72 public String getExcludeDefaults() {
73 return this.excludeDefaults;
74 }
75
76
77
78
79
80
81
82 public String getOutputDirectory() {
83 return this.outputDirectory;
84 }
85
86
87
88
89
90
91 @Nonnull
92 public List<ReportPlugin> getPlugins() {
93 return this.plugins;
94 }
95
96
97
98
99 public InputLocation getLocation(Object key) {
100 return locations != null ? locations.get(key) : null;
101 }
102
103
104
105
106
107
108 @Nonnull
109 public Builder with() {
110 return newBuilder(this);
111 }
112
113
114
115
116
117
118 @Nonnull
119 public Reporting withExcludeDefaults(String excludeDefaults) {
120 return newBuilder(this, true).excludeDefaults(excludeDefaults).build();
121 }
122
123
124
125
126
127
128 @Nonnull
129 public Reporting withOutputDirectory(String outputDirectory) {
130 return newBuilder(this, true).outputDirectory(outputDirectory).build();
131 }
132
133
134
135
136
137
138 @Nonnull
139 public Reporting withPlugins(Collection<ReportPlugin> plugins) {
140 return newBuilder(this, true).plugins(plugins).build();
141 }
142
143
144
145
146
147
148
149
150 @Nonnull
151 public static Reporting newInstance() {
152 return newInstance(true);
153 }
154
155
156
157
158
159
160
161
162 @Nonnull
163 public static Reporting newInstance(boolean withDefaults) {
164 return newBuilder(withDefaults).build();
165 }
166
167
168
169
170
171
172
173
174 @Nonnull
175 public static Builder newBuilder() {
176 return newBuilder(true);
177 }
178
179
180
181
182
183
184
185 @Nonnull
186 public static Builder newBuilder(boolean withDefaults) {
187 return new Builder(withDefaults);
188 }
189
190
191
192
193
194
195
196
197 @Nonnull
198 public static Builder newBuilder(Reporting from) {
199 return newBuilder(from, false);
200 }
201
202
203
204
205
206
207
208
209 @Nonnull
210 public static Builder newBuilder(Reporting from, boolean forceCopy) {
211 return new Builder(from, forceCopy);
212 }
213
214
215
216
217
218
219 @NotThreadSafe
220 public static class Builder
221 {
222 Reporting base;
223 String excludeDefaults;
224 String outputDirectory;
225 Collection<ReportPlugin> plugins;
226 Map<Object, InputLocation> locations;
227
228 Builder(boolean withDefaults) {
229 if (withDefaults) {
230 }
231 }
232
233 Builder(Reporting base, boolean forceCopy) {
234 if (forceCopy) {
235 this.excludeDefaults = base.excludeDefaults;
236 this.outputDirectory = base.outputDirectory;
237 this.plugins = base.plugins;
238 this.locations = base.locations;
239 } else {
240 this.base = base;
241 }
242 }
243
244 @Nonnull
245 public Builder excludeDefaults(String excludeDefaults) {
246 this.excludeDefaults = excludeDefaults;
247 return this;
248 }
249
250 @Nonnull
251 public Builder outputDirectory(String outputDirectory) {
252 this.outputDirectory = outputDirectory;
253 return this;
254 }
255
256 @Nonnull
257 public Builder plugins(Collection<ReportPlugin> plugins) {
258 this.plugins = plugins;
259 return this;
260 }
261
262
263 @Nonnull
264 public Builder location(Object key, InputLocation location) {
265 if (location != null) {
266 if (!(this.locations instanceof HashMap)) {
267 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
268 }
269 this.locations.put(key, location);
270 }
271 return this;
272 }
273
274 @Nonnull
275 public Reporting build() {
276 if (base != null
277 && (excludeDefaults == null || excludeDefaults == base.excludeDefaults)
278 && (outputDirectory == null || outputDirectory == base.outputDirectory)
279 && (plugins == null || plugins == base.plugins)
280 ) {
281 return base;
282 }
283 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
284 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
285 Map<Object, InputLocation> locations = new HashMap<>();
286 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
287 locations.put("excludeDefaults", newlocs.containsKey("excludeDefaults") ? newlocs.get("excludeDefaults") : oldlocs.get("excludeDefaults"));
288 locations.put("outputDirectory", newlocs.containsKey("outputDirectory") ? newlocs.get("outputDirectory") : oldlocs.get("outputDirectory"));
289 locations.put("plugins", newlocs.containsKey("plugins") ? newlocs.get("plugins") : oldlocs.get("plugins"));
290 return new Reporting(
291 excludeDefaults != null ? excludeDefaults : (base != null ? base.excludeDefaults : null),
292 outputDirectory != null ? outputDirectory : (base != null ? base.outputDirectory : null),
293 plugins != null ? plugins : (base != null ? base.plugins : null),
294 locations
295 );
296 }
297 }
298
299
300
301 public boolean isExcludeDefaults()
302 {
303 return ( getExcludeDefaults() != null ) ? Boolean.parseBoolean( getExcludeDefaults() ) : false;
304 }
305
306
307
308 }