001 package 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 022 import java.util.ArrayList; 023 import java.util.List; 024 import java.util.Map; 025 import java.util.Set; 026 027 import org.apache.maven.artifact.Artifact; 028 import org.apache.maven.artifact.repository.ArtifactRepository; 029 import org.apache.maven.artifact.repository.RepositoryCache; 030 import org.apache.maven.artifact.repository.RepositoryRequest; 031 import org.apache.maven.artifact.resolver.filter.ArtifactFilter; 032 import org.apache.maven.settings.Mirror; 033 import org.apache.maven.settings.Proxy; 034 import 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 */ 042 public 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 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 getManagedVersionMap() 199 { 200 return managedVersionMap; 201 } 202 203 public ArtifactResolutionRequest setManagedVersionMap( Map 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 RepositoryCache getCache() 247 { 248 return null; 249 } 250 251 public ArtifactResolutionRequest setCache( RepositoryCache cache ) 252 { 253 return this; 254 } 255 256 public boolean isOffline() 257 { 258 return offline; 259 } 260 261 public ArtifactResolutionRequest setOffline( boolean offline ) 262 { 263 this.offline = offline; 264 265 return this; 266 } 267 268 public boolean isForceUpdate() 269 { 270 return forceUpdate; 271 } 272 273 public ArtifactResolutionRequest setForceUpdate( boolean forceUpdate ) 274 { 275 this.forceUpdate = forceUpdate; 276 277 return this; 278 } 279 280 public ArtifactResolutionRequest setServers( List<Server> servers ) 281 { 282 this.servers = servers; 283 284 return this; 285 } 286 287 public List<Server> getServers() 288 { 289 if ( servers == null ) 290 { 291 servers = new ArrayList<Server>(); 292 } 293 294 return servers; 295 } 296 297 public ArtifactResolutionRequest setMirrors( List<Mirror> mirrors ) 298 { 299 this.mirrors = mirrors; 300 301 return this; 302 } 303 304 public List<Mirror> getMirrors() 305 { 306 if ( mirrors == null ) 307 { 308 mirrors = new ArrayList<Mirror>(); 309 } 310 311 return mirrors; 312 } 313 314 public ArtifactResolutionRequest setProxies( List<Proxy> proxies ) 315 { 316 this.proxies = proxies; 317 318 return this; 319 } 320 321 public List<Proxy> getProxies() 322 { 323 if ( proxies == null ) 324 { 325 proxies = new ArrayList<Proxy>(); 326 } 327 328 return proxies; 329 } 330 331 }