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  
58      /**
59        * Constructor for this class, package protected.
60        * @see Builder#build()
61        */
62      Resource(
63          Collection<String> includes,
64          Collection<String> excludes,
65          String directory,
66          String targetPath,
67          String filtering,
68          String mergeId,
69          Map<Object, InputLocation> locations
70      ) {
71          super(
72              includes,
73              excludes,
74              directory,
75              locations
76          );
77          this.targetPath = targetPath;
78          this.filtering = filtering;
79          this.mergeId = mergeId;
80      }
81  
82      /**
83       * Describe the resource target path. The path is relative to the target/classes
84       * directory (i.e. {@code ${project.build.outputDirectory}}).
85       * For example, if you want that resource to appear in a specific package
86       * ({@code org.apache.maven.messages}), you must specify this
87       * element with this value: {@code org/apache/maven/messages}.
88       * This is not required if you simply put the resources in that directory
89       * structure at the source, however.
90       *
91       * @return a {@code String}
92       */
93      public String getTargetPath() {
94          return this.targetPath;
95      }
96  
97      /**
98       * Whether resources are filtered to replace tokens with parameterised values or not.
99       * The values are taken from the {@code properties} element and from the
100      * properties in the files listed in the {@code filters} element. Note: While the type
101      * of this field is {@code String} for technical reasons, the semantic type is actually
102      * {@code Boolean}. Default value is {@code false}.
103      *
104      * @return a {@code String}
105      */
106     public String getFiltering() {
107         return this.filtering;
108     }
109 
110     /**
111      * FOR INTERNAL USE ONLY. This is a unique identifier assigned to each
112      * resource to allow Maven to merge changes to this resource that take
113      * place during the execution of a plugin. This field must be managed
114      * by the generated parser and formatter classes in order to allow it
115      * to survive model interpolation.
116      *
117      * @return a {@code String}
118      */
119     public String getMergeId() {
120         return this.mergeId;
121     }
122 
123     /**
124      * Creates a new builder with this object as the basis.
125      *
126      * @return a {@code Builder}
127      */
128     @Nonnull
129     public Builder with() {
130         return newBuilder(this);
131     }
132     /**
133      * Creates a new {@code Resource} instance using the specified includes.
134      *
135      * @param includes the new {@code Collection<String>} to use
136      * @return a {@code Resource} with the specified includes
137      */
138     @Nonnull
139     public Resource withIncludes(Collection<String> includes) {
140         return newBuilder(this, true).includes(includes).build();
141     }
142     /**
143      * Creates a new {@code Resource} instance using the specified excludes.
144      *
145      * @param excludes the new {@code Collection<String>} to use
146      * @return a {@code Resource} with the specified excludes
147      */
148     @Nonnull
149     public Resource withExcludes(Collection<String> excludes) {
150         return newBuilder(this, true).excludes(excludes).build();
151     }
152     /**
153      * Creates a new {@code Resource} instance using the specified directory.
154      *
155      * @param directory the new {@code String} to use
156      * @return a {@code Resource} with the specified directory
157      */
158     @Nonnull
159     public Resource withDirectory(String directory) {
160         return newBuilder(this, true).directory(directory).build();
161     }
162     /**
163      * Creates a new {@code Resource} instance using the specified targetPath.
164      *
165      * @param targetPath the new {@code String} to use
166      * @return a {@code Resource} with the specified targetPath
167      */
168     @Nonnull
169     public Resource withTargetPath(String targetPath) {
170         return newBuilder(this, true).targetPath(targetPath).build();
171     }
172     /**
173      * Creates a new {@code Resource} instance using the specified filtering.
174      *
175      * @param filtering the new {@code String} to use
176      * @return a {@code Resource} with the specified filtering
177      */
178     @Nonnull
179     public Resource withFiltering(String filtering) {
180         return newBuilder(this, true).filtering(filtering).build();
181     }
182     /**
183      * Creates a new {@code Resource} instance using the specified mergeId.
184      *
185      * @param mergeId the new {@code String} to use
186      * @return a {@code Resource} with the specified mergeId
187      */
188     @Nonnull
189     public Resource withMergeId(String mergeId) {
190         return newBuilder(this, true).mergeId(mergeId).build();
191     }
192 
193     /**
194      * Creates a new {@code Resource} instance.
195      * Equivalent to {@code newInstance(true)}.
196      * @see #newInstance(boolean)
197      *
198      * @return a new {@code Resource}
199      */
200     @Nonnull
201     public static Resource newInstance() {
202         return newInstance(true);
203     }
204 
205     /**
206      * Creates a new {@code Resource} instance using default values or not.
207      * Equivalent to {@code newBuilder(withDefaults).build()}.
208      *
209      * @param withDefaults the boolean indicating whether default values should be used
210      * @return a new {@code Resource}
211      */
212     @Nonnull
213     public static Resource newInstance(boolean withDefaults) {
214         return newBuilder(withDefaults).build();
215     }
216 
217     /**
218      * Creates a new {@code Resource} builder instance.
219      * Equivalent to {@code newBuilder(true)}.
220      * @see #newBuilder(boolean)
221      *
222      * @return a new {@code Builder}
223      */
224     @Nonnull
225     public static Builder newBuilder() {
226         return newBuilder(true);
227     }
228 
229     /**
230      * Creates a new {@code Resource} builder instance using default values or not.
231      *
232      * @param withDefaults the boolean indicating whether default values should be used
233      * @return a new {@code Builder}
234      */
235     @Nonnull
236     public static Builder newBuilder(boolean withDefaults) {
237         return new Builder(withDefaults);
238     }
239 
240     /**
241      * Creates a new {@code Resource} builder instance using the specified object as a basis.
242      * Equivalent to {@code newBuilder(from, false)}.
243      *
244      * @param from the {@code Resource} instance to use as a basis
245      * @return a new {@code Builder}
246      */
247     @Nonnull
248     public static Builder newBuilder(Resource from) {
249         return newBuilder(from, false);
250     }
251 
252     /**
253      * Creates a new {@code Resource} builder instance using the specified object as a basis.
254      *
255      * @param from the {@code Resource} instance to use as a basis
256      * @param forceCopy the boolean indicating if a copy should be forced
257      * @return a new {@code Builder}
258      */
259     @Nonnull
260     public static Builder newBuilder(Resource from, boolean forceCopy) {
261         return new Builder(from, forceCopy);
262     }
263 
264     /**
265      * Builder class used to create Resource instances.
266      * @see #with()
267      * @see #newBuilder()
268      */
269     @NotThreadSafe
270     public static class Builder
271         extends FileSet.Builder
272     {
273         Resource base;
274         String targetPath;
275         String filtering;
276         String mergeId;
277 
278         Builder(boolean withDefaults) {
279             super(withDefaults);
280             if (withDefaults) {
281             }
282         }
283 
284         Builder(Resource base, boolean forceCopy) {
285             super(base, forceCopy);
286             if (forceCopy) {
287                 this.targetPath = base.targetPath;
288                 this.filtering = base.filtering;
289                 this.mergeId = base.mergeId;
290                 this.locations = base.locations;
291             } else {
292                 this.base = base;
293             }
294         }
295 
296         @Nonnull
297         public Builder includes(Collection<String> includes) {
298             this.includes = includes;
299             return this;
300         }
301 
302         @Nonnull
303         public Builder excludes(Collection<String> excludes) {
304             this.excludes = excludes;
305             return this;
306         }
307 
308         @Nonnull
309         public Builder directory(String directory) {
310             this.directory = directory;
311             return this;
312         }
313 
314         @Nonnull
315         public Builder targetPath(String targetPath) {
316             this.targetPath = targetPath;
317             return this;
318         }
319 
320         @Nonnull
321         public Builder filtering(String filtering) {
322             this.filtering = filtering;
323             return this;
324         }
325 
326         @Nonnull
327         public Builder mergeId(String mergeId) {
328             this.mergeId = mergeId;
329             return this;
330         }
331 
332 
333         @Nonnull
334         public Builder location(Object key, InputLocation location) {
335             if (location != null) {
336                 if (!(this.locations instanceof HashMap)) {
337                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
338                 }
339                 this.locations.put(key, location);
340             }
341             return this;
342         }
343 
344         @Nonnull
345         public Resource build() {
346             if (base != null
347                     && (includes == null || includes == base.includes)
348                     && (excludes == null || excludes == base.excludes)
349                     && (directory == null || directory == base.directory)
350                     && (targetPath == null || targetPath == base.targetPath)
351                     && (filtering == null || filtering == base.filtering)
352                     && (mergeId == null || mergeId == base.mergeId)
353             ) {
354                 return base;
355             }
356             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
357             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
358             Map<Object, InputLocation> locations = new HashMap<>();
359             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
360             locations.put("includes", newlocs.containsKey("includes") ? newlocs.get("includes") : oldlocs.get("includes"));
361             locations.put("excludes", newlocs.containsKey("excludes") ? newlocs.get("excludes") : oldlocs.get("excludes"));
362             locations.put("directory", newlocs.containsKey("directory") ? newlocs.get("directory") : oldlocs.get("directory"));
363             locations.put("targetPath", newlocs.containsKey("targetPath") ? newlocs.get("targetPath") : oldlocs.get("targetPath"));
364             locations.put("filtering", newlocs.containsKey("filtering") ? newlocs.get("filtering") : oldlocs.get("filtering"));
365             locations.put("mergeId", newlocs.containsKey("mergeId") ? newlocs.get("mergeId") : oldlocs.get("mergeId"));
366             return new Resource(
367                 includes != null ? includes : (base != null ? base.includes : null),
368                 excludes != null ? excludes : (base != null ? base.excludes : null),
369                 directory != null ? directory : (base != null ? base.directory : null),
370                 targetPath != null ? targetPath : (base != null ? base.targetPath : null),
371                 filtering != null ? filtering : (base != null ? base.filtering : null),
372                 mergeId != null ? mergeId : (base != null ? base.mergeId : null),
373                 locations
374             );
375         }
376     }
377 
378 
379             
380     public boolean isFiltering()
381     {
382         return ( getFiltering() != null ) ? Boolean.parseBoolean( getFiltering() ) : false;
383     }
384             
385           
386 
387             
388     /**
389      * @see java.lang.Object#toString()
390      */
391     public String toString()
392     {
393         return "Resource {targetPath: " + getTargetPath() + ", filtering: " + isFiltering() + ", " + super.toString() + "}";
394     }
395             
396           
397 }