001package org.apache.maven.artifact.resolver;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.ArrayList;
023import java.util.List;
024import java.util.Map;
025import java.util.Set;
026
027import org.apache.maven.artifact.Artifact;
028import org.apache.maven.artifact.repository.ArtifactRepository;
029import org.apache.maven.artifact.repository.RepositoryCache;
030import org.apache.maven.artifact.repository.RepositoryRequest;
031import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
032import org.apache.maven.settings.Mirror;
033import org.apache.maven.settings.Proxy;
034import org.apache.maven.settings.Server;
035
036/**
037 * A resolution request allows you to either use an existing MavenProject, or a coordinate (gid:aid:version)
038 * to process a POMs dependencies.
039 *
040 * @author Jason van Zyl
041 */
042public class ArtifactResolutionRequest
043    implements RepositoryRequest
044{
045
046    private Artifact artifact;
047
048    // Needs to go away
049    // These are really overrides now, projects defining dependencies for a plugin that override what is
050    // specified in the plugin itself.
051    private Set<Artifact> artifactDependencies;
052
053    private ArtifactRepository localRepository;
054
055    private List<ArtifactRepository> remoteRepositories;
056
057    private ArtifactFilter collectionFilter;
058
059    private ArtifactFilter resolutionFilter;
060
061    // Needs to go away
062    private List<ResolutionListener> listeners = new ArrayList<ResolutionListener>();
063
064    // This is like a filter but overrides all transitive versions 
065    private Map<String, Artifact> managedVersionMap;
066    
067    private boolean resolveRoot = true;
068
069    private boolean resolveTransitively = false;
070
071    private boolean offline;
072
073    private boolean forceUpdate;
074
075    private List<Server> servers;
076
077    private List<Mirror> mirrors;
078
079    private List<Proxy> proxies;
080
081    public ArtifactResolutionRequest()
082    {
083        // nothing here
084    }
085
086    public ArtifactResolutionRequest( RepositoryRequest request )
087    {
088        setLocalRepository( request.getLocalRepository() );
089        setRemoteRepositories( request.getRemoteRepositories() );
090        setOffline( request.isOffline() );
091        setForceUpdate( request.isForceUpdate() );
092    }
093
094    public Artifact getArtifact()
095    {
096        return artifact;
097    }
098
099    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}