1   
2   
3   
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  
23  
24  @Experimental
25  @Generated @ThreadSafe @Immutable
26  public class FileSet
27      extends PatternSet
28      implements Serializable, InputLocationTracker
29  {
30      
31  
32  
33  
34      final String directory;
35      
36      final InputLocation directoryLocation;
37  
38      
39  
40  
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  
67  
68  
69  
70  
71      public String getDirectory()
72      {
73          return this.directory;
74      }
75  
76      
77  
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  
94  
95  
96  
97      @Nonnull
98      public Builder with()
99      {
100         return newBuilder( this );
101     }
102     
103 
104 
105 
106 
107 
108     @Nonnull
109     public FileSet withIncludes( Collection<String> includes )
110     {
111         return with().includes( includes ).build();
112     }
113     
114 
115 
116 
117 
118 
119     @Nonnull
120     public FileSet withExcludes( Collection<String> excludes )
121     {
122         return with().excludes( excludes ).build();
123     }
124     
125 
126 
127 
128 
129 
130     @Nonnull
131     public FileSet withDirectory( String directory )
132     {
133         return with().directory( directory ).build();
134     }
135 
136     
137 
138 
139 
140 
141 
142 
143     @Nonnull
144     public static FileSet newInstance()
145     {
146         return newInstance( true );
147     }
148 
149     
150 
151 
152 
153 
154 
155 
156     @Nonnull
157     public static FileSet newInstance( boolean withDefaults )
158     {
159         return newBuilder( withDefaults ).build();
160     }
161 
162     
163 
164 
165 
166 
167 
168 
169     @Nonnull
170     public static Builder newBuilder()
171     {
172         return newBuilder( true );
173     }
174 
175     
176 
177 
178 
179 
180 
181     @Nonnull
182     public static Builder newBuilder( boolean withDefaults )
183     {
184         return new Builder( withDefaults );
185     }
186 
187     
188 
189 
190 
191 
192 
193 
194     @Nonnull
195     public static Builder newBuilder( FileSet from )
196     {
197         return newBuilder( from, false );
198     }
199 
200     
201 
202 
203 
204 
205 
206 
207     @Nonnull
208     public static Builder newBuilder( FileSet from, boolean forceCopy )
209     {
210         return new Builder( from, forceCopy );
211     }
212 
213     
214 
215 
216 
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 
323 
324     public String toString()
325     {
326         return "FileSet {directory: " + getDirectory() + ", " + super.toString() + "}";
327     }
328             
329           
330 }