View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * Collects settings that control building of effective models.
35   *
36   * @deprecated use {@link org.apache.maven.api.services.ModelBuilder} instead
37   */
38  @Deprecated(since = "4.0.0")
39  public class DefaultModelBuildingRequest implements ModelBuildingRequest {
40      private Model fileModel;
41  
42      private Path pomPath;
43  
44      private ModelSource modelSource;
45  
46      private int validationLevel = VALIDATION_LEVEL_STRICT;
47  
48      private boolean processPlugins;
49  
50      private boolean twoPhaseBuilding;
51  
52      private boolean locationTracking;
53  
54      private List<Profile> profiles;
55  
56      private List<String> activeProfileIds;
57  
58      private List<String> inactiveProfileIds;
59  
60      private Properties systemProperties;
61  
62      private Properties userProperties;
63  
64      private Date buildStartTime;
65  
66      private ModelResolver modelResolver;
67  
68      private ModelBuildingListener modelBuildingListener;
69  
70      private ModelCache modelCache;
71  
72      private WorkspaceModelResolver workspaceResolver;
73  
74      private TransformerContextBuilder contextBuilder;
75  
76      private Path rootDirectory;
77  
78      /**
79       * Creates an empty request.
80       */
81      public DefaultModelBuildingRequest() {}
82  
83      /**
84       * Creates a shallow copy of the specified request.
85       *
86       * @param request The request to copy, must not be {@code null}.
87       */
88      public DefaultModelBuildingRequest(ModelBuildingRequest request) {
89          setPomPath(request.getPomPath());
90          setModelSource(request.getModelSource());
91          setValidationLevel(request.getValidationLevel());
92          setProcessPlugins(request.isProcessPlugins());
93          setTwoPhaseBuilding(request.isTwoPhaseBuilding());
94          setLocationTracking(request.isLocationTracking());
95          setProfiles(request.getProfiles());
96          setActiveProfileIds(request.getActiveProfileIds());
97          setInactiveProfileIds(request.getInactiveProfileIds());
98          setSystemProperties(request.getSystemProperties());
99          setUserProperties(request.getUserProperties());
100         setBuildStartTime(request.getBuildStartTime());
101         setModelResolver(request.getModelResolver());
102         setModelBuildingListener(request.getModelBuildingListener());
103         setModelCache(request.getModelCache());
104         setWorkspaceModelResolver(request.getWorkspaceModelResolver());
105         setTransformerContextBuilder(request.getTransformerContextBuilder());
106         setRootDirectory(request.getRootDirectory());
107     }
108 
109     @Deprecated
110     @Override
111     public File getPomFile() {
112         return pomPath != null ? pomPath.toFile() : null;
113     }
114 
115     @Override
116     public Path getPomPath() {
117         return pomPath;
118     }
119 
120     @Deprecated
121     @Override
122     public DefaultModelBuildingRequest setPomFile(File pomFile) {
123         this.pomPath = (pomFile != null) ? pomFile.toPath().toAbsolutePath() : null;
124         return this;
125     }
126 
127     @Override
128     public DefaultModelBuildingRequest setPomPath(Path pomPath) {
129         this.pomPath = (pomPath != null) ? pomPath.toAbsolutePath() : null;
130         return this;
131     }
132 
133     @Override
134     public synchronized ModelSource getModelSource() {
135         if (modelSource == null && pomPath != null) {
136             modelSource = new FileModelSource(pomPath);
137         }
138         return modelSource;
139     }
140 
141     @Override
142     public DefaultModelBuildingRequest setModelSource(ModelSource modelSource) {
143         this.modelSource = modelSource;
144 
145         return this;
146     }
147 
148     @Override
149     public int getValidationLevel() {
150         return validationLevel;
151     }
152 
153     @Override
154     public DefaultModelBuildingRequest setValidationLevel(int validationLevel) {
155         this.validationLevel = validationLevel;
156 
157         return this;
158     }
159 
160     @Override
161     public boolean isProcessPlugins() {
162         return processPlugins;
163     }
164 
165     @Override
166     public DefaultModelBuildingRequest setProcessPlugins(boolean processPlugins) {
167         this.processPlugins = processPlugins;
168 
169         return this;
170     }
171 
172     @Override
173     public boolean isTwoPhaseBuilding() {
174         return twoPhaseBuilding;
175     }
176 
177     @Override
178     public DefaultModelBuildingRequest setTwoPhaseBuilding(boolean twoPhaseBuilding) {
179         this.twoPhaseBuilding = twoPhaseBuilding;
180 
181         return this;
182     }
183 
184     @Override
185     public boolean isLocationTracking() {
186         return locationTracking;
187     }
188 
189     @Override
190     public DefaultModelBuildingRequest setLocationTracking(boolean locationTracking) {
191         this.locationTracking = locationTracking;
192 
193         return this;
194     }
195 
196     @Override
197     public List<Profile> getProfiles() {
198         if (profiles == null) {
199             profiles = new ArrayList<>();
200         }
201 
202         return profiles;
203     }
204 
205     @Override
206     public DefaultModelBuildingRequest setProfiles(List<Profile> profiles) {
207         if (profiles != null) {
208             this.profiles = new ArrayList<>(profiles);
209         } else {
210             this.profiles = null;
211         }
212 
213         return this;
214     }
215 
216     @Override
217     public List<String> getActiveProfileIds() {
218         if (activeProfileIds == null) {
219             activeProfileIds = new ArrayList<>();
220         }
221 
222         return activeProfileIds;
223     }
224 
225     @Override
226     public DefaultModelBuildingRequest setActiveProfileIds(List<String> activeProfileIds) {
227         if (activeProfileIds != null) {
228             this.activeProfileIds = new ArrayList<>(activeProfileIds);
229         } else {
230             this.activeProfileIds = null;
231         }
232 
233         return this;
234     }
235 
236     @Override
237     public List<String> getInactiveProfileIds() {
238         if (inactiveProfileIds == null) {
239             inactiveProfileIds = new ArrayList<>();
240         }
241 
242         return inactiveProfileIds;
243     }
244 
245     @Override
246     public DefaultModelBuildingRequest setInactiveProfileIds(List<String> inactiveProfileIds) {
247         if (inactiveProfileIds != null) {
248             this.inactiveProfileIds = new ArrayList<>(inactiveProfileIds);
249         } else {
250             this.inactiveProfileIds = null;
251         }
252 
253         return this;
254     }
255 
256     @Override
257     public Properties getSystemProperties() {
258         if (systemProperties == null) {
259             systemProperties = new Properties();
260         }
261 
262         return systemProperties;
263     }
264 
265     @Override
266     public DefaultModelBuildingRequest setSystemProperties(Properties systemProperties) {
267         if (systemProperties != null) {
268             this.systemProperties = new Properties();
269             // avoid concurrent modification if someone else sets/removes an unrelated system property
270             synchronized (systemProperties) {
271                 this.systemProperties.putAll(systemProperties);
272             }
273         } else {
274             this.systemProperties = null;
275         }
276 
277         return this;
278     }
279 
280     @Override
281     public Properties getUserProperties() {
282         if (userProperties == null) {
283             userProperties = new Properties();
284         }
285 
286         return userProperties;
287     }
288 
289     @Override
290     public DefaultModelBuildingRequest setUserProperties(Properties userProperties) {
291         if (userProperties != null) {
292             this.userProperties = new Properties();
293             this.userProperties.putAll(userProperties);
294         } else {
295             this.userProperties = null;
296         }
297 
298         return this;
299     }
300 
301     @Override
302     public Date getBuildStartTime() {
303         return buildStartTime;
304     }
305 
306     @Override
307     public ModelBuildingRequest setBuildStartTime(Date buildStartTime) {
308         this.buildStartTime = buildStartTime;
309 
310         return this;
311     }
312 
313     @Override
314     public ModelResolver getModelResolver() {
315         return this.modelResolver;
316     }
317 
318     @Override
319     public DefaultModelBuildingRequest setModelResolver(ModelResolver modelResolver) {
320         this.modelResolver = modelResolver;
321 
322         return this;
323     }
324 
325     @Override
326     public ModelBuildingListener getModelBuildingListener() {
327         return modelBuildingListener;
328     }
329 
330     @Override
331     public ModelBuildingRequest setModelBuildingListener(ModelBuildingListener modelBuildingListener) {
332         this.modelBuildingListener = modelBuildingListener;
333 
334         return this;
335     }
336 
337     @Override
338     public ModelCache getModelCache() {
339         return this.modelCache;
340     }
341 
342     @Override
343     public DefaultModelBuildingRequest setModelCache(ModelCache modelCache) {
344         this.modelCache = modelCache;
345 
346         return this;
347     }
348 
349     @Override
350     public Model getFileModel() {
351         return fileModel;
352     }
353 
354     @Override
355     public ModelBuildingRequest setFileModel(Model fileModel) {
356         this.fileModel = fileModel;
357         return this;
358     }
359 
360     @Override
361     public Model getRawModel() {
362         return null;
363     }
364 
365     @Override
366     public ModelBuildingRequest setRawModel(Model rawModel) {
367         return this;
368     }
369 
370     @Override
371     public WorkspaceModelResolver getWorkspaceModelResolver() {
372         return workspaceResolver;
373     }
374 
375     @Override
376     public ModelBuildingRequest setWorkspaceModelResolver(WorkspaceModelResolver workspaceResolver) {
377         this.workspaceResolver = workspaceResolver;
378         return this;
379     }
380 
381     @Override
382     public TransformerContextBuilder getTransformerContextBuilder() {
383         return contextBuilder;
384     }
385 
386     @Override
387     public ModelBuildingRequest setTransformerContextBuilder(TransformerContextBuilder contextBuilder) {
388         this.contextBuilder = contextBuilder;
389         return this;
390     }
391 
392     @Override
393     public Path getRootDirectory() {
394         return rootDirectory;
395     }
396 
397     @Override
398     public ModelBuildingRequest setRootDirectory(Path rootDirectory) {
399         this.rootDirectory = rootDirectory;
400         return this;
401     }
402 }