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          setLocationTracking( request.isLocationTracking() );
96          setProfiles( request.getProfiles() );
97          setActiveProfileIds( request.getActiveProfileIds() );
98          setInactiveProfileIds( request.getInactiveProfileIds() );
99          setSystemProperties( request.getSystemProperties() );
100         setUserProperties( request.getUserProperties() );
101         setBuildStartTime( request.getBuildStartTime() );
102         setModelResolver( request.getModelResolver() );
103         setModelBuildingListener( request.getModelBuildingListener() );
104         setModelCache( request.getModelCache() );
105     }
106 
107     @Override
108     public File getPomFile()
109     {
110         return pomFile;
111     }
112 
113     @Override
114     public DefaultModelBuildingRequest setPomFile( File pomFile )
115     {
116         this.pomFile = ( pomFile != null ) ? pomFile.getAbsoluteFile() : null;
117 
118         return this;
119     }
120 
121     @Override
122     public synchronized ModelSource getModelSource()
123     {
124         if ( modelSource == null && pomFile != null )
125         {
126             modelSource = new FileModelSource( pomFile );
127         }
128         return modelSource;
129     }
130 
131     @Override
132     public DefaultModelBuildingRequest setModelSource( ModelSource modelSource )
133     {
134         this.modelSource = modelSource;
135 
136         return this;
137     }
138 
139     @Override
140     public int getValidationLevel()
141     {
142         return validationLevel;
143     }
144 
145     @Override
146     public DefaultModelBuildingRequest setValidationLevel( int validationLevel )
147     {
148         this.validationLevel = validationLevel;
149 
150         return this;
151     }
152 
153     @Override
154     public boolean isProcessPlugins()
155     {
156         return processPlugins;
157     }
158 
159     @Override
160     public DefaultModelBuildingRequest setProcessPlugins( boolean processPlugins )
161     {
162         this.processPlugins = processPlugins;
163 
164         return this;
165     }
166 
167     @Override
168     public boolean isTwoPhaseBuilding()
169     {
170         return twoPhaseBuilding;
171     }
172 
173     @Override
174     public DefaultModelBuildingRequest setTwoPhaseBuilding( boolean twoPhaseBuilding )
175     {
176         this.twoPhaseBuilding = twoPhaseBuilding;
177 
178         return this;
179     }
180 
181     @Override
182     public boolean isLocationTracking()
183     {
184         return locationTracking;
185     }
186 
187     @Override
188     public DefaultModelBuildingRequest setLocationTracking( boolean locationTracking )
189     {
190         this.locationTracking = locationTracking;
191 
192         return this;
193     }
194 
195     @Override
196     public List<Profile> getProfiles()
197     {
198         if ( profiles == null )
199         {
200             profiles = new ArrayList<>();
201         }
202 
203         return profiles;
204     }
205 
206     @Override
207     public DefaultModelBuildingRequest setProfiles( List<Profile> profiles )
208     {
209         if ( profiles != null )
210         {
211             this.profiles = new ArrayList<>( profiles );
212         }
213         else
214         {
215             this.profiles = null;
216         }
217 
218         return this;
219     }
220 
221     @Override
222     public List<String> getActiveProfileIds()
223     {
224         if ( activeProfileIds == null )
225         {
226             activeProfileIds = new ArrayList<>();
227         }
228 
229         return activeProfileIds;
230     }
231 
232     @Override
233     public DefaultModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds )
234     {
235         if ( activeProfileIds != null )
236         {
237             this.activeProfileIds = new ArrayList<>( activeProfileIds );
238         }
239         else
240         {
241             this.activeProfileIds = null;
242         }
243 
244         return this;
245     }
246 
247     @Override
248     public List<String> getInactiveProfileIds()
249     {
250         if ( inactiveProfileIds == null )
251         {
252             inactiveProfileIds = new ArrayList<>();
253         }
254 
255         return inactiveProfileIds;
256     }
257 
258     @Override
259     public DefaultModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds )
260     {
261         if ( inactiveProfileIds != null )
262         {
263             this.inactiveProfileIds = new ArrayList<>( inactiveProfileIds );
264         }
265         else
266         {
267             this.inactiveProfileIds = null;
268         }
269 
270         return this;
271     }
272 
273     @Override
274     public Properties getSystemProperties()
275     {
276         if ( systemProperties == null )
277         {
278             systemProperties = new Properties();
279         }
280 
281         return systemProperties;
282     }
283 
284     @Override
285     public DefaultModelBuildingRequest setSystemProperties( Properties systemProperties )
286     {
287         if ( systemProperties != null )
288         {
289             this.systemProperties = new Properties();
290             synchronized ( systemProperties )
291             { // avoid concurrentmodification if someone else sets/removes an unrelated system property
292                 this.systemProperties.putAll( systemProperties );
293             }
294         }
295         else
296         {
297             this.systemProperties = null;
298         }
299 
300         return this;
301     }
302 
303     @Override
304     public Properties getUserProperties()
305     {
306         if ( userProperties == null )
307         {
308             userProperties = new Properties();
309         }
310 
311         return userProperties;
312     }
313 
314     @Override
315     public DefaultModelBuildingRequest setUserProperties( Properties userProperties )
316     {
317         if ( userProperties != null )
318         {
319             this.userProperties = new Properties();
320             this.userProperties.putAll( userProperties );
321         }
322         else
323         {
324             this.userProperties = null;
325         }
326 
327         return this;
328     }
329 
330     @Override
331     public Date getBuildStartTime()
332     {
333         return buildStartTime;
334     }
335 
336     @Override
337     public ModelBuildingRequest setBuildStartTime( Date buildStartTime )
338     {
339         this.buildStartTime = buildStartTime;
340 
341         return this;
342     }
343 
344     @Override
345     public ModelResolver getModelResolver()
346     {
347         return this.modelResolver;
348     }
349 
350     @Override
351     public DefaultModelBuildingRequest setModelResolver( ModelResolver modelResolver )
352     {
353         this.modelResolver = modelResolver;
354 
355         return this;
356     }
357 
358     @Override
359     public ModelBuildingListener getModelBuildingListener()
360     {
361         return modelBuildingListener;
362     }
363 
364     @Override
365     public ModelBuildingRequest setModelBuildingListener( ModelBuildingListener modelBuildingListener )
366     {
367         this.modelBuildingListener = modelBuildingListener;
368 
369         return this;
370     }
371 
372     @Override
373     public ModelCache getModelCache()
374     {
375         return this.modelCache;
376     }
377 
378     @Override
379     public DefaultModelBuildingRequest setModelCache( ModelCache modelCache )
380     {
381         this.modelCache = modelCache;
382 
383         return this;
384     }
385 
386     @Override
387     public Model getRawModel()
388     {
389         return rawModel;
390     }
391 
392     @Override
393     public ModelBuildingRequest setRawModel( Model rawModel )
394     {
395         this.rawModel = rawModel;
396         return this;
397     }
398 
399     @Override
400     public WorkspaceModelResolver getWorkspaceModelResolver()
401     {
402         return workspaceResolver;
403     }
404 
405     @Override
406     public ModelBuildingRequest setWorkspaceModelResolver( WorkspaceModelResolver workspaceResolver )
407     {
408         this.workspaceResolver = workspaceResolver;
409         return this;
410     }
411 
412 }