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  
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.apache.maven.properties.internal.SystemProperties;
31  import org.eclipse.aether.RepositorySystemSession;
32  
33  /**
34   * DefaultProjectBuildingRequest
35   */
36  public class DefaultProjectBuildingRequest implements ProjectBuildingRequest {
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          processPlugins = true;
73          profiles = new ArrayList<>();
74          activeProfileIds = new ArrayList<>();
75          inactiveProfileIds = new ArrayList<>();
76          systemProperties = new Properties();
77          userProperties = new Properties();
78          remoteRepositories = new ArrayList<>();
79          pluginArtifactRepositories = new ArrayList<>();
80      }
81  
82      public DefaultProjectBuildingRequest(ProjectBuildingRequest request) {
83          this();
84          setProcessPlugins(request.isProcessPlugins());
85          setProfiles(request.getProfiles());
86          setActiveProfileIds(request.getActiveProfileIds());
87          setInactiveProfileIds(request.getInactiveProfileIds());
88          setSystemProperties(request.getSystemProperties());
89          setUserProperties(request.getUserProperties());
90          setRemoteRepositories(request.getRemoteRepositories());
91          setPluginArtifactRepositories(request.getPluginArtifactRepositories());
92          setRepositorySession(request.getRepositorySession());
93          setLocalRepository(request.getLocalRepository());
94          setBuildStartTime(request.getBuildStartTime());
95          setProject(request.getProject());
96          setResolveDependencies(request.isResolveDependencies());
97          setValidationLevel(request.getValidationLevel());
98          setResolveVersionRanges(request.isResolveVersionRanges());
99          setRepositoryMerging(request.getRepositoryMerging());
100     }
101 
102     public MavenProject getProject() {
103         return project;
104     }
105 
106     public void setProject(MavenProject mavenProject) {
107         this.project = mavenProject;
108     }
109 
110     public ProjectBuildingRequest setLocalRepository(ArtifactRepository localRepository) {
111         this.localRepository = localRepository;
112         return this;
113     }
114 
115     public ArtifactRepository getLocalRepository() {
116         return localRepository;
117     }
118 
119     public List<ArtifactRepository> getRemoteRepositories() {
120         return remoteRepositories;
121     }
122 
123     public ProjectBuildingRequest setRemoteRepositories(List<ArtifactRepository> remoteRepositories) {
124         if (remoteRepositories != null) {
125             this.remoteRepositories = new ArrayList<>(remoteRepositories);
126         } else {
127             this.remoteRepositories.clear();
128         }
129 
130         return this;
131     }
132 
133     public List<ArtifactRepository> getPluginArtifactRepositories() {
134         return pluginArtifactRepositories;
135     }
136 
137     public ProjectBuildingRequest setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) {
138         if (pluginArtifactRepositories != null) {
139             this.pluginArtifactRepositories = new ArrayList<>(pluginArtifactRepositories);
140         } else {
141             this.pluginArtifactRepositories.clear();
142         }
143 
144         return this;
145     }
146 
147     public Properties getSystemProperties() {
148         return systemProperties;
149     }
150 
151     public ProjectBuildingRequest setSystemProperties(Properties systemProperties) {
152         if (systemProperties != null) {
153             this.systemProperties = SystemProperties.copyProperties(systemProperties);
154         } else {
155             this.systemProperties.clear();
156         }
157 
158         return this;
159     }
160 
161     public Properties getUserProperties() {
162         return userProperties;
163     }
164 
165     public ProjectBuildingRequest setUserProperties(Properties userProperties) {
166         if (userProperties != null) {
167             this.userProperties = new Properties();
168             this.userProperties.putAll(userProperties);
169         } else {
170             this.userProperties.clear();
171         }
172 
173         return this;
174     }
175 
176     public boolean isProcessPlugins() {
177         return processPlugins;
178     }
179 
180     public ProjectBuildingRequest setProcessPlugins(boolean processPlugins) {
181         this.processPlugins = processPlugins;
182         return this;
183     }
184 
185     public ProjectBuildingRequest setResolveDependencies(boolean resolveDependencies) {
186         this.resolveDependencies = resolveDependencies;
187         return this;
188     }
189 
190     public boolean isResolveDependencies() {
191         return resolveDependencies;
192     }
193 
194     /**
195      * @since 3.2.2
196      * @deprecated This got added when implementing MNG-2199 and is no longer used.
197      * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 'MavenProject' objects are initialized.
198      */
199     @Deprecated
200     public ProjectBuildingRequest setResolveVersionRanges(boolean value) {
201         this.resolveVersionRanges = value;
202         return this;
203     }
204 
205     /**
206      * @since 3.2.2
207      * @deprecated This got added when implementing MNG-2199 and is no longer used.
208      * Commit 6cf9320942c34bc68205425ab696b1712ace9ba4 updated the way 'MavenProject' objects are initialized.
209      */
210     @Deprecated
211     public boolean isResolveVersionRanges() {
212         return this.resolveVersionRanges;
213     }
214 
215     public ProjectBuildingRequest setValidationLevel(int validationLevel) {
216         this.validationLevel = validationLevel;
217         return this;
218     }
219 
220     public int getValidationLevel() {
221         return validationLevel;
222     }
223 
224     public List<String> getActiveProfileIds() {
225         return activeProfileIds;
226     }
227 
228     public void setActiveProfileIds(List<String> activeProfileIds) {
229         if (activeProfileIds != null) {
230             this.activeProfileIds = new ArrayList<>(activeProfileIds);
231         } else {
232             this.activeProfileIds.clear();
233         }
234     }
235 
236     public List<String> getInactiveProfileIds() {
237         return inactiveProfileIds;
238     }
239 
240     public void setInactiveProfileIds(List<String> inactiveProfileIds) {
241         if (inactiveProfileIds != null) {
242             this.inactiveProfileIds = new ArrayList<>(inactiveProfileIds);
243         } else {
244             this.inactiveProfileIds.clear();
245         }
246     }
247 
248     public void setProfiles(List<Profile> profiles) {
249         if (profiles != null) {
250             this.profiles = new ArrayList<>(profiles);
251         } else {
252             this.profiles.clear();
253         }
254     }
255 
256     public void addProfile(Profile profile) {
257         profiles.add(profile);
258     }
259 
260     public List<Profile> getProfiles() {
261         return profiles;
262     }
263 
264     public Date getBuildStartTime() {
265         return buildStartTime;
266     }
267 
268     public void setBuildStartTime(Date buildStartTime) {
269         this.buildStartTime = buildStartTime;
270     }
271 
272     public RepositorySystemSession getRepositorySession() {
273         return repositorySession;
274     }
275 
276     public DefaultProjectBuildingRequest setRepositorySession(RepositorySystemSession repositorySession) {
277         this.repositorySession = repositorySession;
278         return this;
279     }
280 
281     public DefaultProjectBuildingRequest setRepositoryMerging(RepositoryMerging repositoryMerging) {
282         this.repositoryMerging = Objects.requireNonNull(repositoryMerging, "repositoryMerging cannot be null");
283         return this;
284     }
285 
286     public RepositoryMerging getRepositoryMerging() {
287         return repositoryMerging;
288     }
289 }