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             this.systemProperties.putAll( systemProperties );
290         }
291         else
292         {
293             this.systemProperties = null;
294         }
295 
296         return this;
297     }
298 
299     @Override
300     public Properties getUserProperties()
301     {
302         if ( userProperties == null )
303         {
304             userProperties = new Properties();
305         }
306 
307         return userProperties;
308     }
309 
310     @Override
311     public DefaultModelBuildingRequest setUserProperties( Properties userProperties )
312     {
313         if ( userProperties != null )
314         {
315             this.userProperties = new Properties();
316             this.userProperties.putAll( userProperties );
317         }
318         else
319         {
320             this.userProperties = null;
321         }
322 
323         return this;
324     }
325 
326     @Override
327     public Date getBuildStartTime()
328     {
329         return buildStartTime;
330     }
331 
332     @Override
333     public ModelBuildingRequest setBuildStartTime( Date buildStartTime )
334     {
335         this.buildStartTime = buildStartTime;
336 
337         return this;
338     }
339 
340     @Override
341     public ModelResolver getModelResolver()
342     {
343         return this.modelResolver;
344     }
345 
346     @Override
347     public DefaultModelBuildingRequest setModelResolver( ModelResolver modelResolver )
348     {
349         this.modelResolver = modelResolver;
350 
351         return this;
352     }
353 
354     @Override
355     public ModelBuildingListener getModelBuildingListener()
356     {
357         return modelBuildingListener;
358     }
359 
360     @Override
361     public ModelBuildingRequest setModelBuildingListener( ModelBuildingListener modelBuildingListener )
362     {
363         this.modelBuildingListener = modelBuildingListener;
364 
365         return this;
366     }
367 
368     @Override
369     public ModelCache getModelCache()
370     {
371         return this.modelCache;
372     }
373 
374     @Override
375     public DefaultModelBuildingRequest setModelCache( ModelCache modelCache )
376     {
377         this.modelCache = modelCache;
378 
379         return this;
380     }
381 
382     @Override
383     public Model getRawModel()
384     {
385         return rawModel;
386     }
387 
388     @Override
389     public ModelBuildingRequest setRawModel( Model rawModel )
390     {
391         this.rawModel = rawModel;
392         return this;
393     }
394 
395     @Override
396     public WorkspaceModelResolver getWorkspaceModelResolver()
397     {
398         return workspaceResolver;
399     }
400 
401     @Override
402     public ModelBuildingRequest setWorkspaceModelResolver( WorkspaceModelResolver workspaceResolver )
403     {
404         this.workspaceResolver = workspaceResolver;
405         return this;
406     }
407 
408 }