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