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