View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.project;
20  
21  import java.util.ArrayList;
22  import java.util.Date;
23  import java.util.List;
24  import java.util.Objects;
25  import java.util.Properties;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.model.Profile;
28  import org.apache.maven.model.building.ModelBuildingRequest;
29  import org.apache.maven.properties.internal.SystemProperties;
30  import org.eclipse.aether.RepositorySystemSession;
31  
32  /**
33   * DefaultProjectBuildingRequest
34   */
35  public class DefaultProjectBuildingRequest implements ProjectBuildingRequest {
36  
37      private RepositorySystemSession repositorySession;
38  
39      private ArtifactRepository localRepository;
40  
41      private List<ArtifactRepository> remoteRepositories;
42  
43      private List<ArtifactRepository> pluginArtifactRepositories;
44  
45      private MavenProject project;
46  
47      private int validationLevel = ModelBuildingRequest.VALIDATION_LEVEL_STRICT;
48  
49      private boolean processPlugins;
50  
51      private List<Profile> profiles;
52  
53      private List<String> activeProfileIds;
54  
55      private List<String> inactiveProfileIds;
56  
57      private Properties systemProperties;
58  
59      private Properties userProperties;
60  
61      private Date buildStartTime;
62  
63      private boolean resolveDependencies;
64  
65      @Deprecated
66      private boolean resolveVersionRanges;
67  
68      private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
69  
70      public DefaultProjectBuildingRequest() {
71          processPlugins = true;
72          profiles = new ArrayList<>();
73          activeProfileIds = new ArrayList<>();
74          inactiveProfileIds = new ArrayList<>();
75          systemProperties = new Properties();
76          userProperties = new Properties();
77          remoteRepositories = new ArrayList<>();
78          pluginArtifactRepositories = new ArrayList<>();
79      }
80  
81      public DefaultProjectBuildingRequest(ProjectBuildingRequest request) {
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          setResolveVersionRanges(request.isResolveVersionRanges());
98          setRepositoryMerging(request.getRepositoryMerging());
99      }
100 
101     public MavenProject getProject() {
102         return project;
103     }
104 
105     public void setProject(MavenProject mavenProject) {
106         this.project = mavenProject;
107     }
108 
109     public ProjectBuildingRequest setLocalRepository(ArtifactRepository localRepository) {
110         this.localRepository = localRepository;
111         return this;
112     }
113 
114     public ArtifactRepository getLocalRepository() {
115         return localRepository;
116     }
117 
118     public List<ArtifactRepository> getRemoteRepositories() {
119         return remoteRepositories;
120     }
121 
122     public ProjectBuildingRequest setRemoteRepositories(List<ArtifactRepository> remoteRepositories) {
123         if (remoteRepositories != null) {
124             this.remoteRepositories = new ArrayList<>(remoteRepositories);
125         } else {
126             this.remoteRepositories.clear();
127         }
128 
129         return this;
130     }
131 
132     public List<ArtifactRepository> getPluginArtifactRepositories() {
133         return pluginArtifactRepositories;
134     }
135 
136     public ProjectBuildingRequest setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) {
137         if (pluginArtifactRepositories != null) {
138             this.pluginArtifactRepositories = new ArrayList<>(pluginArtifactRepositories);
139         } else {
140             this.pluginArtifactRepositories.clear();
141         }
142 
143         return this;
144     }
145 
146     public Properties getSystemProperties() {
147         return systemProperties;
148     }
149 
150     public ProjectBuildingRequest setSystemProperties(Properties systemProperties) {
151         if (systemProperties != null) {
152             this.systemProperties = SystemProperties.copyProperties(systemProperties);
153         } else {
154             this.systemProperties.clear();
155         }
156 
157         return this;
158     }
159 
160     public Properties getUserProperties() {
161         return userProperties;
162     }
163 
164     public ProjectBuildingRequest setUserProperties(Properties userProperties) {
165         if (userProperties != null) {
166             this.userProperties = new Properties();
167             this.userProperties.putAll(userProperties);
168         } else {
169             this.userProperties.clear();
170         }
171 
172         return this;
173     }
174 
175     public boolean isProcessPlugins() {
176         return processPlugins;
177     }
178 
179     public ProjectBuildingRequest setProcessPlugins(boolean processPlugins) {
180         this.processPlugins = processPlugins;
181         return this;
182     }
183 
184     public ProjectBuildingRequest setResolveDependencies(boolean resolveDependencies) {
185         this.resolveDependencies = resolveDependencies;
186         return this;
187     }
188 
189     public boolean isResolveDependencies() {
190         return resolveDependencies;
191     }
192 
193     /**
194      * @since 3.2.2
195      * @deprecated This got added when implementing MNG-2199 and is no longer used.
196      * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 'MavenProject' objects are initialized.
197      */
198     @Deprecated
199     public ProjectBuildingRequest setResolveVersionRanges(boolean value) {
200         this.resolveVersionRanges = value;
201         return this;
202     }
203 
204     /**
205      * @since 3.2.2
206      * @deprecated This got added when implementing MNG-2199 and is no longer used.
207      * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 'MavenProject' objects are initialized.
208      */
209     @Deprecated
210     public boolean isResolveVersionRanges() {
211         return this.resolveVersionRanges;
212     }
213 
214     public ProjectBuildingRequest setValidationLevel(int validationLevel) {
215         this.validationLevel = validationLevel;
216         return this;
217     }
218 
219     public int getValidationLevel() {
220         return validationLevel;
221     }
222 
223     public List<String> getActiveProfileIds() {
224         return activeProfileIds;
225     }
226 
227     public void setActiveProfileIds(List<String> activeProfileIds) {
228         if (activeProfileIds != null) {
229             this.activeProfileIds = new ArrayList<>(activeProfileIds);
230         } else {
231             this.activeProfileIds.clear();
232         }
233     }
234 
235     public List<String> getInactiveProfileIds() {
236         return inactiveProfileIds;
237     }
238 
239     public void setInactiveProfileIds(List<String> inactiveProfileIds) {
240         if (inactiveProfileIds != null) {
241             this.inactiveProfileIds = new ArrayList<>(inactiveProfileIds);
242         } else {
243             this.inactiveProfileIds.clear();
244         }
245     }
246 
247     public void setProfiles(List<Profile> profiles) {
248         if (profiles != null) {
249             this.profiles = new ArrayList<>(profiles);
250         } else {
251             this.profiles.clear();
252         }
253     }
254 
255     public void addProfile(Profile profile) {
256         profiles.add(profile);
257     }
258 
259     public List<Profile> getProfiles() {
260         return profiles;
261     }
262 
263     public Date getBuildStartTime() {
264         return buildStartTime;
265     }
266 
267     public void setBuildStartTime(Date buildStartTime) {
268         this.buildStartTime = buildStartTime;
269     }
270 
271     public RepositorySystemSession getRepositorySession() {
272         return repositorySession;
273     }
274 
275     public DefaultProjectBuildingRequest setRepositorySession(RepositorySystemSession repositorySession) {
276         this.repositorySession = repositorySession;
277         return this;
278     }
279 
280     public DefaultProjectBuildingRequest setRepositoryMerging(RepositoryMerging repositoryMerging) {
281         this.repositoryMerging = Objects.requireNonNull(repositoryMerging, "repositoryMerging cannot be null");
282         return this;
283     }
284 
285     public RepositoryMerging getRepositoryMerging() {
286         return repositoryMerging;
287     }
288 }