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.artifact.resolver;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Set;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.artifact.repository.RepositoryCache;
29  import org.apache.maven.artifact.repository.RepositoryRequest;
30  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
31  import org.apache.maven.settings.Mirror;
32  import org.apache.maven.settings.Proxy;
33  import org.apache.maven.settings.Server;
34  
35  /**
36   * A resolution request allows you to either use an existing MavenProject, or a coordinate (gid:aid:version)
37   * to process a POMs dependencies.
38   *
39   * @author Jason van Zyl
40   */
41  public class ArtifactResolutionRequest implements RepositoryRequest {
42      private static final String LS = System.lineSeparator();
43  
44      private Artifact artifact;
45  
46      // Needs to go away
47      // These are really overrides now, projects defining dependencies for a plugin that override what is
48      // specified in the plugin itself.
49      private Set<Artifact> artifactDependencies;
50  
51      private ArtifactRepository localRepository;
52  
53      private List<ArtifactRepository> remoteRepositories;
54  
55      private ArtifactFilter collectionFilter;
56  
57      private ArtifactFilter resolutionFilter;
58  
59      // Needs to go away
60      private List<ResolutionListener> listeners = new ArrayList<>();
61  
62      // This is like a filter but overrides all transitive versions
63      private Map<String, Artifact> managedVersionMap;
64  
65      private boolean resolveRoot = true;
66  
67      private boolean resolveTransitively = false;
68  
69      private boolean offline;
70  
71      private boolean forceUpdate;
72  
73      private List<Server> servers;
74  
75      private List<Mirror> mirrors;
76  
77      private List<Proxy> proxies;
78  
79      public ArtifactResolutionRequest() {
80          // nothing here
81      }
82  
83      public ArtifactResolutionRequest(RepositoryRequest request) {
84          setLocalRepository(request.getLocalRepository());
85          setRemoteRepositories(request.getRemoteRepositories());
86          setOffline(request.isOffline());
87          setForceUpdate(request.isForceUpdate());
88      }
89  
90      public Artifact getArtifact() {
91          return artifact;
92      }
93  
94      public ArtifactResolutionRequest setArtifact(Artifact artifact) {
95          this.artifact = artifact;
96  
97          return this;
98      }
99  
100     public ArtifactResolutionRequest setArtifactDependencies(Set<Artifact> artifactDependencies) {
101         this.artifactDependencies = artifactDependencies;
102 
103         return this;
104     }
105 
106     public Set<Artifact> getArtifactDependencies() {
107         return artifactDependencies;
108     }
109 
110     public ArtifactRepository getLocalRepository() {
111         return localRepository;
112     }
113 
114     public ArtifactResolutionRequest setLocalRepository(ArtifactRepository localRepository) {
115         this.localRepository = localRepository;
116 
117         return this;
118     }
119 
120     public List<ArtifactRepository> getRemoteRepositories() {
121         return remoteRepositories;
122     }
123 
124     public ArtifactResolutionRequest setRemoteRepositories(List<ArtifactRepository> remoteRepositories) {
125         this.remoteRepositories = remoteRepositories;
126 
127         return this;
128     }
129 
130     /**
131      * Gets the artifact filter that controls traversal of the dependency graph.
132      *
133      * @return The filter used to determine which of the artifacts in the dependency graph should be traversed or
134      *         {@code null} to collect all transitive dependencies.
135      */
136     public ArtifactFilter getCollectionFilter() {
137         return collectionFilter;
138     }
139 
140     public ArtifactResolutionRequest setCollectionFilter(ArtifactFilter filter) {
141         this.collectionFilter = filter;
142 
143         return this;
144     }
145 
146     /**
147      * Gets the artifact filter that controls downloading of artifact files. This filter operates on those artifacts
148      * that have been included by the {@link #getCollectionFilter()}.
149      *
150      * @return The filter used to determine which of the artifacts should have their files resolved or {@code null} to
151      *         resolve the files for all collected artifacts.
152      */
153     public ArtifactFilter getResolutionFilter() {
154         return resolutionFilter;
155     }
156 
157     public ArtifactResolutionRequest setResolutionFilter(ArtifactFilter filter) {
158         this.resolutionFilter = filter;
159 
160         return this;
161     }
162 
163     public List<ResolutionListener> getListeners() {
164         return listeners;
165     }
166 
167     public ArtifactResolutionRequest setListeners(List<ResolutionListener> listeners) {
168         this.listeners = listeners;
169 
170         return this;
171     }
172 
173     public ArtifactResolutionRequest addListener(ResolutionListener listener) {
174         listeners.add(listener);
175 
176         return this;
177     }
178 
179     public Map<String, Artifact> getManagedVersionMap() {
180         return managedVersionMap;
181     }
182 
183     public ArtifactResolutionRequest setManagedVersionMap(Map<String, Artifact> managedVersionMap) {
184         this.managedVersionMap = managedVersionMap;
185 
186         return this;
187     }
188 
189     public ArtifactResolutionRequest setResolveRoot(boolean resolveRoot) {
190         this.resolveRoot = resolveRoot;
191 
192         return this;
193     }
194 
195     public boolean isResolveRoot() {
196         return resolveRoot;
197     }
198 
199     public ArtifactResolutionRequest setResolveTransitively(boolean resolveDependencies) {
200         this.resolveTransitively = resolveDependencies;
201 
202         return this;
203     }
204 
205     public boolean isResolveTransitively() {
206         return resolveTransitively;
207     }
208 
209     public String toString() {
210         StringBuilder sb = new StringBuilder()
211                 .append("REQUEST: ")
212                 .append(LS)
213                 .append("artifact: ")
214                 .append(artifact)
215                 .append(LS)
216                 .append(artifactDependencies)
217                 .append(LS)
218                 .append("localRepository: ")
219                 .append(localRepository)
220                 .append(LS)
221                 .append("remoteRepositories: ")
222                 .append(remoteRepositories);
223 
224         return sb.toString();
225     }
226 
227     public boolean isOffline() {
228         return offline;
229     }
230 
231     public ArtifactResolutionRequest setOffline(boolean offline) {
232         this.offline = offline;
233 
234         return this;
235     }
236 
237     public boolean isForceUpdate() {
238         return forceUpdate;
239     }
240 
241     public ArtifactResolutionRequest setForceUpdate(boolean forceUpdate) {
242         this.forceUpdate = forceUpdate;
243 
244         return this;
245     }
246 
247     public ArtifactResolutionRequest setServers(List<Server> servers) {
248         this.servers = servers;
249 
250         return this;
251     }
252 
253     public List<Server> getServers() {
254         if (servers == null) {
255             servers = new ArrayList<>();
256         }
257 
258         return servers;
259     }
260 
261     public ArtifactResolutionRequest setMirrors(List<Mirror> mirrors) {
262         this.mirrors = mirrors;
263 
264         return this;
265     }
266 
267     public List<Mirror> getMirrors() {
268         if (mirrors == null) {
269             mirrors = new ArrayList<>();
270         }
271 
272         return mirrors;
273     }
274 
275     public ArtifactResolutionRequest setProxies(List<Proxy> proxies) {
276         this.proxies = proxies;
277 
278         return this;
279     }
280 
281     public List<Proxy> getProxies() {
282         if (proxies == null) {
283             proxies = new ArrayList<>();
284         }
285 
286         return proxies;
287     }
288 
289     //
290     // Used by Tycho and will break users and force them to upgrade to Maven 3.1 so we should really leave
291     // this here, possibly indefinitely.
292     //
293     public ArtifactResolutionRequest setCache(RepositoryCache cache) {
294         return this;
295     }
296 }