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 java.util.Set;
15 import org.apache.maven.api.annotations.Experimental;
16 import org.apache.maven.api.annotations.Generated;
17 import org.apache.maven.api.annotations.Immutable;
18 import org.apache.maven.api.annotations.Nonnull;
19 import org.apache.maven.api.annotations.NotThreadSafe;
20 import org.apache.maven.api.annotations.ThreadSafe;
21
22
23
24
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class FileSet
28 extends PatternSet
29 implements Serializable, InputLocationTracker
30 {
31
32
33
34
35 final String directory;
36
37 final Map<Object, InputLocation> locations;
38
39
40
41
42
43 protected FileSet(Builder builder) {
44 super(builder);
45 this.directory = builder.directory != null ? builder.directory : (builder.base != null ? builder.base.directory : null);
46 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
47 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
48 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
49 mutableLocations.put("directory", newlocs.containsKey("directory") ? newlocs.get("directory") : oldlocs.get("directory"));
50 this.locations = Collections.unmodifiableMap(mutableLocations);
51 }
52
53
54
55
56
57
58
59 public String getDirectory() {
60 return this.directory;
61 }
62
63
64
65
66 public InputLocation getLocation(Object key) {
67 return locations != null ? locations.get(key) : null;
68 }
69
70
71
72
73 public Set<Object> getLocationKeys() {
74 return locations != null ? locations.keySet() : null;
75 }
76
77
78
79
80
81
82 @Nonnull
83 public Builder with() {
84 return newBuilder(this);
85 }
86
87
88
89
90
91
92 @Nonnull
93 public FileSet withIncludes(Collection<String> includes) {
94 return newBuilder(this, true).includes(includes).build();
95 }
96
97
98
99
100
101
102 @Nonnull
103 public FileSet withExcludes(Collection<String> excludes) {
104 return newBuilder(this, true).excludes(excludes).build();
105 }
106
107
108
109
110
111
112 @Nonnull
113 public FileSet withDirectory(String directory) {
114 return newBuilder(this, true).directory(directory).build();
115 }
116
117
118
119
120
121
122
123
124 @Nonnull
125 public static FileSet newInstance() {
126 return newInstance(true);
127 }
128
129
130
131
132
133
134
135
136 @Nonnull
137 public static FileSet newInstance(boolean withDefaults) {
138 return newBuilder(withDefaults).build();
139 }
140
141
142
143
144
145
146
147
148 @Nonnull
149 public static Builder newBuilder() {
150 return newBuilder(true);
151 }
152
153
154
155
156
157
158
159 @Nonnull
160 public static Builder newBuilder(boolean withDefaults) {
161 return new Builder(withDefaults);
162 }
163
164
165
166
167
168
169
170
171 @Nonnull
172 public static Builder newBuilder(FileSet from) {
173 return newBuilder(from, false);
174 }
175
176
177
178
179
180
181
182
183 @Nonnull
184 public static Builder newBuilder(FileSet from, boolean forceCopy) {
185 return new Builder(from, forceCopy);
186 }
187
188
189
190
191
192
193 @NotThreadSafe
194 public static class Builder
195 extends PatternSet.Builder
196 {
197 FileSet base;
198 String directory;
199
200 protected Builder(boolean withDefaults) {
201 super(withDefaults);
202 if (withDefaults) {
203 }
204 }
205
206 protected Builder(FileSet base, boolean forceCopy) {
207 super(base, forceCopy);
208 if (forceCopy) {
209 this.directory = base.directory;
210 this.locations = base.locations;
211 this.importedFrom = base.importedFrom;
212 } else {
213 this.base = base;
214 }
215 }
216
217 @Nonnull
218 public Builder includes(Collection<String> includes) {
219 this.includes = includes;
220 return this;
221 }
222
223 @Nonnull
224 public Builder excludes(Collection<String> excludes) {
225 this.excludes = excludes;
226 return this;
227 }
228
229 @Nonnull
230 public Builder directory(String directory) {
231 this.directory = directory;
232 return this;
233 }
234
235
236 @Nonnull
237 public Builder location(Object key, InputLocation location) {
238 if (location != null) {
239 if (!(this.locations instanceof HashMap)) {
240 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
241 }
242 this.locations.put(key, location);
243 }
244 return this;
245 }
246
247 @Nonnull
248 public Builder importedFrom(InputLocation importedFrom) {
249 this.importedFrom = importedFrom;
250 return this;
251 }
252
253 @Nonnull
254 public FileSet build() {
255
256 if (base != null
257 && (includes == null || includes == base.includes)
258 && (excludes == null || excludes == base.excludes)
259 && (directory == null || directory == base.directory)
260 ) {
261 return base;
262 }
263 return new FileSet(this);
264 }
265 }
266
267
268
269
270
271
272 public String toString() {
273 return "FileSet {directory: " + getDirectory() + ", " + super.toString() + "}";
274 }
275
276
277 }