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