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