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