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
26 @Experimental
27 @Generated @ThreadSafe @Immutable
28 public class Resource
29 extends FileSet
30 implements Serializable, InputLocationTracker
31 {
32
33
34
35
36
37
38
39
40
41 final String targetPath;
42
43
44
45
46
47
48
49 final String filtering;
50
51
52
53
54
55
56
57 final String mergeId;
58
59 final Map<Object, InputLocation> locations;
60
61
62
63
64
65 protected Resource(Builder builder) {
66 super(builder);
67 this.targetPath = builder.targetPath != null ? builder.targetPath : (builder.base != null ? builder.base.targetPath : null);
68 this.filtering = builder.filtering != null ? builder.filtering : (builder.base != null ? builder.base.filtering : null);
69 this.mergeId = builder.mergeId != null ? builder.mergeId : (builder.base != null ? builder.base.mergeId : null);
70 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
71 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
72 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
73 mutableLocations.put("targetPath", newlocs.containsKey("targetPath") ? newlocs.get("targetPath") : oldlocs.get("targetPath"));
74 mutableLocations.put("filtering", newlocs.containsKey("filtering") ? newlocs.get("filtering") : oldlocs.get("filtering"));
75 mutableLocations.put("mergeId", newlocs.containsKey("mergeId") ? newlocs.get("mergeId") : oldlocs.get("mergeId"));
76 this.locations = Collections.unmodifiableMap(mutableLocations);
77 }
78
79
80
81
82
83
84
85
86
87
88
89
90 public String getTargetPath() {
91 return this.targetPath;
92 }
93
94
95
96
97
98
99
100
101
102
103 public String getFiltering() {
104 return this.filtering;
105 }
106
107
108
109
110
111
112
113
114
115
116 public String getMergeId() {
117 return this.mergeId;
118 }
119
120
121
122
123 public InputLocation getLocation(Object key) {
124 return locations != null ? locations.get(key) : null;
125 }
126
127
128
129
130 public Set<Object> getLocationKeys() {
131 return locations != null ? locations.keySet() : null;
132 }
133
134
135
136
137
138
139 @Nonnull
140 public Builder with() {
141 return newBuilder(this);
142 }
143
144
145
146
147
148
149 @Nonnull
150 public Resource withIncludes(Collection<String> includes) {
151 return newBuilder(this, true).includes(includes).build();
152 }
153
154
155
156
157
158
159 @Nonnull
160 public Resource withExcludes(Collection<String> excludes) {
161 return newBuilder(this, true).excludes(excludes).build();
162 }
163
164
165
166
167
168
169 @Nonnull
170 public Resource withDirectory(String directory) {
171 return newBuilder(this, true).directory(directory).build();
172 }
173
174
175
176
177
178
179 @Nonnull
180 public Resource withTargetPath(String targetPath) {
181 return newBuilder(this, true).targetPath(targetPath).build();
182 }
183
184
185
186
187
188
189 @Nonnull
190 public Resource withFiltering(String filtering) {
191 return newBuilder(this, true).filtering(filtering).build();
192 }
193
194
195
196
197
198
199 @Nonnull
200 public Resource withMergeId(String mergeId) {
201 return newBuilder(this, true).mergeId(mergeId).build();
202 }
203
204
205
206
207
208
209
210
211 @Nonnull
212 public static Resource newInstance() {
213 return newInstance(true);
214 }
215
216
217
218
219
220
221
222
223 @Nonnull
224 public static Resource newInstance(boolean withDefaults) {
225 return newBuilder(withDefaults).build();
226 }
227
228
229
230
231
232
233
234
235 @Nonnull
236 public static Builder newBuilder() {
237 return newBuilder(true);
238 }
239
240
241
242
243
244
245
246 @Nonnull
247 public static Builder newBuilder(boolean withDefaults) {
248 return new Builder(withDefaults);
249 }
250
251
252
253
254
255
256
257
258 @Nonnull
259 public static Builder newBuilder(Resource from) {
260 return newBuilder(from, false);
261 }
262
263
264
265
266
267
268
269
270 @Nonnull
271 public static Builder newBuilder(Resource from, boolean forceCopy) {
272 return new Builder(from, forceCopy);
273 }
274
275
276
277
278
279
280 @NotThreadSafe
281 public static class Builder
282 extends FileSet.Builder
283 {
284 Resource base;
285 String targetPath;
286 String filtering;
287 String mergeId;
288
289 protected Builder(boolean withDefaults) {
290 super(withDefaults);
291 if (withDefaults) {
292 }
293 }
294
295 protected Builder(Resource base, boolean forceCopy) {
296 super(base, forceCopy);
297 if (forceCopy) {
298 this.targetPath = base.targetPath;
299 this.filtering = base.filtering;
300 this.mergeId = base.mergeId;
301 this.locations = base.locations;
302 this.importedFrom = base.importedFrom;
303 } else {
304 this.base = base;
305 }
306 }
307
308 @Nonnull
309 public Builder includes(Collection<String> includes) {
310 this.includes = includes;
311 return this;
312 }
313
314 @Nonnull
315 public Builder excludes(Collection<String> excludes) {
316 this.excludes = excludes;
317 return this;
318 }
319
320 @Nonnull
321 public Builder directory(String directory) {
322 this.directory = directory;
323 return this;
324 }
325
326 @Nonnull
327 public Builder targetPath(String targetPath) {
328 this.targetPath = targetPath;
329 return this;
330 }
331
332 @Nonnull
333 public Builder filtering(String filtering) {
334 this.filtering = filtering;
335 return this;
336 }
337
338 @Nonnull
339 public Builder mergeId(String mergeId) {
340 this.mergeId = mergeId;
341 return this;
342 }
343
344
345 @Nonnull
346 public Builder location(Object key, InputLocation location) {
347 if (location != null) {
348 if (!(this.locations instanceof HashMap)) {
349 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
350 }
351 this.locations.put(key, location);
352 }
353 return this;
354 }
355
356 @Nonnull
357 public Builder importedFrom(InputLocation importedFrom) {
358 this.importedFrom = importedFrom;
359 return this;
360 }
361
362 @Nonnull
363 public Resource build() {
364
365 if (base != null
366 && (includes == null || includes == base.includes)
367 && (excludes == null || excludes == base.excludes)
368 && (directory == null || directory == base.directory)
369 && (targetPath == null || targetPath == base.targetPath)
370 && (filtering == null || filtering == base.filtering)
371 && (mergeId == null || mergeId == base.mergeId)
372 ) {
373 return base;
374 }
375 return new Resource(this);
376 }
377 }
378
379
380
381 public boolean isFiltering() {
382 return (getFiltering() != null) ? Boolean.parseBoolean(getFiltering()) : false;
383 }
384
385
386
387
388
389
390
391 public String toString() {
392 return "Resource {targetPath: " + getTargetPath() + ", filtering: " + isFiltering() + ", " + super.toString() + "}";
393 }
394
395
396 }