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