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