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