001package org.apache.maven.model.building;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.File;
023import java.util.ArrayList;
024import java.util.Date;
025import java.util.List;
026import java.util.Properties;
027
028import org.apache.maven.model.Profile;
029import org.apache.maven.model.resolution.ModelResolver;
030
031/**
032 * Collects settings that control building of effective models.
033 * 
034 * @author Benjamin Bentmann
035 */
036public class DefaultModelBuildingRequest
037    implements ModelBuildingRequest
038{
039
040    private File pomFile;
041
042    private ModelSource modelSource;
043
044    private int validationLevel = VALIDATION_LEVEL_STRICT;
045
046    private boolean processPlugins;
047
048    private boolean twoPhaseBuilding;
049
050    private boolean locationTracking;
051
052    private List<Profile> profiles;
053
054    private List<String> activeProfileIds;
055
056    private List<String> inactiveProfileIds;
057
058    private Properties systemProperties;
059
060    private Properties userProperties;
061
062    private Date buildStartTime;
063
064    private ModelResolver modelResolver;
065
066    private ModelBuildingListener modelBuildingListener;
067
068    private ModelCache modelCache;
069
070    /**
071     * Creates an empty request.
072     */
073    public DefaultModelBuildingRequest()
074    {
075    }
076
077    /**
078     * Creates a shallow copy of the specified request.
079     * 
080     * @param request The request to copy, must not be {@code null}.
081     */
082    public DefaultModelBuildingRequest( ModelBuildingRequest request )
083    {
084        setPomFile( request.getPomFile() );
085        setModelSource( request.getModelSource() );
086        setValidationLevel( request.getValidationLevel() );
087        setProcessPlugins( request.isProcessPlugins() );
088        setTwoPhaseBuilding( request.isTwoPhaseBuilding() );
089        setProfiles( request.getProfiles() );
090        setActiveProfileIds( request.getActiveProfileIds() );
091        setInactiveProfileIds( request.getInactiveProfileIds() );
092        setSystemProperties( request.getSystemProperties() );
093        setUserProperties( request.getUserProperties() );
094        setBuildStartTime( request.getBuildStartTime() );
095        setModelResolver( request.getModelResolver() );
096        setModelBuildingListener( request.getModelBuildingListener() );
097        setModelCache( request.getModelCache() );
098    }
099
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}