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 InputLocation location;
53
54 final InputLocation nameLocation;
55
56 final InputLocation urlLocation;
57
58 final InputLocation distributionLocation;
59
60 final InputLocation commentsLocation;
61
62 final Map<Object, InputLocation> locations;
63
64
65
66
67
68 License(
69 String name,
70 String url,
71 String distribution,
72 String comments,
73 Map<Object, InputLocation> locations,
74 InputLocation location,
75 InputLocation nameLocation,
76 InputLocation urlLocation,
77 InputLocation distributionLocation,
78 InputLocation commentsLocation
79 )
80 {
81 this.name = name;
82 this.url = url;
83 this.distribution = distribution;
84 this.comments = comments;
85 this.locations = ImmutableCollections.copy( locations );
86 this.location = location;
87 this.nameLocation = nameLocation;
88 this.urlLocation = urlLocation;
89 this.distributionLocation = distributionLocation;
90 this.commentsLocation = commentsLocation;
91 }
92
93
94
95
96
97
98 public String getName()
99 {
100 return this.name;
101 }
102
103
104
105
106
107
108 public String getUrl()
109 {
110 return this.url;
111 }
112
113
114
115
116
117
118
119
120
121
122
123
124 public String getDistribution()
125 {
126 return this.distribution;
127 }
128
129
130
131
132
133
134 public String getComments()
135 {
136 return this.comments;
137 }
138
139
140
141
142 public InputLocation getLocation( Object key )
143 {
144 if ( key instanceof String )
145 {
146 switch ( ( String ) key )
147 {
148 case "":
149 return location;
150 case "name":
151 return nameLocation;
152 case "url":
153 return urlLocation;
154 case "distribution":
155 return distributionLocation;
156 case "comments":
157 return commentsLocation;
158 }
159 }
160 return locations != null ? locations.get( key ) : null;
161 }
162
163
164
165
166
167
168 @Nonnull
169 public Builder with()
170 {
171 return newBuilder( this );
172 }
173
174
175
176
177
178
179 @Nonnull
180 public License withName( String name )
181 {
182 return with().name( name ).build();
183 }
184
185
186
187
188
189
190 @Nonnull
191 public License withUrl( String url )
192 {
193 return with().url( url ).build();
194 }
195
196
197
198
199
200
201 @Nonnull
202 public License withDistribution( String distribution )
203 {
204 return with().distribution( distribution ).build();
205 }
206
207
208
209
210
211
212 @Nonnull
213 public License withComments( String comments )
214 {
215 return with().comments( comments ).build();
216 }
217
218
219
220
221
222
223
224
225 @Nonnull
226 public static License newInstance()
227 {
228 return newInstance( true );
229 }
230
231
232
233
234
235
236
237
238 @Nonnull
239 public static License newInstance( boolean withDefaults )
240 {
241 return newBuilder( withDefaults ).build();
242 }
243
244
245
246
247
248
249
250
251 @Nonnull
252 public static Builder newBuilder()
253 {
254 return newBuilder( true );
255 }
256
257
258
259
260
261
262
263 @Nonnull
264 public static Builder newBuilder( boolean withDefaults )
265 {
266 return new Builder( withDefaults );
267 }
268
269
270
271
272
273
274
275
276 @Nonnull
277 public static Builder newBuilder( License from )
278 {
279 return newBuilder( from, false );
280 }
281
282
283
284
285
286
287
288
289 @Nonnull
290 public static Builder newBuilder( License from, boolean forceCopy )
291 {
292 return new Builder( from, forceCopy );
293 }
294
295
296
297
298
299
300 @NotThreadSafe
301 public static class Builder
302 {
303 License base;
304 String name;
305 String url;
306 String distribution;
307 String comments;
308 Map<Object, InputLocation> locations;
309
310 Builder( boolean withDefaults )
311 {
312 if ( withDefaults )
313 {
314 }
315 }
316
317 Builder( License base, boolean forceCopy )
318 {
319 if ( forceCopy )
320 {
321 this.name = base.name;
322 this.url = base.url;
323 this.distribution = base.distribution;
324 this.comments = base.comments;
325 }
326 else
327 {
328 this.base = base;
329 }
330 }
331
332 @Nonnull
333 public Builder name( String name )
334 {
335 this.name = name;
336 return this;
337 }
338
339 @Nonnull
340 public Builder url( String url )
341 {
342 this.url = url;
343 return this;
344 }
345
346 @Nonnull
347 public Builder distribution( String distribution )
348 {
349 this.distribution = distribution;
350 return this;
351 }
352
353 @Nonnull
354 public Builder comments( String comments )
355 {
356 this.comments = comments;
357 return this;
358 }
359
360
361 @Nonnull
362 public Builder location( Object key, InputLocation location )
363 {
364 if ( location != null )
365 {
366 if ( this.locations == null )
367 {
368 this.locations = new HashMap<>();
369 }
370 this.locations.put( key, location );
371 }
372 return this;
373 }
374
375 @Nonnull
376 public License build()
377 {
378 if ( base != null
379 && ( name == null || name == base.name )
380 && ( url == null || url == base.url )
381 && ( distribution == null || distribution == base.distribution )
382 && ( comments == null || comments == base.comments )
383 )
384 {
385 return base;
386 }
387 Map<Object, InputLocation> locations = null;
388 InputLocation location = null;
389 InputLocation nameLocation = null;
390 InputLocation urlLocation = null;
391 InputLocation distributionLocation = null;
392 InputLocation commentsLocation = null;
393 if ( this.locations != null )
394 {
395 locations = this.locations;
396 location = locations.remove( "" );
397 nameLocation = locations.remove( "name" );
398 urlLocation = locations.remove( "url" );
399 distributionLocation = locations.remove( "distribution" );
400 commentsLocation = locations.remove( "comments" );
401 }
402 return new License(
403 name != null ? name : ( base != null ? base.name : null ),
404 url != null ? url : ( base != null ? base.url : null ),
405 distribution != null ? distribution : ( base != null ? base.distribution : null ),
406 comments != null ? comments : ( base != null ? base.comments : null ),
407 locations != null ? locations : ( base != null ? base.locations : null ),
408 location != null ? location : ( base != null ? base.location : null ),
409 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
410 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
411 distributionLocation != null ? distributionLocation : ( base != null ? base.distributionLocation : null ),
412 commentsLocation != null ? commentsLocation : ( base != null ? base.commentsLocation : null )
413 );
414 }
415 }
416
417
418
419
420
421
422 public String toString()
423 {
424 return "License {name=" + getName() + ", url=" + getUrl() + "}";
425 }
426
427
428 }