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