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            this.systemProperties.putAll( systemProperties );
169        }
170        else
171        {
172            this.systemProperties.clear();
173        }
174
175        return this;
176    }
177
178    public Properties getUserProperties()
179    {
180        return userProperties;
181    }
182
183    public ProjectBuildingRequest setUserProperties( Properties userProperties )
184    {
185        if ( userProperties != null )
186        {
187            this.userProperties = new Properties();
188            this.userProperties.putAll( userProperties );
189        }
190        else
191        {
192            this.userProperties.clear();
193        }
194
195        return this;
196    }
197
198    public boolean isProcessPlugins()
199    {
200        return processPlugins;
201    }
202
203    public ProjectBuildingRequest setProcessPlugins( boolean processPlugins )
204    {
205        this.processPlugins = processPlugins;
206        return this;
207    }
208    
209    public ProjectBuildingRequest setResolveDependencies( boolean resolveDependencies )
210    {
211        this.resolveDependencies = resolveDependencies;
212        return this;
213    }
214
215    public boolean isResolveDependencies()
216    {
217        return resolveDependencies;
218    }
219
220    /** @since 3.2.2 */
221    public ProjectBuildingRequest setResolveVersionRanges( boolean value )
222    {
223        this.resolveVersionRanges = value;
224        return this;
225    }
226
227    /** @since 3.2.2 */
228    public boolean isResolveVersionRanges()
229    {
230        return this.resolveVersionRanges;
231    }
232
233    public ProjectBuildingRequest setValidationLevel( int validationLevel )
234    {
235        this.validationLevel = validationLevel;
236        return this;
237    }
238
239    public int getValidationLevel()
240    {
241        return validationLevel;
242    }
243
244    public List<String> getActiveProfileIds()
245    {
246        return activeProfileIds;
247    }
248
249    public void setActiveProfileIds( List<String> activeProfileIds )
250    {
251        if ( activeProfileIds != null )
252        {
253            this.activeProfileIds = new ArrayList<String>( activeProfileIds );
254        }
255        else
256        {
257            this.activeProfileIds.clear();
258        }
259    }
260
261    public List<String> getInactiveProfileIds()
262    {
263        return inactiveProfileIds;
264    }
265
266    public void setInactiveProfileIds( List<String> inactiveProfileIds )
267    {
268        if ( inactiveProfileIds != null )
269        {
270            this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds );
271        }
272        else
273        {
274            this.inactiveProfileIds.clear();
275        }
276    }
277
278    public void setProfiles( List<Profile> profiles )
279    {
280        if ( profiles != null )
281        {
282            this.profiles = new ArrayList<Profile>( profiles );
283        }
284        else
285        {
286            this.profiles.clear();
287        }
288    }
289
290    public void addProfile( Profile profile )
291    {
292        profiles.add( profile );
293    }
294
295    public List<Profile> getProfiles()
296    {
297        return profiles;
298    }
299
300    public Date getBuildStartTime()
301    {
302        return buildStartTime;
303    }
304
305    public void setBuildStartTime( Date buildStartTime )
306    {
307        this.buildStartTime = buildStartTime;
308    }
309
310    public RepositorySystemSession getRepositorySession()
311    {
312        return repositorySession;
313    }
314
315    public DefaultProjectBuildingRequest setRepositorySession( RepositorySystemSession repositorySession )
316    {
317        this.repositorySession = repositorySession;
318        return this;
319    }
320
321    public DefaultProjectBuildingRequest setRepositoryMerging( RepositoryMerging repositoryMerging )
322    {
323        if ( repositoryMerging == null )
324        {
325            throw new IllegalArgumentException( "repository merge mode not specified" );
326        }
327        this.repositoryMerging = repositoryMerging;
328        return this;
329    }
330
331    public RepositoryMerging getRepositoryMerging()
332    {
333        return repositoryMerging;
334    }
335
336}