View Javadoc
1   package org.apache.maven.artifact.resolver;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.Set;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.artifact.repository.RepositoryCache;
30  import org.apache.maven.artifact.repository.RepositoryRequest;
31  import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
32  import org.apache.maven.settings.Mirror;
33  import org.apache.maven.settings.Proxy;
34  import org.apache.maven.settings.Server;
35  
36  /**
37   * A resolution request allows you to either use an existing MavenProject, or a coordinate (gid:aid:version)
38   * to process a POMs dependencies.
39   *
40   * @author Jason van Zyl
41   */
42  public class ArtifactResolutionRequest
43      implements RepositoryRequest
44  {
45  
46      private Artifact artifact;
47  
48      // Needs to go away
49      // These are really overrides now, projects defining dependencies for a plugin that override what is
50      // specified in the plugin itself.
51      private Set<Artifact> artifactDependencies;
52  
53      private ArtifactRepository localRepository;
54  
55      private List<ArtifactRepository> remoteRepositories;
56  
57      private ArtifactFilter collectionFilter;
58  
59      private ArtifactFilter resolutionFilter;
60  
61      // Needs to go away
62      private List<ResolutionListener> listeners = new ArrayList<ResolutionListener>();
63  
64      // This is like a filter but overrides all transitive versions 
65      private Map<String, Artifact> managedVersionMap;
66      
67      private boolean resolveRoot = true;
68  
69      private boolean resolveTransitively = false;
70  
71      private boolean offline;
72  
73      private boolean forceUpdate;
74  
75      private List<Server> servers;
76  
77      private List<Mirror> mirrors;
78  
79      private List<Proxy> proxies;
80  
81      public ArtifactResolutionRequest()
82      {
83          // nothing here
84      }
85  
86      public ArtifactResolutionRequest( RepositoryRequest request )
87      {
88          setLocalRepository( request.getLocalRepository() );
89          setRemoteRepositories( request.getRemoteRepositories() );
90          setOffline( request.isOffline() );
91          setForceUpdate( request.isForceUpdate() );
92      }
93  
94      public Artifact getArtifact()
95      {
96          return artifact;
97      }
98  
99      public ArtifactResolutionRequest setArtifact( Artifact artifact )
100     {
101         this.artifact = artifact;
102 
103         return this;
104     }
105 
106     public ArtifactResolutionRequest setArtifactDependencies( Set<Artifact> artifactDependencies )
107     {
108         this.artifactDependencies = artifactDependencies;
109 
110         return this;
111     }
112 
113     public Set<Artifact> getArtifactDependencies()
114     {
115         return artifactDependencies;
116     }
117 
118     public ArtifactRepository getLocalRepository()
119     {
120         return localRepository;
121     }
122 
123     public ArtifactResolutionRequest setLocalRepository( ArtifactRepository localRepository )
124     {
125         this.localRepository = localRepository;
126 
127         return this;
128     }
129 
130     public List<ArtifactRepository> getRemoteRepositories()
131     {
132         return remoteRepositories;
133     }
134 
135     public ArtifactResolutionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
136     {
137         this.remoteRepositories = remoteRepositories;
138 
139         return this;
140     }
141 
142     /**
143      * Gets the artifact filter that controls traversal of the dependency graph.
144      * 
145      * @return The filter used to determine which of the artifacts in the dependency graph should be traversed or
146      *         {@code null} to collect all transitive dependencies.
147      */
148     public ArtifactFilter getCollectionFilter()
149     {
150         return collectionFilter;
151     }
152 
153     public ArtifactResolutionRequest setCollectionFilter( ArtifactFilter filter )
154     {
155         this.collectionFilter = filter;
156 
157         return this;
158     }
159 
160     /**
161      * Gets the artifact filter that controls downloading of artifact files. This filter operates on those artifacts
162      * that have been included by the {@link #getCollectionFilter()}.
163      * 
164      * @return The filter used to determine which of the artifacts should have their files resolved or {@code null} to
165      *         resolve the files for all collected artifacts.
166      */
167     public ArtifactFilter getResolutionFilter()
168     {
169         return resolutionFilter;
170     }
171 
172     public ArtifactResolutionRequest setResolutionFilter( ArtifactFilter filter )
173     {
174         this.resolutionFilter = filter;
175 
176         return this;
177     }
178 
179     public List<ResolutionListener> getListeners()
180     {
181         return listeners;
182     }
183 
184     public ArtifactResolutionRequest setListeners( List<ResolutionListener> listeners )
185     {        
186         this.listeners = listeners;
187         
188         return this;
189     }
190     
191     public ArtifactResolutionRequest addListener( ResolutionListener listener )
192     {
193         listeners.add( listener );
194 
195         return this;
196     }
197 
198     public Map<String, Artifact> getManagedVersionMap()
199     {
200         return managedVersionMap;
201     }
202 
203     public ArtifactResolutionRequest setManagedVersionMap( Map<String, Artifact> managedVersionMap )
204     {
205         this.managedVersionMap = managedVersionMap;
206 
207         return this;
208     }
209 
210     public ArtifactResolutionRequest setResolveRoot( boolean resolveRoot )
211     {
212         this.resolveRoot = resolveRoot;
213         
214         return this;
215     }
216     
217     public boolean isResolveRoot()
218     {
219         return resolveRoot;
220     }        
221 
222     public ArtifactResolutionRequest setResolveTransitively( boolean resolveDependencies )
223     {
224         this.resolveTransitively = resolveDependencies;
225         
226         return this;
227     }
228     
229     public boolean isResolveTransitively()
230     {
231         return resolveTransitively;
232     }        
233 
234     public String toString()
235     {
236         StringBuilder sb = new StringBuilder()
237                 .append( "REQUEST: " ).append(  "\n" )
238                 .append( "artifact: " ).append( artifact ).append(  "\n" )
239                 .append( artifactDependencies ).append(  "\n" )
240                 .append( "localRepository: " ).append(  localRepository ).append(  "\n" )
241                 .append( "remoteRepositories: " ).append(  remoteRepositories ).append(  "\n" );
242         
243         return sb.toString();
244     }
245 
246     public boolean isOffline()
247     {
248         return offline;
249     }
250 
251     public ArtifactResolutionRequest setOffline( boolean offline )
252     {
253         this.offline = offline;
254 
255         return this;
256     }
257 
258     public boolean isForceUpdate()
259     {
260         return forceUpdate;
261     }
262 
263     public ArtifactResolutionRequest setForceUpdate( boolean forceUpdate )
264     {
265         this.forceUpdate = forceUpdate;
266 
267         return this;
268     }
269 
270     public ArtifactResolutionRequest setServers( List<Server> servers )
271     {
272         this.servers = servers;
273 
274         return this;
275     }
276 
277     public List<Server> getServers()
278     {
279         if ( servers == null )
280         {
281             servers = new ArrayList<Server>();
282         }
283 
284         return servers;
285     }
286 
287     public ArtifactResolutionRequest setMirrors( List<Mirror> mirrors )
288     {
289         this.mirrors = mirrors;
290 
291         return this;
292     }
293 
294     public List<Mirror> getMirrors()
295     {
296         if ( mirrors == null )
297         {
298             mirrors = new ArrayList<Mirror>();
299         }
300 
301         return mirrors;
302     }
303 
304     public ArtifactResolutionRequest setProxies( List<Proxy> proxies )
305     {
306         this.proxies = proxies;
307 
308         return this;
309     }
310 
311     public List<Proxy> getProxies()
312     {
313         if ( proxies == null )
314         {
315             proxies = new ArrayList<Proxy>();
316         }
317 
318         return proxies;
319     }
320 
321     //
322     // Used by Tycho and will break users and force them to upgrade to Maven 3.1 so we should really leave
323     // this here, possibly indefinitely.
324     //
325     public ArtifactResolutionRequest setCache( RepositoryCache cache )                                                                                             
326     {                                                                                                                                                              
327         return this;                                                                                                                                               
328     }                    
329 }