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