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