1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.api.services;
20
21 import java.nio.file.Path;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.maven.api.Session;
27 import org.apache.maven.api.annotations.Experimental;
28 import org.apache.maven.api.annotations.Immutable;
29 import org.apache.maven.api.annotations.Nonnull;
30 import org.apache.maven.api.annotations.NotThreadSafe;
31 import org.apache.maven.api.annotations.Nullable;
32 import org.apache.maven.api.model.Profile;
33
34 import static org.apache.maven.api.services.BaseRequest.nonNull;
35
36
37
38
39
40
41
42
43
44
45 @Experimental
46 @Immutable
47 public interface ModelBuilderRequest {
48
49
50
51
52
53 int VALIDATION_LEVEL_MINIMAL = 0;
54
55
56
57
58
59 int VALIDATION_LEVEL_MAVEN_2_0 = 20;
60
61
62
63
64 int VALIDATION_LEVEL_MAVEN_3_0 = 30;
65
66
67
68
69 int VALIDATION_LEVEL_MAVEN_3_1 = 31;
70
71
72
73
74 int VALIDATION_LEVEL_MAVEN_4_0 = 40;
75
76
77
78
79 int VALIDATION_LEVEL_STRICT = VALIDATION_LEVEL_MAVEN_4_0;
80
81 @Nonnull
82 Session getSession();
83
84 @Nonnull
85 ModelSource getSource();
86
87 int getValidationLevel();
88
89 boolean isTwoPhaseBuilding();
90
91 boolean isLocationTracking();
92
93
94
95
96
97
98
99 boolean isProjectBuild();
100
101
102
103
104
105
106
107
108 boolean isProcessPlugins();
109
110
111
112
113
114 @Nonnull
115 Collection<Profile> getProfiles();
116
117
118
119
120 @Nonnull
121 List<String> getActiveProfileIds();
122
123
124
125
126 @Nonnull
127 List<String> getInactiveProfileIds();
128
129
130
131
132 @Nonnull
133 Map<String, String> getSystemProperties();
134
135
136
137
138
139 @Nonnull
140 Map<String, String> getUserProperties();
141
142 @Nonnull
143 ModelResolver getModelResolver();
144
145 @Nonnull
146 ModelRepositoryHolder getModelRepositoryHolder();
147
148 @Nullable
149 ModelCache getModelCache();
150
151 @Nullable
152 Object getListener();
153
154 @Nullable
155 ModelBuilderResult getInterimResult();
156
157 @Nullable
158 ModelTransformerContextBuilder getTransformerContextBuilder();
159
160 @Nonnull
161 static ModelBuilderRequest build(@Nonnull ModelBuilderRequest request, @Nonnull ModelSource source) {
162 return builder(nonNull(request, "request cannot be null"))
163 .source(nonNull(source, "source cannot be null"))
164 .build();
165 }
166
167 @Nonnull
168 static ModelBuilderRequest build(@Nonnull Session session, @Nonnull ModelSource source) {
169 return builder()
170 .session(nonNull(session, "session cannot be null"))
171 .source(nonNull(source, "source cannot be null"))
172 .build();
173 }
174
175 @Nonnull
176 static ModelBuilderRequest build(@Nonnull Session session, @Nonnull Path path) {
177 return builder()
178 .session(nonNull(session, "session cannot be null"))
179 .source(ModelSource.fromPath(path))
180 .build();
181 }
182
183 @Nonnull
184 static ModelBuilderRequestBuilder builder() {
185 return new ModelBuilderRequestBuilder();
186 }
187
188 @Nonnull
189 static ModelBuilderRequestBuilder builder(ModelBuilderRequest request) {
190 return new ModelBuilderRequestBuilder(request);
191 }
192
193 @NotThreadSafe
194 class ModelBuilderRequestBuilder {
195 Session session;
196 int validationLevel;
197 boolean locationTracking;
198 boolean twoPhaseBuilding;
199 ModelSource source;
200 boolean projectBuild;
201 boolean processPlugins = true;
202 Collection<Profile> profiles;
203 List<String> activeProfileIds;
204 List<String> inactiveProfileIds;
205 Map<String, String> systemProperties;
206 Map<String, String> userProperties;
207 ModelResolver modelResolver;
208 ModelRepositoryHolder modelRepositoryHolder;
209 ModelCache modelCache;
210 Object listener;
211 ModelBuilderResult interimResult;
212 ModelTransformerContextBuilder transformerContextBuilder;
213
214 ModelBuilderRequestBuilder() {}
215
216 ModelBuilderRequestBuilder(ModelBuilderRequest request) {
217 this.session = request.getSession();
218 this.validationLevel = request.getValidationLevel();
219 this.locationTracking = request.isLocationTracking();
220 this.twoPhaseBuilding = request.isTwoPhaseBuilding();
221 this.source = request.getSource();
222 this.projectBuild = request.isProjectBuild();
223 this.processPlugins = request.isProcessPlugins();
224 this.profiles = request.getProfiles();
225 this.activeProfileIds = request.getActiveProfileIds();
226 this.inactiveProfileIds = request.getInactiveProfileIds();
227 this.systemProperties = request.getSystemProperties();
228 this.userProperties = request.getUserProperties();
229 this.modelResolver = request.getModelResolver();
230 this.modelRepositoryHolder = request.getModelRepositoryHolder();
231 this.modelCache = request.getModelCache();
232 this.listener = request.getListener();
233 this.interimResult = request.getInterimResult();
234 this.transformerContextBuilder = request.getTransformerContextBuilder();
235 }
236
237 public ModelBuilderRequestBuilder session(Session session) {
238 this.session = session;
239 return this;
240 }
241
242 public ModelBuilderRequestBuilder validationLevel(int validationLevel) {
243 this.validationLevel = validationLevel;
244 return this;
245 }
246
247 public ModelBuilderRequestBuilder twoPhaseBuilding(boolean twoPhaseBuilding) {
248 this.twoPhaseBuilding = twoPhaseBuilding;
249 return this;
250 }
251
252 public ModelBuilderRequestBuilder locationTracking(boolean locationTracking) {
253 this.locationTracking = locationTracking;
254 return this;
255 }
256
257 public ModelBuilderRequestBuilder source(ModelSource source) {
258 this.source = source;
259 return this;
260 }
261
262 public ModelBuilderRequestBuilder projectBuild(boolean projectBuild) {
263 this.projectBuild = projectBuild;
264 return this;
265 }
266
267 public ModelBuilderRequestBuilder processPlugins(boolean processPlugins) {
268 this.processPlugins = processPlugins;
269 return this;
270 }
271
272 public ModelBuilderRequestBuilder profiles(List<Profile> profiles) {
273 this.profiles = profiles;
274 return this;
275 }
276
277 public ModelBuilderRequestBuilder activeProfileIds(List<String> activeProfileIds) {
278 this.activeProfileIds = activeProfileIds;
279 return this;
280 }
281
282 public ModelBuilderRequestBuilder inactiveProfileIds(List<String> inactiveProfileIds) {
283 this.inactiveProfileIds = inactiveProfileIds;
284 return this;
285 }
286
287 public ModelBuilderRequestBuilder systemProperties(Map<String, String> systemProperties) {
288 this.systemProperties = systemProperties;
289 return this;
290 }
291
292 public ModelBuilderRequestBuilder userProperties(Map<String, String> userProperties) {
293 this.userProperties = userProperties;
294 return this;
295 }
296
297 public ModelBuilderRequestBuilder modelResolver(ModelResolver modelResolver) {
298 this.modelResolver = modelResolver;
299 return this;
300 }
301
302 public ModelBuilderRequestBuilder modelRepositoryHolder(ModelRepositoryHolder modelRepositoryHolder) {
303 this.modelRepositoryHolder = modelRepositoryHolder;
304 return this;
305 }
306
307 public ModelBuilderRequestBuilder modelCache(ModelCache modelCache) {
308 this.modelCache = modelCache;
309 return this;
310 }
311
312 public ModelBuilderRequestBuilder listener(Object listener) {
313 this.listener = listener;
314 return this;
315 }
316
317 public ModelBuilderRequestBuilder interimResult(ModelBuilderResult interimResult) {
318 this.interimResult = interimResult;
319 return this;
320 }
321
322 public ModelBuilderRequestBuilder transformerContextBuilder(
323 ModelTransformerContextBuilder transformerContextBuilder) {
324 this.transformerContextBuilder = transformerContextBuilder;
325 return this;
326 }
327
328 public ModelBuilderRequest build() {
329 return new DefaultModelBuilderRequest(
330 session,
331 validationLevel,
332 locationTracking,
333 twoPhaseBuilding,
334 source,
335 projectBuild,
336 processPlugins,
337 profiles,
338 activeProfileIds,
339 inactiveProfileIds,
340 systemProperties,
341 userProperties,
342 modelResolver,
343 modelRepositoryHolder,
344 modelCache,
345 listener,
346 interimResult,
347 transformerContextBuilder);
348 }
349
350 private static class DefaultModelBuilderRequest extends BaseRequest implements ModelBuilderRequest {
351 private final int validationLevel;
352 private final boolean locationTracking;
353 private final boolean twoPhaseBuilding;
354 private final ModelSource source;
355 private final boolean projectBuild;
356 private final boolean processPlugins;
357 private final Collection<Profile> profiles;
358 private final List<String> activeProfileIds;
359 private final List<String> inactiveProfileIds;
360 private final Map<String, String> systemProperties;
361 private final Map<String, String> userProperties;
362 private final ModelResolver modelResolver;
363 private final ModelRepositoryHolder modelRepositoryHolder;
364 private final ModelCache modelCache;
365 private final Object listener;
366 private final ModelBuilderResult interimResult;
367 private final ModelTransformerContextBuilder transformerContextBuilder;
368
369 @SuppressWarnings("checkstyle:ParameterNumber")
370 DefaultModelBuilderRequest(
371 @Nonnull Session session,
372 int validationLevel,
373 boolean locationTracking,
374 boolean twoPhaseBuilding,
375 @Nonnull ModelSource source,
376 boolean projectBuild,
377 boolean processPlugins,
378 Collection<Profile> profiles,
379 List<String> activeProfileIds,
380 List<String> inactiveProfileIds,
381 Map<String, String> systemProperties,
382 Map<String, String> userProperties,
383 ModelResolver modelResolver,
384 ModelRepositoryHolder modelRepositoryHolder,
385 ModelCache modelCache,
386 Object listener,
387 ModelBuilderResult interimResult,
388 ModelTransformerContextBuilder transformerContextBuilder) {
389 super(session);
390 this.validationLevel = validationLevel;
391 this.locationTracking = locationTracking;
392 this.twoPhaseBuilding = twoPhaseBuilding;
393 this.source = source;
394 this.projectBuild = projectBuild;
395 this.processPlugins = processPlugins;
396 this.profiles = profiles != null ? List.copyOf(profiles) : List.of();
397 this.activeProfileIds = activeProfileIds != null ? List.copyOf(activeProfileIds) : List.of();
398 this.inactiveProfileIds = inactiveProfileIds != null ? List.copyOf(inactiveProfileIds) : List.of();
399 this.systemProperties =
400 systemProperties != null ? Map.copyOf(systemProperties) : session.getSystemProperties();
401 this.userProperties = userProperties != null ? Map.copyOf(userProperties) : session.getUserProperties();
402 this.modelResolver = modelResolver;
403 this.modelRepositoryHolder = modelRepositoryHolder;
404 this.modelCache = modelCache;
405 this.listener = listener;
406 this.interimResult = interimResult;
407 this.transformerContextBuilder = transformerContextBuilder;
408 }
409
410 @Override
411 public int getValidationLevel() {
412 return validationLevel;
413 }
414
415 @Override
416 public boolean isTwoPhaseBuilding() {
417 return twoPhaseBuilding;
418 }
419
420 @Override
421 public boolean isLocationTracking() {
422 return locationTracking;
423 }
424
425 @Nonnull
426 @Override
427 public ModelSource getSource() {
428 return source;
429 }
430
431 public boolean isProjectBuild() {
432 return projectBuild;
433 }
434
435 @Override
436 public boolean isProcessPlugins() {
437 return processPlugins;
438 }
439
440 @Override
441 public Collection<Profile> getProfiles() {
442 return profiles;
443 }
444
445 @Override
446 public List<String> getActiveProfileIds() {
447 return activeProfileIds;
448 }
449
450 @Override
451 public List<String> getInactiveProfileIds() {
452 return inactiveProfileIds;
453 }
454
455 @Override
456 public Map<String, String> getSystemProperties() {
457 return systemProperties;
458 }
459
460 @Override
461 public Map<String, String> getUserProperties() {
462 return userProperties;
463 }
464
465 @Override
466 public ModelResolver getModelResolver() {
467 return modelResolver;
468 }
469
470 @Override
471 public ModelRepositoryHolder getModelRepositoryHolder() {
472 return modelRepositoryHolder;
473 }
474
475 @Override
476 public ModelCache getModelCache() {
477 return modelCache;
478 }
479
480 public Object getListener() {
481 return listener;
482 }
483
484 @Override
485 public ModelBuilderResult getInterimResult() {
486 return interimResult;
487 }
488
489 public ModelTransformerContextBuilder getTransformerContextBuilder() {
490 return transformerContextBuilder;
491 }
492 }
493 }
494 }