1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.building;
20
21 import java.io.File;
22 import java.nio.file.Path;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.Properties;
27
28 import org.apache.maven.model.Model;
29 import org.apache.maven.model.Profile;
30 import org.apache.maven.model.resolution.ModelResolver;
31 import org.apache.maven.model.resolution.WorkspaceModelResolver;
32
33
34
35
36
37 public class DefaultModelBuildingRequest implements ModelBuildingRequest {
38 private Model fileModel;
39
40 private Path pomPath;
41
42 private ModelSource modelSource;
43
44 private int validationLevel = VALIDATION_LEVEL_STRICT;
45
46 private boolean processPlugins;
47
48 private boolean twoPhaseBuilding;
49
50 private boolean locationTracking;
51
52 private List<Profile> profiles;
53
54 private List<String> activeProfileIds;
55
56 private List<String> inactiveProfileIds;
57
58 private Properties systemProperties;
59
60 private Properties userProperties;
61
62 private Date buildStartTime;
63
64 private ModelResolver modelResolver;
65
66 private ModelBuildingListener modelBuildingListener;
67
68 private ModelCache modelCache;
69
70 private WorkspaceModelResolver workspaceResolver;
71
72 private TransformerContextBuilder contextBuilder;
73
74 private Path rootDirectory;
75
76
77
78
79 public DefaultModelBuildingRequest() {}
80
81
82
83
84
85
86 public DefaultModelBuildingRequest(ModelBuildingRequest request) {
87 setPomPath(request.getPomPath());
88 setModelSource(request.getModelSource());
89 setValidationLevel(request.getValidationLevel());
90 setProcessPlugins(request.isProcessPlugins());
91 setTwoPhaseBuilding(request.isTwoPhaseBuilding());
92 setLocationTracking(request.isLocationTracking());
93 setProfiles(request.getProfiles());
94 setActiveProfileIds(request.getActiveProfileIds());
95 setInactiveProfileIds(request.getInactiveProfileIds());
96 setSystemProperties(request.getSystemProperties());
97 setUserProperties(request.getUserProperties());
98 setBuildStartTime(request.getBuildStartTime());
99 setModelResolver(request.getModelResolver());
100 setModelBuildingListener(request.getModelBuildingListener());
101 setModelCache(request.getModelCache());
102 setWorkspaceModelResolver(request.getWorkspaceModelResolver());
103 setTransformerContextBuilder(request.getTransformerContextBuilder());
104 setRootDirectory(request.getRootDirectory());
105 }
106
107 @Deprecated
108 @Override
109 public File getPomFile() {
110 return pomPath != null ? pomPath.toFile() : null;
111 }
112
113 @Override
114 public Path getPomPath() {
115 return pomPath;
116 }
117
118 @Deprecated
119 @Override
120 public DefaultModelBuildingRequest setPomFile(File pomFile) {
121 this.pomPath = (pomFile != null) ? pomFile.toPath().toAbsolutePath() : null;
122 return this;
123 }
124
125 @Override
126 public DefaultModelBuildingRequest setPomPath(Path pomPath) {
127 this.pomPath = (pomPath != null) ? pomPath.toAbsolutePath() : null;
128 return this;
129 }
130
131 @Override
132 public synchronized ModelSource getModelSource() {
133 if (modelSource == null && pomPath != null) {
134 modelSource = new FileModelSource(pomPath);
135 }
136 return modelSource;
137 }
138
139 @Override
140 public DefaultModelBuildingRequest setModelSource(ModelSource modelSource) {
141 this.modelSource = modelSource;
142
143 return this;
144 }
145
146 @Override
147 public int getValidationLevel() {
148 return validationLevel;
149 }
150
151 @Override
152 public DefaultModelBuildingRequest setValidationLevel(int validationLevel) {
153 this.validationLevel = validationLevel;
154
155 return this;
156 }
157
158 @Override
159 public boolean isProcessPlugins() {
160 return processPlugins;
161 }
162
163 @Override
164 public DefaultModelBuildingRequest setProcessPlugins(boolean processPlugins) {
165 this.processPlugins = processPlugins;
166
167 return this;
168 }
169
170 @Override
171 public boolean isTwoPhaseBuilding() {
172 return twoPhaseBuilding;
173 }
174
175 @Override
176 public DefaultModelBuildingRequest setTwoPhaseBuilding(boolean twoPhaseBuilding) {
177 this.twoPhaseBuilding = twoPhaseBuilding;
178
179 return this;
180 }
181
182 @Override
183 public boolean isLocationTracking() {
184 return locationTracking;
185 }
186
187 @Override
188 public DefaultModelBuildingRequest setLocationTracking(boolean locationTracking) {
189 this.locationTracking = locationTracking;
190
191 return this;
192 }
193
194 @Override
195 public List<Profile> getProfiles() {
196 if (profiles == null) {
197 profiles = new ArrayList<>();
198 }
199
200 return profiles;
201 }
202
203 @Override
204 public DefaultModelBuildingRequest setProfiles(List<Profile> profiles) {
205 if (profiles != null) {
206 this.profiles = new ArrayList<>(profiles);
207 } else {
208 this.profiles = null;
209 }
210
211 return this;
212 }
213
214 @Override
215 public List<String> getActiveProfileIds() {
216 if (activeProfileIds == null) {
217 activeProfileIds = new ArrayList<>();
218 }
219
220 return activeProfileIds;
221 }
222
223 @Override
224 public DefaultModelBuildingRequest setActiveProfileIds(List<String> activeProfileIds) {
225 if (activeProfileIds != null) {
226 this.activeProfileIds = new ArrayList<>(activeProfileIds);
227 } else {
228 this.activeProfileIds = null;
229 }
230
231 return this;
232 }
233
234 @Override
235 public List<String> getInactiveProfileIds() {
236 if (inactiveProfileIds == null) {
237 inactiveProfileIds = new ArrayList<>();
238 }
239
240 return inactiveProfileIds;
241 }
242
243 @Override
244 public DefaultModelBuildingRequest setInactiveProfileIds(List<String> inactiveProfileIds) {
245 if (inactiveProfileIds != null) {
246 this.inactiveProfileIds = new ArrayList<>(inactiveProfileIds);
247 } else {
248 this.inactiveProfileIds = null;
249 }
250
251 return this;
252 }
253
254 @Override
255 public Properties getSystemProperties() {
256 if (systemProperties == null) {
257 systemProperties = new Properties();
258 }
259
260 return systemProperties;
261 }
262
263 @Override
264 public DefaultModelBuildingRequest setSystemProperties(Properties systemProperties) {
265 if (systemProperties != null) {
266 this.systemProperties = new Properties();
267
268 synchronized (systemProperties) {
269 this.systemProperties.putAll(systemProperties);
270 }
271 } else {
272 this.systemProperties = null;
273 }
274
275 return this;
276 }
277
278 @Override
279 public Properties getUserProperties() {
280 if (userProperties == null) {
281 userProperties = new Properties();
282 }
283
284 return userProperties;
285 }
286
287 @Override
288 public DefaultModelBuildingRequest setUserProperties(Properties userProperties) {
289 if (userProperties != null) {
290 this.userProperties = new Properties();
291 this.userProperties.putAll(userProperties);
292 } else {
293 this.userProperties = null;
294 }
295
296 return this;
297 }
298
299 @Override
300 public Date getBuildStartTime() {
301 return buildStartTime;
302 }
303
304 @Override
305 public ModelBuildingRequest setBuildStartTime(Date buildStartTime) {
306 this.buildStartTime = buildStartTime;
307
308 return this;
309 }
310
311 @Override
312 public ModelResolver getModelResolver() {
313 return this.modelResolver;
314 }
315
316 @Override
317 public DefaultModelBuildingRequest setModelResolver(ModelResolver modelResolver) {
318 this.modelResolver = modelResolver;
319
320 return this;
321 }
322
323 @Override
324 public ModelBuildingListener getModelBuildingListener() {
325 return modelBuildingListener;
326 }
327
328 @Override
329 public ModelBuildingRequest setModelBuildingListener(ModelBuildingListener modelBuildingListener) {
330 this.modelBuildingListener = modelBuildingListener;
331
332 return this;
333 }
334
335 @Override
336 public ModelCache getModelCache() {
337 return this.modelCache;
338 }
339
340 @Override
341 public DefaultModelBuildingRequest setModelCache(ModelCache modelCache) {
342 this.modelCache = modelCache;
343
344 return this;
345 }
346
347 @Override
348 public Model getFileModel() {
349 return fileModel;
350 }
351
352 @Override
353 public ModelBuildingRequest setFileModel(Model fileModel) {
354 this.fileModel = fileModel;
355 return this;
356 }
357
358 @Override
359 public Model getRawModel() {
360 return null;
361 }
362
363 @Override
364 public ModelBuildingRequest setRawModel(Model rawModel) {
365 return this;
366 }
367
368 @Override
369 public WorkspaceModelResolver getWorkspaceModelResolver() {
370 return workspaceResolver;
371 }
372
373 @Override
374 public ModelBuildingRequest setWorkspaceModelResolver(WorkspaceModelResolver workspaceResolver) {
375 this.workspaceResolver = workspaceResolver;
376 return this;
377 }
378
379 @Override
380 public TransformerContextBuilder getTransformerContextBuilder() {
381 return contextBuilder;
382 }
383
384 @Override
385 public ModelBuildingRequest setTransformerContextBuilder(TransformerContextBuilder contextBuilder) {
386 this.contextBuilder = contextBuilder;
387 return this;
388 }
389
390 @Override
391 public Path getRootDirectory() {
392 return rootDirectory;
393 }
394
395 @Override
396 public ModelBuildingRequest setRootDirectory(Path rootDirectory) {
397 this.rootDirectory = rootDirectory;
398 return this;
399 }
400 }