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.Set;
15  import org.apache.maven.api.annotations.Experimental;
16  import org.apache.maven.api.annotations.Generated;
17  import org.apache.maven.api.annotations.Immutable;
18  import org.apache.maven.api.annotations.Nonnull;
19  import org.apache.maven.api.annotations.NotThreadSafe;
20  import org.apache.maven.api.annotations.ThreadSafe;
21  
22  /**
23   * A PatternSet for files.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class FileSet
28      extends PatternSet
29      implements Serializable, InputLocationTracker
30  {
31      /**
32       * Describe the directory where the resources are stored. The path is relative
33       * to the POM.
34       */
35      final String directory;
36      /** Locations (this potentially hides the same name field from the super class) */
37      final Map<Object, InputLocation> locations;
38  
39      /**
40        * Constructor for this class, to be called from its subclasses and {@link Builder}.
41        * @see Builder#build()
42        */
43      protected FileSet(Builder builder) {
44          super(builder);
45          this.directory = builder.directory != null ? builder.directory : (builder.base != null ? builder.base.directory : null);
46          Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
47          Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
48          Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
49          mutableLocations.put("directory", newlocs.containsKey("directory") ? newlocs.get("directory") : oldlocs.get("directory"));
50          this.locations = Collections.unmodifiableMap(mutableLocations);
51      }
52  
53      /**
54       * Describe the directory where the resources are stored. The path is relative
55       * to the POM.
56       *
57       * @return a {@code String}
58       */
59      public String getDirectory() {
60          return this.directory;
61      }
62  
63      /**
64       * Gets the location of the specified field in the input source.
65       */
66      public InputLocation getLocation(Object key) {
67          return locations != null ? locations.get(key) : null;
68      }
69  
70      /**
71      * Gets the keys of the locations of the input source.
72      */
73      public Set<Object> getLocationKeys() {
74          return locations != null ? locations.keySet() : null;
75      }
76  
77      /**
78       * Creates a new builder with this object as the basis.
79       *
80       * @return a {@code Builder}
81       */
82      @Nonnull
83      public Builder with() {
84          return newBuilder(this);
85      }
86      /**
87       * Creates a new {@code FileSet} instance using the specified includes.
88       *
89       * @param includes the new {@code Collection<String>} to use
90       * @return a {@code FileSet} with the specified includes
91       */
92      @Nonnull
93      public FileSet withIncludes(Collection<String> includes) {
94          return newBuilder(this, true).includes(includes).build();
95      }
96      /**
97       * Creates a new {@code FileSet} instance using the specified excludes.
98       *
99       * @param excludes the new {@code Collection<String>} to use
100      * @return a {@code FileSet} with the specified excludes
101      */
102     @Nonnull
103     public FileSet withExcludes(Collection<String> excludes) {
104         return newBuilder(this, true).excludes(excludes).build();
105     }
106     /**
107      * Creates a new {@code FileSet} instance using the specified directory.
108      *
109      * @param directory the new {@code String} to use
110      * @return a {@code FileSet} with the specified directory
111      */
112     @Nonnull
113     public FileSet withDirectory(String directory) {
114         return newBuilder(this, true).directory(directory).build();
115     }
116 
117     /**
118      * Creates a new {@code FileSet} instance.
119      * Equivalent to {@code newInstance(true)}.
120      * @see #newInstance(boolean)
121      *
122      * @return a new {@code FileSet}
123      */
124     @Nonnull
125     public static FileSet newInstance() {
126         return newInstance(true);
127     }
128 
129     /**
130      * Creates a new {@code FileSet} instance using default values or not.
131      * Equivalent to {@code newBuilder(withDefaults).build()}.
132      *
133      * @param withDefaults the boolean indicating whether default values should be used
134      * @return a new {@code FileSet}
135      */
136     @Nonnull
137     public static FileSet newInstance(boolean withDefaults) {
138         return newBuilder(withDefaults).build();
139     }
140 
141     /**
142      * Creates a new {@code FileSet} builder instance.
143      * Equivalent to {@code newBuilder(true)}.
144      * @see #newBuilder(boolean)
145      *
146      * @return a new {@code Builder}
147      */
148     @Nonnull
149     public static Builder newBuilder() {
150         return newBuilder(true);
151     }
152 
153     /**
154      * Creates a new {@code FileSet} builder instance using default values or not.
155      *
156      * @param withDefaults the boolean indicating whether default values should be used
157      * @return a new {@code Builder}
158      */
159     @Nonnull
160     public static Builder newBuilder(boolean withDefaults) {
161         return new Builder(withDefaults);
162     }
163 
164     /**
165      * Creates a new {@code FileSet} builder instance using the specified object as a basis.
166      * Equivalent to {@code newBuilder(from, false)}.
167      *
168      * @param from the {@code FileSet} instance to use as a basis
169      * @return a new {@code Builder}
170      */
171     @Nonnull
172     public static Builder newBuilder(FileSet from) {
173         return newBuilder(from, false);
174     }
175 
176     /**
177      * Creates a new {@code FileSet} builder instance using the specified object as a basis.
178      *
179      * @param from the {@code FileSet} instance to use as a basis
180      * @param forceCopy the boolean indicating if a copy should be forced
181      * @return a new {@code Builder}
182      */
183     @Nonnull
184     public static Builder newBuilder(FileSet from, boolean forceCopy) {
185         return new Builder(from, forceCopy);
186     }
187 
188     /**
189      * Builder class used to create FileSet instances.
190      * @see #with()
191      * @see #newBuilder()
192      */
193     @NotThreadSafe
194     public static class Builder
195         extends PatternSet.Builder
196     {
197         FileSet base;
198         String directory;
199 
200         protected Builder(boolean withDefaults) {
201             super(withDefaults);
202             if (withDefaults) {
203             }
204         }
205 
206         protected Builder(FileSet base, boolean forceCopy) {
207             super(base, forceCopy);
208             if (forceCopy) {
209                 this.directory = base.directory;
210                 this.locations = base.locations;
211                 this.importedFrom = base.importedFrom;
212             } else {
213                 this.base = base;
214             }
215         }
216 
217         @Nonnull
218         public Builder includes(Collection<String> includes) {
219             this.includes = includes;
220             return this;
221         }
222 
223         @Nonnull
224         public Builder excludes(Collection<String> excludes) {
225             this.excludes = excludes;
226             return this;
227         }
228 
229         @Nonnull
230         public Builder directory(String directory) {
231             this.directory = directory;
232             return this;
233         }
234 
235 
236         @Nonnull
237         public Builder location(Object key, InputLocation location) {
238             if (location != null) {
239                 if (!(this.locations instanceof HashMap)) {
240                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
241                 }
242                 this.locations.put(key, location);
243             }
244             return this;
245         }
246 
247         @Nonnull
248         public Builder importedFrom(InputLocation importedFrom) {
249             this.importedFrom = importedFrom;
250             return this;
251         }
252 
253         @Nonnull
254         public FileSet build() {
255             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
256             if (base != null
257                     && (includes == null || includes == base.includes)
258                     && (excludes == null || excludes == base.excludes)
259                     && (directory == null || directory == base.directory)
260             ) {
261                 return base;
262             }
263             return new FileSet(this);
264         }
265     }
266 
267 
268             
269     /**
270      * @see java.lang.Object#toString()
271      */
272     public String toString() {
273         return "FileSet {directory: " + getDirectory() + ", " + super.toString() + "}";
274     }
275             
276           
277 }