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