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