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