001    package 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    
022    import java.io.File;
023    import java.util.ArrayList;
024    import java.util.Date;
025    import java.util.List;
026    import java.util.Properties;
027    
028    import org.apache.maven.model.Profile;
029    import org.apache.maven.model.resolution.ModelResolver;
030    
031    /**
032     * Collects settings that control building of effective models.
033     * 
034     * @author Benjamin Bentmann
035     */
036    public 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 ModelSource getModelSource()
113        {
114            return modelSource;
115        }
116    
117        public DefaultModelBuildingRequest setModelSource( ModelSource modelSource )
118        {
119            this.modelSource = modelSource;
120    
121            return this;
122        }
123    
124        public int getValidationLevel()
125        {
126            return validationLevel;
127        }
128    
129        public DefaultModelBuildingRequest setValidationLevel( int validationLevel )
130        {
131            this.validationLevel = validationLevel;
132    
133            return this;
134        }
135    
136        public boolean isProcessPlugins()
137        {
138            return processPlugins;
139        }
140    
141        public DefaultModelBuildingRequest setProcessPlugins( boolean processPlugins )
142        {
143            this.processPlugins = processPlugins;
144    
145            return this;
146        }
147    
148        public boolean isTwoPhaseBuilding()
149        {
150            return twoPhaseBuilding;
151        }
152    
153        public DefaultModelBuildingRequest setTwoPhaseBuilding( boolean twoPhaseBuilding )
154        {
155            this.twoPhaseBuilding = twoPhaseBuilding;
156    
157            return this;
158        }
159    
160        public boolean isLocationTracking()
161        {
162            return locationTracking;
163        }
164    
165        public DefaultModelBuildingRequest setLocationTracking( boolean locationTracking )
166        {
167            this.locationTracking = locationTracking;
168    
169            return this;
170        }
171    
172        public List<Profile> getProfiles()
173        {
174            if ( profiles == null )
175            {
176                profiles = new ArrayList<Profile>();
177            }
178    
179            return profiles;
180        }
181    
182        public DefaultModelBuildingRequest setProfiles( List<Profile> profiles )
183        {
184            if ( profiles != null )
185            {
186                this.profiles = new ArrayList<Profile>( profiles );
187            }
188            else
189            {
190                this.profiles = null;
191            }
192    
193            return this;
194        }
195    
196        public List<String> getActiveProfileIds()
197        {
198            if ( activeProfileIds == null )
199            {
200                activeProfileIds = new ArrayList<String>();
201            }
202    
203            return activeProfileIds;
204        }
205    
206        public DefaultModelBuildingRequest setActiveProfileIds( List<String> activeProfileIds )
207        {
208            if ( activeProfileIds != null )
209            {
210                this.activeProfileIds = new ArrayList<String>( activeProfileIds );
211            }
212            else
213            {
214                this.activeProfileIds = null;
215            }
216    
217            return this;
218        }
219    
220        public List<String> getInactiveProfileIds()
221        {
222            if ( inactiveProfileIds == null )
223            {
224                inactiveProfileIds = new ArrayList<String>();
225            }
226    
227            return inactiveProfileIds;
228        }
229    
230        public DefaultModelBuildingRequest setInactiveProfileIds( List<String> inactiveProfileIds )
231        {
232            if ( inactiveProfileIds != null )
233            {
234                this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds );
235            }
236            else
237            {
238                this.inactiveProfileIds = null;
239            }
240    
241            return this;
242        }
243    
244        public Properties getSystemProperties()
245        {
246            if ( systemProperties == null )
247            {
248                systemProperties = new Properties();
249            }
250    
251            return systemProperties;
252        }
253    
254        public DefaultModelBuildingRequest setSystemProperties( Properties systemProperties )
255        {
256            if ( systemProperties != null )
257            {
258                this.systemProperties = new Properties();
259                this.systemProperties.putAll( systemProperties );
260            }
261            else
262            {
263                this.systemProperties = null;
264            }
265    
266            return this;
267        }
268    
269        public Properties getUserProperties()
270        {
271            if ( userProperties == null )
272            {
273                userProperties = new Properties();
274            }
275    
276            return userProperties;
277        }
278    
279        public DefaultModelBuildingRequest setUserProperties( Properties userProperties )
280        {
281            if ( userProperties != null )
282            {
283                this.userProperties = new Properties();
284                this.userProperties.putAll( userProperties );
285            }
286            else
287            {
288                this.userProperties = null;
289            }
290    
291            return this;
292        }
293    
294        public Date getBuildStartTime()
295        {
296            return buildStartTime;
297        }
298    
299        public ModelBuildingRequest setBuildStartTime( Date buildStartTime )
300        {
301            this.buildStartTime = buildStartTime;
302    
303            return this;
304        }
305    
306        public ModelResolver getModelResolver()
307        {
308            return this.modelResolver;
309        }
310    
311        public DefaultModelBuildingRequest setModelResolver( ModelResolver modelResolver )
312        {
313            this.modelResolver = modelResolver;
314    
315            return this;
316        }
317    
318        public ModelBuildingListener getModelBuildingListener()
319        {
320            return modelBuildingListener;
321        }
322    
323        public ModelBuildingRequest setModelBuildingListener( ModelBuildingListener modelBuildingListener )
324        {
325            this.modelBuildingListener = modelBuildingListener;
326    
327            return this;
328        }
329    
330        public ModelCache getModelCache()
331        {
332            return this.modelCache;
333        }
334    
335        public DefaultModelBuildingRequest setModelCache( ModelCache modelCache )
336        {
337            this.modelCache = modelCache;
338    
339            return this;
340        }
341    
342    }