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      /** Location of the xml element for the field directory. */
36      final InputLocation directoryLocation;
37  
38      /**
39        * Constructor for this class, package protected.
40        * @see Builder#build()
41        */
42      FileSet(
43          Collection<String> includes,
44          Collection<String> excludes,
45          String directory,
46          Map<Object, InputLocation> locations,
47          InputLocation location,
48          InputLocation includesLocation,
49          InputLocation excludesLocation,
50          InputLocation directoryLocation
51      )
52      {
53          super(
54              includes,
55              excludes,
56              locations,
57              location,
58              includesLocation,
59              excludesLocation
60          );
61          this.directory = directory;
62          this.directoryLocation = directoryLocation;
63      }
64  
65      /**
66       * Describe the directory where the resources are stored. The path is relative
67       * to the POM.
68       *
69       * @return a {@code String}
70       */
71      public String getDirectory()
72      {
73          return this.directory;
74      }
75  
76      /**
77       * Gets the location of the specified field in the input source.
78       */
79      public InputLocation getLocation( Object key )
80      {
81          if ( key instanceof String )
82          {
83              switch ( ( String ) key )
84              {
85                  case "directory":
86                      return directoryLocation;
87              }
88          }
89          return super.getLocation( key );
90      }
91  
92      /**
93       * Creates a new builder with this object as the basis.
94       *
95       * @return a {@code Builder}
96       */
97      @Nonnull
98      public Builder with()
99      {
100         return newBuilder( this );
101     }
102     /**
103      * Creates a new {@code FileSet} instance using the specified includes.
104      *
105      * @param includes the new {@code Collection<String>} to use
106      * @return a {@code FileSet} with the specified includes
107      */
108     @Nonnull
109     public FileSet withIncludes( Collection<String> includes )
110     {
111         return with().includes( includes ).build();
112     }
113     /**
114      * Creates a new {@code FileSet} instance using the specified excludes.
115      *
116      * @param excludes the new {@code Collection<String>} to use
117      * @return a {@code FileSet} with the specified excludes
118      */
119     @Nonnull
120     public FileSet withExcludes( Collection<String> excludes )
121     {
122         return with().excludes( excludes ).build();
123     }
124     /**
125      * Creates a new {@code FileSet} instance using the specified directory.
126      *
127      * @param directory the new {@code String} to use
128      * @return a {@code FileSet} with the specified directory
129      */
130     @Nonnull
131     public FileSet withDirectory( String directory )
132     {
133         return with().directory( directory ).build();
134     }
135 
136     /**
137      * Creates a new {@code FileSet} instance.
138      * Equivalent to {@code newInstance( true )}.
139      * @see #newInstance(boolean)
140      *
141      * @return a new {@code FileSet}
142      */
143     @Nonnull
144     public static FileSet newInstance()
145     {
146         return newInstance( true );
147     }
148 
149     /**
150      * Creates a new {@code FileSet} instance using default values or not.
151      * Equivalent to {@code newBuilder( withDefaults ).build()}.
152      *
153      * @param withDefaults the boolean indicating whether default values should be used
154      * @return a new {@code FileSet}
155      */
156     @Nonnull
157     public static FileSet newInstance( boolean withDefaults )
158     {
159         return newBuilder( withDefaults ).build();
160     }
161 
162     /**
163      * Creates a new {@code FileSet} builder instance.
164      * Equivalent to {@code newBuilder( true )}.
165      * @see #newBuilder(boolean)
166      *
167      * @return a new {@code Builder}
168      */
169     @Nonnull
170     public static Builder newBuilder()
171     {
172         return newBuilder( true );
173     }
174 
175     /**
176      * Creates a new {@code FileSet} builder instance using default values or not.
177      *
178      * @param withDefaults the boolean indicating whether default values should be used
179      * @return a new {@code Builder}
180      */
181     @Nonnull
182     public static Builder newBuilder( boolean withDefaults )
183     {
184         return new Builder( withDefaults );
185     }
186 
187     /**
188      * Creates a new {@code FileSet} builder instance using the specified object as a basis.
189      * Equivalent to {@code newBuilder( from, false )}.
190      *
191      * @param from the {@code FileSet} instance to use as a basis
192      * @return a new {@code Builder}
193      */
194     @Nonnull
195     public static Builder newBuilder( FileSet from )
196     {
197         return newBuilder( from, false );
198     }
199 
200     /**
201      * Creates a new {@code FileSet} builder instance using the specified object as a basis.
202      *
203      * @param from the {@code FileSet} instance to use as a basis
204      * @param forceCopy the boolean indicating if a copy should be forced
205      * @return a new {@code Builder}
206      */
207     @Nonnull
208     public static Builder newBuilder( FileSet from, boolean forceCopy )
209     {
210         return new Builder( from, forceCopy );
211     }
212 
213     /**
214      * Builder class used to create FileSet instances.
215      * @see #with()
216      * @see #newBuilder()
217      */
218     @NotThreadSafe
219     public static class Builder
220         extends PatternSet.Builder
221     {
222         FileSet base;
223         String directory;
224 
225         Builder( boolean withDefaults )
226         {
227             super( withDefaults );
228             if ( withDefaults )
229             {
230             }
231         }
232 
233         Builder( FileSet base, boolean forceCopy )
234         {
235             super( base, forceCopy );
236             if ( forceCopy )
237             {
238                 this.directory = base.directory;
239             }
240             else
241             {
242                 this.base = base;
243             }
244         }
245 
246         @Nonnull
247         public Builder includes( Collection<String> includes )
248         {
249             this.includes = includes;
250             return this;
251         }
252 
253         @Nonnull
254         public Builder excludes( Collection<String> excludes )
255         {
256             this.excludes = excludes;
257             return this;
258         }
259 
260         @Nonnull
261         public Builder directory( String directory )
262         {
263             this.directory = directory;
264             return this;
265         }
266 
267 
268         @Nonnull
269         public Builder location( Object key, InputLocation location )
270         {
271             if ( location != null )
272             {
273                 if ( this.locations == null )
274                 {
275                     this.locations = new HashMap<>();
276                 }
277                 this.locations.put( key, location );
278             }
279             return this;
280         }
281 
282         @Nonnull
283         public FileSet build()
284         {
285             if ( base != null
286                     && ( includes == null || includes == base.includes )
287                     && ( excludes == null || excludes == base.excludes )
288                     && ( directory == null || directory == base.directory )
289             )
290             {
291                 return base;
292             }
293             Map<Object, InputLocation> locations = null;
294             InputLocation location = null;
295             InputLocation includesLocation = null;
296             InputLocation excludesLocation = null;
297             InputLocation directoryLocation = null;
298             if ( this.locations != null )
299             {
300                 locations = this.locations;
301                 location = locations.remove( "" );
302                 includesLocation = locations.remove( "includes" );
303                 excludesLocation = locations.remove( "excludes" );
304                 directoryLocation = locations.remove( "directory" );
305             }
306             return new FileSet(
307                 includes != null ? includes : ( base != null ? base.includes : null ),
308                 excludes != null ? excludes : ( base != null ? base.excludes : null ),
309                 directory != null ? directory : ( base != null ? base.directory : null ),
310                 locations != null ? locations : ( base != null ? base.locations : null ),
311                 location != null ? location : ( base != null ? base.location : null ),
312                 includesLocation != null ? includesLocation : ( base != null ? base.includesLocation : null ),
313                 excludesLocation != null ? excludesLocation : ( base != null ? base.excludesLocation : null ),
314                 directoryLocation != null ? directoryLocation : ( base != null ? base.directoryLocation : null )
315             );
316         }
317     }
318 
319 
320             
321     /**
322      * @see java.lang.Object#toString()
323      */
324     public String toString()
325     {
326         return "FileSet {directory: " + getDirectory() + ", " + super.toString() + "}";
327     }
328             
329           
330 }