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.sonatype.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 RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
65  
66      public DefaultProjectBuildingRequest()
67      {
68          processPlugins = true;
69          profiles = new ArrayList<Profile>();
70          activeProfileIds = new ArrayList<String>();
71          inactiveProfileIds = new ArrayList<String>();
72          systemProperties = new Properties();
73          userProperties = new Properties();
74          remoteRepositories = new ArrayList<ArtifactRepository>();
75          pluginArtifactRepositories = new ArrayList<ArtifactRepository>();
76      }
77  
78      public DefaultProjectBuildingRequest( ProjectBuildingRequest request )
79      {
80          this();
81          setProcessPlugins( request.isProcessPlugins() );
82          setProfiles( request.getProfiles() );
83          setActiveProfileIds( request.getActiveProfileIds() );
84          setInactiveProfileIds( request.getInactiveProfileIds() );
85          setSystemProperties( request.getSystemProperties() );
86          setUserProperties( request.getUserProperties() );
87          setRemoteRepositories( request.getRemoteRepositories() );
88          setPluginArtifactRepositories( request.getPluginArtifactRepositories() );
89          setRepositorySession( request.getRepositorySession() );
90          setLocalRepository( request.getLocalRepository() );
91          setBuildStartTime( request.getBuildStartTime() );
92          setProject( request.getProject() );
93          setResolveDependencies( request.isResolveDependencies() );
94          setValidationLevel( request.getValidationLevel() );
95      }
96  
97      public MavenProject getProject()
98      {
99          return project;
100     }
101 
102     public void setProject( MavenProject mavenProject )
103     {
104         this.project = mavenProject;
105     }
106 
107     public ProjectBuildingRequest setLocalRepository( ArtifactRepository localRepository )
108     {
109         this.localRepository = localRepository;
110         return this;
111     }
112 
113     public ArtifactRepository getLocalRepository()
114     {
115         return localRepository;
116     }
117 
118     public List<ArtifactRepository> getRemoteRepositories()
119     {
120         return remoteRepositories;
121     }
122 
123     public ProjectBuildingRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
124     {
125         if ( remoteRepositories != null )
126         {
127             this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
128         }
129         else
130         {
131             this.remoteRepositories.clear();
132         }
133 
134         return this;
135     }
136 
137     public List<ArtifactRepository> getPluginArtifactRepositories()
138     {
139         return pluginArtifactRepositories;
140     }
141 
142     public ProjectBuildingRequest setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
143     {
144         if ( pluginArtifactRepositories != null )
145         {
146             this.pluginArtifactRepositories = new ArrayList<ArtifactRepository>( pluginArtifactRepositories );
147         }
148         else
149         {
150             this.pluginArtifactRepositories.clear();
151         }
152 
153         return this;
154     }
155 
156     public Properties getSystemProperties()
157     {
158         return systemProperties;
159     }
160 
161     public ProjectBuildingRequest setSystemProperties( Properties systemProperties )
162     {
163         if ( systemProperties != null )
164         {
165             this.systemProperties = new Properties();
166             this.systemProperties.putAll( systemProperties );
167         }
168         else
169         {
170             this.systemProperties.clear();
171         }
172 
173         return this;
174     }
175 
176     public Properties getUserProperties()
177     {
178         return userProperties;
179     }
180 
181     public ProjectBuildingRequest setUserProperties( Properties userProperties )
182     {
183         if ( userProperties != null )
184         {
185             this.userProperties = new Properties();
186             this.userProperties.putAll( userProperties );
187         }
188         else
189         {
190             this.userProperties.clear();
191         }
192 
193         return this;
194     }
195 
196     public boolean isProcessPlugins()
197     {
198         return processPlugins;
199     }
200 
201     public ProjectBuildingRequest setProcessPlugins( boolean processPlugins )
202     {
203         this.processPlugins = processPlugins;
204         return this;
205     }
206     
207     public ProjectBuildingRequest setResolveDependencies( boolean resolveDependencies )
208     {
209         this.resolveDependencies = resolveDependencies;
210         return this;
211     }
212 
213     public boolean isResolveDependencies()
214     {
215         return resolveDependencies;
216     }
217 
218     public ProjectBuildingRequest setValidationLevel( int validationLevel )
219     {
220         this.validationLevel = validationLevel;
221         return this;
222     }
223 
224     public int getValidationLevel()
225     {
226         return validationLevel;
227     }
228 
229     public List<String> getActiveProfileIds()
230     {
231         return activeProfileIds;
232     }
233 
234     public void setActiveProfileIds( List<String> activeProfileIds )
235     {
236         if ( activeProfileIds != null )
237         {
238             this.activeProfileIds = new ArrayList<String>( activeProfileIds );
239         }
240         else
241         {
242             this.activeProfileIds.clear();
243         }
244     }
245 
246     public List<String> getInactiveProfileIds()
247     {
248         return inactiveProfileIds;
249     }
250 
251     public void setInactiveProfileIds( List<String> inactiveProfileIds )
252     {
253         if ( inactiveProfileIds != null )
254         {
255             this.inactiveProfileIds = new ArrayList<String>( inactiveProfileIds );
256         }
257         else
258         {
259             this.inactiveProfileIds.clear();
260         }
261     }
262 
263     public void setProfiles( List<Profile> profiles )
264     {
265         if ( profiles != null )
266         {
267             this.profiles = new ArrayList<Profile>( profiles );
268         }
269         else
270         {
271             this.profiles.clear();
272         }
273     }
274 
275     public void addProfile( Profile profile )
276     {
277         profiles.add( profile );
278     }
279 
280     public List<Profile> getProfiles()
281     {
282         return profiles;
283     }
284 
285     public Date getBuildStartTime()
286     {
287         return buildStartTime;
288     }
289 
290     public void setBuildStartTime( Date buildStartTime )
291     {
292         this.buildStartTime = buildStartTime;
293     }
294 
295     public RepositorySystemSession getRepositorySession()
296     {
297         return repositorySession;
298     }
299 
300     public DefaultProjectBuildingRequest setRepositorySession( RepositorySystemSession repositorySession )
301     {
302         this.repositorySession = repositorySession;
303         return this;
304     }
305 
306     public DefaultProjectBuildingRequest setRepositoryMerging( RepositoryMerging repositoryMerging )
307     {
308         if ( repositoryMerging == null )
309         {
310             throw new IllegalArgumentException( "repository merge mode not specified" );
311         }
312         this.repositoryMerging = repositoryMerging;
313         return this;
314     }
315 
316     public RepositoryMerging getRepositoryMerging()
317     {
318         return repositoryMerging;
319     }
320 
321 }