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