001package org.apache.maven.project;
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.util.ArrayList;
023import java.util.Date;
024import java.util.List;
025import java.util.Properties;
026
027import org.apache.maven.artifact.repository.ArtifactRepository;
028import org.apache.maven.model.Profile;
029import org.apache.maven.model.building.ModelBuildingRequest;
030import org.eclipse.aether.RepositorySystemSession;
031
032public class DefaultProjectBuildingRequest
033    implements ProjectBuildingRequest
034{
035
036    private RepositorySystemSession repositorySession;
037
038    private ArtifactRepository localRepository;
039
040    private List<ArtifactRepository> remoteRepositories;
041
042    private List<ArtifactRepository> pluginArtifactRepositories;
043
044    private MavenProject project;
045
046    private int validationLevel = ModelBuildingRequest.VALIDATION_LEVEL_STRICT;
047
048    private boolean processPlugins;
049
050    private List<Profile> profiles;
051
052    private List<String> activeProfileIds;
053
054    private List<String> inactiveProfileIds;
055
056    private Properties systemProperties;
057
058    private Properties userProperties;
059
060    private Date buildStartTime;
061
062    private boolean resolveDependencies;
063
064    private boolean resolveVersionRanges;
065
066    private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
067
068    public DefaultProjectBuildingRequest()
069    {
070        processPlugins = true;
071        profiles = new ArrayList<Profile>();
072        activeProfileIds = new ArrayList<String>();
073        inactiveProfileIds = new ArrayList<String>();
074        systemProperties = new Properties();
075        userProperties = new Properties();
076        remoteRepositories = new ArrayList<ArtifactRepository>();
077        pluginArtifactRepositories = new ArrayList<ArtifactRepository>();
078    }
079
080    public DefaultProjectBuildingRequest( ProjectBuildingRequest request )
081    {
082        this();
083        setProcessPlugins( request.isProcessPlugins() );
084        setProfiles( request.getProfiles() );
085        setActiveProfileIds( request.getActiveProfileIds() );
086        setInactiveProfileIds( request.getInactiveProfileIds() );
087        setSystemProperties( request.getSystemProperties() );
088        setUserProperties( request.getUserProperties() );
089        setRemoteRepositories( request.getRemoteRepositories() );
090        setPluginArtifactRepositories( request.getPluginArtifactRepositories() );
091        setRepositorySession( request.getRepositorySession() );
092        setLocalRepository( request.getLocalRepository() );
093        setBuildStartTime( request.getBuildStartTime() );
094        setProject( request.getProject() );
095        setResolveDependencies( request.isResolveDependencies() );
096        setValidationLevel( request.getValidationLevel() );
097    }
098
099    public MavenProject getProject()
100    {
101        return project;
102    }
103
104    public void setProject( MavenProject mavenProject )
105    {
106        this.project = mavenProject;
107    }
108
109    public ProjectBuildingRequest setLocalRepository( ArtifactRepository localRepository )
110    {
111        this.localRepository = localRepository;
112        return this;
113    }
114
115    public ArtifactRepository getLocalRepository()
116    {
117        return localRepository;
118    }
119
120    public List<ArtifactRepository> getRemoteRepositories()
121    {
122        return remoteRepositories;
123    }
124
125    public ProjectBuildingRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
126    {
127        if ( remoteRepositories != null )
128        {
129            this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
130        }
131        else
132        {
133            this.remoteRepositories.clear();
134        }
135
136        return this;
137    }
138
139    public List<ArtifactRepository> getPluginArtifactRepositories()
140    {
141        return pluginArtifactRepositories;
142    }
143
144    public ProjectBuildingRequest setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
145    {
146        if ( pluginArtifactRepositories != null )
147        {
148            this.pluginArtifactRepositories = new ArrayList<ArtifactRepository>( pluginArtifactRepositories );
149        }
150        else
151        {
152            this.pluginArtifactRepositories.clear();
153        }
154
155        return this;
156    }
157
158    public Properties getSystemProperties()
159    {
160        return systemProperties;
161    }
162
163    public ProjectBuildingRequest setSystemProperties( Properties systemProperties )
164    {
165        if ( systemProperties != null )
166        {
167            this.systemProperties = new Properties();
168            synchronized ( systemProperties )
169            { // avoid concurrentmodification if someone else sets/removes an unrelated system property
170                this.systemProperties.putAll( systemProperties );
171            }
172        }
173        else
174        {
175            this.systemProperties.clear();
176        }
177
178        return this;
179    }
180
181    public Properties getUserProperties()
182    {
183        return userProperties;
184    }
185
186    public ProjectBuildingRequest setUserProperties( Properties userProperties )
187    {
188        if ( userProperties != null )
189        {
190            this.userProperties = new Properties();
191            this.userProperties.putAll( userProperties );
192        }
193        else
194        {
195            this.userProperties.clear();
196        }
197
198        return this;
199    }
200
201    public boolean isProcessPlugins()
202    {
203        return processPlugins;
204    }
205
206    public ProjectBuildingRequest setProcessPlugins( boolean processPlugins )
207    {
208        this.processPlugins = processPlugins;
209        return this;
210    }
211    
212    public ProjectBuildingRequest setResolveDependencies( boolean resolveDependencies )
213    {
214        this.resolveDependencies = resolveDependencies;
215        return this;
216    }
217
218    public boolean isResolveDependencies()
219    {
220        return resolveDependencies;
221    }
222
223    /** @since 3.2.2 */
224    public ProjectBuildingRequest setResolveVersionRanges( boolean value )
225    {
226        this.resolveVersionRanges = value;
227        return this;
228    }
229
230    /** @since 3.2.2 */
231    public boolean isResolveVersionRanges()
232    {
233        return this.resolveVersionRanges;
234    }
235
236    public ProjectBuildingRequest setValidationLevel( int validationLevel )
237    {
238        this.validationLevel = validationLevel;
239        return this;
240    }
241
242    public int getValidationLevel()
243    {
244        return validationLevel;
245    }
246
247    public List<String> getActiveProfileIds()
248    {
249        return activeProfileIds;
250    }
251
252    public void setActiveProfileIds( List<String> activeProfileIds )
253    {
254        if ( activeProfileIds != null )
255        {
256            this.activeProfileIds = new ArrayList<String>( activeProfileIds );
257        }
258        else
259        {
260            this.activeProfileIds.clear();
261        }
262    }
263
264    public List<String> getInactiveProfileIds()
265    {
266        return inactiveProfileIds;
267    }
268
269    public void setInactiveProfileIds( List<String> inactiveProfileIds )
270    {
271        if ( inactiveProfileIds != null )
272        {
273            this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds );
274        }
275        else
276        {
277            this.inactiveProfileIds.clear();
278        }
279    }
280
281    public void setProfiles( List<Profile> profiles )
282    {
283        if ( profiles != null )
284        {
285            this.profiles = new ArrayList<Profile>( profiles );
286        }
287        else
288        {
289            this.profiles.clear();
290        }
291    }
292
293    public void addProfile( Profile profile )
294    {
295        profiles.add( profile );
296    }
297
298    public List<Profile> getProfiles()
299    {
300        return profiles;
301    }
302
303    public Date getBuildStartTime()
304    {
305        return buildStartTime;
306    }
307
308    public void setBuildStartTime( Date buildStartTime )
309    {
310        this.buildStartTime = buildStartTime;
311    }
312
313    public RepositorySystemSession getRepositorySession()
314    {
315        return repositorySession;
316    }
317
318    public DefaultProjectBuildingRequest setRepositorySession( RepositorySystemSession repositorySession )
319    {
320        this.repositorySession = repositorySession;
321        return this;
322    }
323
324    public DefaultProjectBuildingRequest setRepositoryMerging( RepositoryMerging repositoryMerging )
325    {
326        if ( repositoryMerging == null )
327        {
328            throw new IllegalArgumentException( "repository merge mode not specified" );
329        }
330        this.repositoryMerging = repositoryMerging;
331        return this;
332    }
333
334    public RepositoryMerging getRepositoryMerging()
335    {
336        return repositoryMerging;
337    }
338
339}