View Javadoc
1   package org.apache.maven.project;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Date;
24  import java.util.List;
25  import java.util.Properties;
26  
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.model.Profile;
29  import org.apache.maven.model.building.ModelBuildingRequest;
30  import org.eclipse.aether.RepositorySystemSession;
31  
32  public class DefaultProjectBuildingRequest
33      implements ProjectBuildingRequest
34  {
35  
36      private RepositorySystemSession repositorySession;
37  
38      private ArtifactRepository localRepository;
39  
40      private List<ArtifactRepository> remoteRepositories;
41  
42      private List<ArtifactRepository> pluginArtifactRepositories;
43  
44      private MavenProject project;
45  
46      private int validationLevel = ModelBuildingRequest.VALIDATION_LEVEL_STRICT;
47  
48      private boolean processPlugins;
49  
50      private List<Profile> profiles;
51  
52      private List<String> activeProfileIds;
53  
54      private List<String> inactiveProfileIds;
55  
56      private Properties systemProperties;
57  
58      private Properties userProperties;
59  
60      private Date buildStartTime;
61  
62      private boolean resolveDependencies;
63  
64      private boolean resolveVersionRanges;
65  
66      private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
67  
68      public DefaultProjectBuildingRequest()
69      {
70          processPlugins = true;
71          profiles = new ArrayList<Profile>();
72          activeProfileIds = new ArrayList<String>();
73          inactiveProfileIds = new ArrayList<String>();
74          systemProperties = new Properties();
75          userProperties = new Properties();
76          remoteRepositories = new ArrayList<ArtifactRepository>();
77          pluginArtifactRepositories = new ArrayList<ArtifactRepository>();
78      }
79  
80      public DefaultProjectBuildingRequest( ProjectBuildingRequest request )
81      {
82          this();
83          setProcessPlugins( request.isProcessPlugins() );
84          setProfiles( request.getProfiles() );
85          setActiveProfileIds( request.getActiveProfileIds() );
86          setInactiveProfileIds( request.getInactiveProfileIds() );
87          setSystemProperties( request.getSystemProperties() );
88          setUserProperties( request.getUserProperties() );
89          setRemoteRepositories( request.getRemoteRepositories() );
90          setPluginArtifactRepositories( request.getPluginArtifactRepositories() );
91          setRepositorySession( request.getRepositorySession() );
92          setLocalRepository( request.getLocalRepository() );
93          setBuildStartTime( request.getBuildStartTime() );
94          setProject( request.getProject() );
95          setResolveDependencies( request.isResolveDependencies() );
96          setValidationLevel( request.getValidationLevel() );
97      }
98  
99      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 }