1 // =================== DO NOT EDIT THIS FILE ====================
2 // Generated by Maven, any modifications will be overwritten.
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 * This element describes all of the classpath resources associated with a project
22 * or unit tests.
23 */
24 @Experimental
25 @Generated @ThreadSafe @Immutable
26 public class Resource
27 extends FileSet
28 implements Serializable, InputLocationTracker
29 {
30 /**
31 * Describe the resource target path. The path is relative to the target/classes
32 * directory (i.e. {@code ${project.build.outputDirectory}}).
33 * For example, if you want that resource to appear in a specific package
34 * ({@code org.apache.maven.messages}), you must specify this
35 * element with this value: {@code org/apache/maven/messages}.
36 * This is not required if you simply put the resources in that directory
37 * structure at the source, however.
38 */
39 final String targetPath;
40 /**
41 * Whether resources are filtered to replace tokens with parameterised values or not.
42 * The values are taken from the {@code properties} element and from the
43 * properties in the files listed in the {@code filters} element. Note: While the type
44 * of this field is {@code String} for technical reasons, the semantic type is actually
45 * {@code Boolean}. Default value is {@code false}.
46 */
47 final String filtering;
48 /**
49 * FOR INTERNAL USE ONLY. This is a unique identifier assigned to each
50 * resource to allow Maven to merge changes to this resource that take
51 * place during the execution of a plugin. This field must be managed
52 * by the generated parser and formatter classes in order to allow it
53 * to survive model interpolation.
54 */
55 final String mergeId;
56 /** Location of the xml element for the field targetPath. */
57 final InputLocation targetPathLocation;
58 /** Location of the xml element for the field filtering. */
59 final InputLocation filteringLocation;
60 /** Location of the xml element for the field mergeId. */
61 final InputLocation mergeIdLocation;
62
63 /**
64 * Constructor for this class, package protected.
65 * @see Builder#build()
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 * Describe the resource target path. The path is relative to the target/classes
104 * directory (i.e. {@code ${project.build.outputDirectory}}).
105 * For example, if you want that resource to appear in a specific package
106 * ({@code org.apache.maven.messages}), you must specify this
107 * element with this value: {@code org/apache/maven/messages}.
108 * This is not required if you simply put the resources in that directory
109 * structure at the source, however.
110 *
111 * @return a {@code String}
112 */
113 public String getTargetPath()
114 {
115 return this.targetPath;
116 }
117
118 /**
119 * Whether resources are filtered to replace tokens with parameterised values or not.
120 * The values are taken from the {@code properties} element and from the
121 * properties in the files listed in the {@code filters} element. Note: While the type
122 * of this field is {@code String} for technical reasons, the semantic type is actually
123 * {@code Boolean}. Default value is {@code false}.
124 *
125 * @return a {@code String}
126 */
127 public String getFiltering()
128 {
129 return this.filtering;
130 }
131
132 /**
133 * FOR INTERNAL USE ONLY. This is a unique identifier assigned to each
134 * resource to allow Maven to merge changes to this resource that take
135 * place during the execution of a plugin. This field must be managed
136 * by the generated parser and formatter classes in order to allow it
137 * to survive model interpolation.
138 *
139 * @return a {@code String}
140 */
141 public String getMergeId()
142 {
143 return this.mergeId;
144 }
145
146 /**
147 * Gets the location of the specified field in the input source.
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 * Creates a new builder with this object as the basis.
168 *
169 * @return a {@code Builder}
170 */
171 @Nonnull
172 public Builder with()
173 {
174 return newBuilder( this );
175 }
176 /**
177 * Creates a new {@code Resource} instance using the specified includes.
178 *
179 * @param includes the new {@code Collection<String>} to use
180 * @return a {@code Resource} with the specified includes
181 */
182 @Nonnull
183 public Resource withIncludes( Collection<String> includes )
184 {
185 return with().includes( includes ).build();
186 }
187 /**
188 * Creates a new {@code Resource} instance using the specified excludes.
189 *
190 * @param excludes the new {@code Collection<String>} to use
191 * @return a {@code Resource} with the specified excludes
192 */
193 @Nonnull
194 public Resource withExcludes( Collection<String> excludes )
195 {
196 return with().excludes( excludes ).build();
197 }
198 /**
199 * Creates a new {@code Resource} instance using the specified directory.
200 *
201 * @param directory the new {@code String} to use
202 * @return a {@code Resource} with the specified directory
203 */
204 @Nonnull
205 public Resource withDirectory( String directory )
206 {
207 return with().directory( directory ).build();
208 }
209 /**
210 * Creates a new {@code Resource} instance using the specified targetPath.
211 *
212 * @param targetPath the new {@code String} to use
213 * @return a {@code Resource} with the specified targetPath
214 */
215 @Nonnull
216 public Resource withTargetPath( String targetPath )
217 {
218 return with().targetPath( targetPath ).build();
219 }
220 /**
221 * Creates a new {@code Resource} instance using the specified filtering.
222 *
223 * @param filtering the new {@code String} to use
224 * @return a {@code Resource} with the specified filtering
225 */
226 @Nonnull
227 public Resource withFiltering( String filtering )
228 {
229 return with().filtering( filtering ).build();
230 }
231 /**
232 * Creates a new {@code Resource} instance using the specified mergeId.
233 *
234 * @param mergeId the new {@code String} to use
235 * @return a {@code Resource} with the specified mergeId
236 */
237 @Nonnull
238 public Resource withMergeId( String mergeId )
239 {
240 return with().mergeId( mergeId ).build();
241 }
242
243 /**
244 * Creates a new {@code Resource} instance.
245 * Equivalent to {@code newInstance( true )}.
246 * @see #newInstance(boolean)
247 *
248 * @return a new {@code Resource}
249 */
250 @Nonnull
251 public static Resource newInstance()
252 {
253 return newInstance( true );
254 }
255
256 /**
257 * Creates a new {@code Resource} instance using default values or not.
258 * Equivalent to {@code newBuilder( withDefaults ).build()}.
259 *
260 * @param withDefaults the boolean indicating whether default values should be used
261 * @return a new {@code Resource}
262 */
263 @Nonnull
264 public static Resource newInstance( boolean withDefaults )
265 {
266 return newBuilder( withDefaults ).build();
267 }
268
269 /**
270 * Creates a new {@code Resource} builder instance.
271 * Equivalent to {@code newBuilder( true )}.
272 * @see #newBuilder(boolean)
273 *
274 * @return a new {@code Builder}
275 */
276 @Nonnull
277 public static Builder newBuilder()
278 {
279 return newBuilder( true );
280 }
281
282 /**
283 * Creates a new {@code Resource} builder instance using default values or not.
284 *
285 * @param withDefaults the boolean indicating whether default values should be used
286 * @return a new {@code Builder}
287 */
288 @Nonnull
289 public static Builder newBuilder( boolean withDefaults )
290 {
291 return new Builder( withDefaults );
292 }
293
294 /**
295 * Creates a new {@code Resource} builder instance using the specified object as a basis.
296 * Equivalent to {@code newBuilder( from, false )}.
297 *
298 * @param from the {@code Resource} instance to use as a basis
299 * @return a new {@code Builder}
300 */
301 @Nonnull
302 public static Builder newBuilder( Resource from )
303 {
304 return newBuilder( from, false );
305 }
306
307 /**
308 * Creates a new {@code Resource} builder instance using the specified object as a basis.
309 *
310 * @param from the {@code Resource} instance to use as a basis
311 * @param forceCopy the boolean indicating if a copy should be forced
312 * @return a new {@code Builder}
313 */
314 @Nonnull
315 public static Builder newBuilder( Resource from, boolean forceCopy )
316 {
317 return new Builder( from, forceCopy );
318 }
319
320 /**
321 * Builder class used to create Resource instances.
322 * @see #with()
323 * @see #newBuilder()
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 * @see java.lang.Object#toString()
478 */
479 public String toString()
480 {
481 return "Resource {targetPath: " + getTargetPath() + ", filtering: " + isFiltering() + ", " + super.toString() + "}";
482 }
483
484
485 }