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.commons.lang3.Validate;
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.model.Profile;
30  import org.apache.maven.model.building.ModelBuildingRequest;
31  import org.apache.maven.properties.internal.SystemProperties;
32  import org.eclipse.aether.RepositorySystemSession;
33  
34  public class DefaultProjectBuildingRequest
35      implements ProjectBuildingRequest
36  {
37  
38      private RepositorySystemSession repositorySession;
39  
40      private ArtifactRepository localRepository;
41  
42      private List<ArtifactRepository> remoteRepositories;
43  
44      private List<ArtifactRepository> pluginArtifactRepositories;
45  
46      private MavenProject project;
47  
48      private int validationLevel = ModelBuildingRequest.VALIDATION_LEVEL_STRICT;
49  
50      private boolean processPlugins;
51  
52      private List<Profile> profiles;
53  
54      private List<String> activeProfileIds;
55  
56      private List<String> inactiveProfileIds;
57  
58      private Properties systemProperties;
59  
60      private Properties userProperties;
61  
62      private Date buildStartTime;
63  
64      private boolean resolveDependencies;
65  
66      @Deprecated
67      private boolean resolveVersionRanges;
68  
69      private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
70  
71      public DefaultProjectBuildingRequest()
72      {
73          processPlugins = true;
74          profiles = new ArrayList<>();
75          activeProfileIds = new ArrayList<>();
76          inactiveProfileIds = new ArrayList<>();
77          systemProperties = new Properties();
78          userProperties = new Properties();
79          remoteRepositories = new ArrayList<>();
80          pluginArtifactRepositories = new ArrayList<>();
81      }
82  
83      public DefaultProjectBuildingRequest( ProjectBuildingRequest request )
84      {
85          this();
86          setProcessPlugins( request.isProcessPlugins() );
87          setProfiles( request.getProfiles() );
88          setActiveProfileIds( request.getActiveProfileIds() );
89          setInactiveProfileIds( request.getInactiveProfileIds() );
90          setSystemProperties( request.getSystemProperties() );
91          setUserProperties( request.getUserProperties() );
92          setRemoteRepositories( request.getRemoteRepositories() );
93          setPluginArtifactRepositories( request.getPluginArtifactRepositories() );
94          setRepositorySession( request.getRepositorySession() );
95          setLocalRepository( request.getLocalRepository() );
96          setBuildStartTime( request.getBuildStartTime() );
97          setProject( request.getProject() );
98          setResolveDependencies( request.isResolveDependencies() );
99          setValidationLevel( request.getValidationLevel() );
100     }
101 
102     public MavenProject getProject()
103     {
104         return project;
105     }
106 
107     public void setProject( MavenProject mavenProject )
108     {
109         this.project = mavenProject;
110     }
111 
112     public ProjectBuildingRequest setLocalRepository( ArtifactRepository localRepository )
113     {
114         this.localRepository = localRepository;
115         return this;
116     }
117 
118     public ArtifactRepository getLocalRepository()
119     {
120         return localRepository;
121     }
122 
123     public List<ArtifactRepository> getRemoteRepositories()
124     {
125         return remoteRepositories;
126     }
127 
128     public ProjectBuildingRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
129     {
130         if ( remoteRepositories != null )
131         {
132             this.remoteRepositories = new ArrayList<>( remoteRepositories );
133         }
134         else
135         {
136             this.remoteRepositories.clear();
137         }
138 
139         return this;
140     }
141 
142     public List<ArtifactRepository> getPluginArtifactRepositories()
143     {
144         return pluginArtifactRepositories;
145     }
146 
147     public ProjectBuildingRequest setPluginArtifactRepositories( List<ArtifactRepository> pluginArtifactRepositories )
148     {
149         if ( pluginArtifactRepositories != null )
150         {
151             this.pluginArtifactRepositories = new ArrayList<>( pluginArtifactRepositories );
152         }
153         else
154         {
155             this.pluginArtifactRepositories.clear();
156         }
157 
158         return this;
159     }
160 
161     public Properties getSystemProperties()
162     {
163         return systemProperties;
164     }
165 
166     public ProjectBuildingRequest setSystemProperties( Properties systemProperties )
167     {
168         if ( systemProperties != null )
169         {
170             this.systemProperties = SystemProperties.copyProperties( systemProperties );
171         }
172         else
173         {
174             this.systemProperties.clear();
175         }
176 
177         return this;
178     }
179 
180     public Properties getUserProperties()
181     {
182         return userProperties;
183     }
184 
185     public ProjectBuildingRequest setUserProperties( Properties userProperties )
186     {
187         if ( userProperties != null )
188         {
189             this.userProperties = new Properties();
190             this.userProperties.putAll( userProperties );
191         }
192         else
193         {
194             this.userProperties.clear();
195         }
196 
197         return this;
198     }
199 
200     public boolean isProcessPlugins()
201     {
202         return processPlugins;
203     }
204 
205     public ProjectBuildingRequest setProcessPlugins( boolean processPlugins )
206     {
207         this.processPlugins = processPlugins;
208         return this;
209     }
210 
211     public ProjectBuildingRequest setResolveDependencies( boolean resolveDependencies )
212     {
213         this.resolveDependencies = resolveDependencies;
214         return this;
215     }
216 
217     public boolean isResolveDependencies()
218     {
219         return resolveDependencies;
220     }
221 
222     /**
223      * @since 3.2.2
224      * @deprecated This got added when implementing MNG-2199 and is no longer used.
225      * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 'MavenProject' objects are initialized.
226      */
227     @Deprecated
228     public ProjectBuildingRequest setResolveVersionRanges( boolean value )
229     {
230         this.resolveVersionRanges = value;
231         return this;
232     }
233 
234     /**
235      * @since 3.2.2
236      * @deprecated This got added when implementing MNG-2199 and is no longer used.
237      * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 'MavenProject' objects are initialized.
238      */
239     @Deprecated
240     public boolean isResolveVersionRanges()
241     {
242         return this.resolveVersionRanges;
243     }
244 
245     public ProjectBuildingRequest setValidationLevel( int validationLevel )
246     {
247         this.validationLevel = validationLevel;
248         return this;
249     }
250 
251     public int getValidationLevel()
252     {
253         return validationLevel;
254     }
255 
256     public List<String> getActiveProfileIds()
257     {
258         return activeProfileIds;
259     }
260 
261     public void setActiveProfileIds( List<String> activeProfileIds )
262     {
263         if ( activeProfileIds != null )
264         {
265             this.activeProfileIds = new ArrayList<>( activeProfileIds );
266         }
267         else
268         {
269             this.activeProfileIds.clear();
270         }
271     }
272 
273     public List<String> getInactiveProfileIds()
274     {
275         return inactiveProfileIds;
276     }
277 
278     public void setInactiveProfileIds( List<String> inactiveProfileIds )
279     {
280         if ( inactiveProfileIds != null )
281         {
282             this.inactiveProfileIds = new ArrayList<>( inactiveProfileIds );
283         }
284         else
285         {
286             this.inactiveProfileIds.clear();
287         }
288     }
289 
290     public void setProfiles( List<Profile> profiles )
291     {
292         if ( profiles != null )
293         {
294             this.profiles = new ArrayList<>( profiles );
295         }
296         else
297         {
298             this.profiles.clear();
299         }
300     }
301 
302     public void addProfile( Profile profile )
303     {
304         profiles.add( profile );
305     }
306 
307     public List<Profile> getProfiles()
308     {
309         return profiles;
310     }
311 
312     public Date getBuildStartTime()
313     {
314         return buildStartTime;
315     }
316 
317     public void setBuildStartTime( Date buildStartTime )
318     {
319         this.buildStartTime = buildStartTime;
320     }
321 
322     public RepositorySystemSession getRepositorySession()
323     {
324         return repositorySession;
325     }
326 
327     public DefaultProjectBuildingRequest setRepositorySession( RepositorySystemSession repositorySession )
328     {
329         this.repositorySession = repositorySession;
330         return this;
331     }
332 
333     public DefaultProjectBuildingRequest setRepositoryMerging( RepositoryMerging repositoryMerging )
334     {
335         this.repositoryMerging = Validate.notNull( repositoryMerging, "repositoryMerging cannot be null" );
336         return this;
337     }
338 
339     public RepositoryMerging getRepositoryMerging()
340     {
341         return repositoryMerging;
342     }
343 
344 }