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.Model;
029import org.apache.maven.model.Profile;
030import org.apache.maven.model.resolution.ModelResolver;
031import org.apache.maven.model.resolution.WorkspaceModelResolver;
032
033/**
034 * Collects settings that control building of effective models.
035 *
036 * @author Benjamin Bentmann
037 */
038public class DefaultModelBuildingRequest
039    implements ModelBuildingRequest
040{
041
042    private Model rawModel;
043
044    private File pomFile;
045
046    private ModelSource modelSource;
047
048    private int validationLevel = VALIDATION_LEVEL_STRICT;
049
050    private boolean processPlugins;
051
052    private boolean twoPhaseBuilding;
053
054    private boolean locationTracking;
055
056    private List<Profile> profiles;
057
058    private List<String> activeProfileIds;
059
060    private List<String> inactiveProfileIds;
061
062    private Properties systemProperties;
063
064    private Properties userProperties;
065
066    private Date buildStartTime;
067
068    private ModelResolver modelResolver;
069
070    private ModelBuildingListener modelBuildingListener;
071
072    private ModelCache modelCache;
073
074    private WorkspaceModelResolver workspaceResolver;
075
076    /**
077     * Creates an empty request.
078     */
079    public DefaultModelBuildingRequest()
080    {
081    }
082
083    /**
084     * Creates a shallow copy of the specified request.
085     *
086     * @param request The request to copy, must not be {@code null}.
087     */
088    public DefaultModelBuildingRequest( ModelBuildingRequest request )
089    {
090        setPomFile( request.getPomFile() );
091        setModelSource( request.getModelSource() );
092        setValidationLevel( request.getValidationLevel() );
093        setProcessPlugins( request.isProcessPlugins() );
094        setTwoPhaseBuilding( request.isTwoPhaseBuilding() );
095        setProfiles( request.getProfiles() );
096        setActiveProfileIds( request.getActiveProfileIds() );
097        setInactiveProfileIds( request.getInactiveProfileIds() );
098        setSystemProperties( request.getSystemProperties() );
099        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<Profile>();
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<Profile>( 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<String>();
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<String>( 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<String>();
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<String>( 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}