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