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