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