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