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