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.util.ArrayList;
23  import java.util.Date;
24  import java.util.List;
25  import java.util.Properties;
26  
27  import org.apache.maven.model.Model;
28  import org.apache.maven.model.Profile;
29  import org.apache.maven.model.resolution.ModelResolver;
30  import org.apache.maven.model.resolution.WorkspaceModelResolver;
31  
32  /**
33   * Collects settings that control building of effective models.
34   *
35   * @deprecated use {@code org.apache.maven.api.services.ModelBuilder} instead
36   */
37  @Deprecated(since = "4.0.0")
38  public class DefaultModelBuildingRequest implements ModelBuildingRequest {
39  
40      private Model rawModel;
41  
42      private File pomFile;
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      /**
75       * Creates an empty request.
76       */
77      public DefaultModelBuildingRequest() {}
78  
79      /**
80       * Creates a shallow copy of the specified request.
81       *
82       * @param request The request to copy, must not be {@code null}.
83       */
84      public DefaultModelBuildingRequest(ModelBuildingRequest request) {
85          setPomFile(request.getPomFile());
86          setModelSource(request.getModelSource());
87          setValidationLevel(request.getValidationLevel());
88          setProcessPlugins(request.isProcessPlugins());
89          setTwoPhaseBuilding(request.isTwoPhaseBuilding());
90          setLocationTracking(request.isLocationTracking());
91          setProfiles(request.getProfiles());
92          setActiveProfileIds(request.getActiveProfileIds());
93          setInactiveProfileIds(request.getInactiveProfileIds());
94          setSystemProperties(request.getSystemProperties());
95          setUserProperties(request.getUserProperties());
96          setBuildStartTime(request.getBuildStartTime());
97          setModelResolver(request.getModelResolver());
98          setModelBuildingListener(request.getModelBuildingListener());
99          setModelCache(request.getModelCache());
100     }
101 
102     @Override
103     public File getPomFile() {
104         return pomFile;
105     }
106 
107     @Override
108     public DefaultModelBuildingRequest setPomFile(File pomFile) {
109         this.pomFile = (pomFile != null) ? pomFile.getAbsoluteFile() : null;
110 
111         return this;
112     }
113 
114     @Override
115     public synchronized ModelSource getModelSource() {
116         if (modelSource == null && pomFile != null) {
117             modelSource = new FileModelSource(pomFile);
118         }
119         return modelSource;
120     }
121 
122     @Override
123     public DefaultModelBuildingRequest setModelSource(ModelSource modelSource) {
124         this.modelSource = modelSource;
125 
126         return this;
127     }
128 
129     @Override
130     public int getValidationLevel() {
131         return validationLevel;
132     }
133 
134     @Override
135     public DefaultModelBuildingRequest setValidationLevel(int validationLevel) {
136         this.validationLevel = validationLevel;
137 
138         return this;
139     }
140 
141     @Override
142     public boolean isProcessPlugins() {
143         return processPlugins;
144     }
145 
146     @Override
147     public DefaultModelBuildingRequest setProcessPlugins(boolean processPlugins) {
148         this.processPlugins = processPlugins;
149 
150         return this;
151     }
152 
153     @Override
154     public boolean isTwoPhaseBuilding() {
155         return twoPhaseBuilding;
156     }
157 
158     @Override
159     public DefaultModelBuildingRequest setTwoPhaseBuilding(boolean twoPhaseBuilding) {
160         this.twoPhaseBuilding = twoPhaseBuilding;
161 
162         return this;
163     }
164 
165     @Override
166     public boolean isLocationTracking() {
167         return locationTracking;
168     }
169 
170     @Override
171     public DefaultModelBuildingRequest setLocationTracking(boolean locationTracking) {
172         this.locationTracking = locationTracking;
173 
174         return this;
175     }
176 
177     @Override
178     public List<Profile> getProfiles() {
179         if (profiles == null) {
180             profiles = new ArrayList<>();
181         }
182 
183         return profiles;
184     }
185 
186     @Override
187     public DefaultModelBuildingRequest setProfiles(List<Profile> profiles) {
188         if (profiles != null) {
189             this.profiles = new ArrayList<>(profiles);
190         } else {
191             this.profiles = null;
192         }
193 
194         return this;
195     }
196 
197     @Override
198     public List<String> getActiveProfileIds() {
199         if (activeProfileIds == null) {
200             activeProfileIds = new ArrayList<>();
201         }
202 
203         return activeProfileIds;
204     }
205 
206     @Override
207     public DefaultModelBuildingRequest setActiveProfileIds(List<String> activeProfileIds) {
208         if (activeProfileIds != null) {
209             this.activeProfileIds = new ArrayList<>(activeProfileIds);
210         } else {
211             this.activeProfileIds = null;
212         }
213 
214         return this;
215     }
216 
217     @Override
218     public List<String> getInactiveProfileIds() {
219         if (inactiveProfileIds == null) {
220             inactiveProfileIds = new ArrayList<>();
221         }
222 
223         return inactiveProfileIds;
224     }
225 
226     @Override
227     public DefaultModelBuildingRequest setInactiveProfileIds(List<String> inactiveProfileIds) {
228         if (inactiveProfileIds != null) {
229             this.inactiveProfileIds = new ArrayList<>(inactiveProfileIds);
230         } else {
231             this.inactiveProfileIds = null;
232         }
233 
234         return this;
235     }
236 
237     @Override
238     public Properties getSystemProperties() {
239         if (systemProperties == null) {
240             systemProperties = new Properties();
241         }
242 
243         return systemProperties;
244     }
245 
246     @Override
247     public DefaultModelBuildingRequest setSystemProperties(Properties systemProperties) {
248         if (systemProperties != null) {
249             this.systemProperties = new Properties();
250             synchronized (
251                     systemProperties) { // avoid concurrentmodification if someone else sets/removes an unrelated system
252                 // property
253                 this.systemProperties.putAll(systemProperties);
254             }
255         } else {
256             this.systemProperties = null;
257         }
258 
259         return this;
260     }
261 
262     @Override
263     public Properties getUserProperties() {
264         if (userProperties == null) {
265             userProperties = new Properties();
266         }
267 
268         return userProperties;
269     }
270 
271     @Override
272     public DefaultModelBuildingRequest setUserProperties(Properties userProperties) {
273         if (userProperties != null) {
274             this.userProperties = new Properties();
275             this.userProperties.putAll(userProperties);
276         } else {
277             this.userProperties = null;
278         }
279 
280         return this;
281     }
282 
283     @Override
284     public Date getBuildStartTime() {
285         return buildStartTime;
286     }
287 
288     @Override
289     public ModelBuildingRequest setBuildStartTime(Date buildStartTime) {
290         this.buildStartTime = buildStartTime;
291 
292         return this;
293     }
294 
295     @Override
296     public ModelResolver getModelResolver() {
297         return this.modelResolver;
298     }
299 
300     @Override
301     public DefaultModelBuildingRequest setModelResolver(ModelResolver modelResolver) {
302         this.modelResolver = modelResolver;
303 
304         return this;
305     }
306 
307     @Override
308     public ModelBuildingListener getModelBuildingListener() {
309         return modelBuildingListener;
310     }
311 
312     @Override
313     public ModelBuildingRequest setModelBuildingListener(ModelBuildingListener modelBuildingListener) {
314         this.modelBuildingListener = modelBuildingListener;
315 
316         return this;
317     }
318 
319     @Override
320     public ModelCache getModelCache() {
321         return this.modelCache;
322     }
323 
324     @Override
325     public DefaultModelBuildingRequest setModelCache(ModelCache modelCache) {
326         this.modelCache = modelCache;
327 
328         return this;
329     }
330 
331     @Override
332     public Model getRawModel() {
333         return rawModel;
334     }
335 
336     @Override
337     public ModelBuildingRequest setRawModel(Model rawModel) {
338         this.rawModel = rawModel;
339         return this;
340     }
341 
342     @Override
343     public WorkspaceModelResolver getWorkspaceModelResolver() {
344         return workspaceResolver;
345     }
346 
347     @Override
348     public ModelBuildingRequest setWorkspaceModelResolver(WorkspaceModelResolver workspaceResolver) {
349         this.workspaceResolver = workspaceResolver;
350         return this;
351     }
352 }