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