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