1 /******************************************************************************* 2 * Copyright (c) 2010, 2011 Sonatype, Inc. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Sonatype, Inc. - initial API and implementation 10 *******************************************************************************/ 11 package org.eclipse.aether.resolution; 12 13 import org.eclipse.aether.RepositorySystem; 14 import org.eclipse.aether.RepositorySystemSession; 15 import org.eclipse.aether.RequestTrace; 16 import org.eclipse.aether.artifact.Artifact; 17 import org.eclipse.aether.collection.CollectRequest; 18 import org.eclipse.aether.graph.DependencyFilter; 19 import org.eclipse.aether.graph.DependencyNode; 20 21 /** 22 * A request to resolve transitive dependencies. This request can either be supplied with a {@link CollectRequest} to 23 * calculate the transitive dependencies or with an already resolved dependency graph. 24 * 25 * @see RepositorySystem#resolveDependencies(RepositorySystemSession, DependencyRequest) 26 * @see Artifact#getFile() 27 */ 28 public final class DependencyRequest 29 { 30 31 private DependencyNode root; 32 33 private CollectRequest collectRequest; 34 35 private DependencyFilter filter; 36 37 private RequestTrace trace; 38 39 /** 40 * Creates an uninitialized request. Note that either {@link #setRoot(DependencyNode)} or 41 * {@link #setCollectRequest(CollectRequest)} must eventually be called to create a valid request. 42 */ 43 public DependencyRequest() 44 { 45 // enables default constructor 46 } 47 48 /** 49 * Creates a request for the specified dependency graph and with the given resolution filter. 50 * 51 * @param node The root node of the dependency graph whose artifacts should be resolved, may be {@code null}. 52 * @param filter The resolution filter to use, may be {@code null}. 53 */ 54 public DependencyRequest( DependencyNode node, DependencyFilter filter ) 55 { 56 setRoot( node ); 57 setFilter( filter ); 58 } 59 60 /** 61 * Creates a request for the specified collect request and with the given resolution filter. 62 * 63 * @param request The collect request used to calculate the dependency graph whose artifacts should be resolved, may 64 * be {@code null}. 65 * @param filter The resolution filter to use, may be {@code null}. 66 */ 67 public DependencyRequest( CollectRequest request, DependencyFilter filter ) 68 { 69 setCollectRequest( request ); 70 setFilter( filter ); 71 } 72 73 /** 74 * Gets the root node of the dependency graph whose artifacts should be resolved. 75 * 76 * @return The root node of the dependency graph or {@code null} if none. 77 */ 78 public DependencyNode getRoot() 79 { 80 return root; 81 } 82 83 /** 84 * Sets the root node of the dependency graph whose artifacts should be resolved. When this request is processed, 85 * the nodes of the given dependency graph will be updated to refer to the resolved artifacts. Eventually, either 86 * {@link #setRoot(DependencyNode)} or {@link #setCollectRequest(CollectRequest)} must be called to create a valid 87 * request. 88 * 89 * @param root The root node of the dependency graph, may be {@code null}. 90 * @return This request for chaining, never {@code null}. 91 */ 92 public DependencyRequest setRoot( DependencyNode root ) 93 { 94 this.root = root; 95 return this; 96 } 97 98 /** 99 * Gets the collect request used to calculate the dependency graph whose artifacts should be resolved. 100 * 101 * @return The collect request or {@code null} if none. 102 */ 103 public CollectRequest getCollectRequest() 104 { 105 return collectRequest; 106 } 107 108 /** 109 * Sets the collect request used to calculate the dependency graph whose artifacts should be resolved. Eventually, 110 * either {@link #setRoot(DependencyNode)} or {@link #setCollectRequest(CollectRequest)} must be called to create a 111 * valid request. If this request is supplied with a dependency node via {@link #setRoot(DependencyNode)}, the 112 * collect request is ignored. 113 * 114 * @param collectRequest The collect request, may be {@code null}. 115 * @return This request for chaining, never {@code null}. 116 */ 117 public DependencyRequest setCollectRequest( CollectRequest collectRequest ) 118 { 119 this.collectRequest = collectRequest; 120 return this; 121 } 122 123 /** 124 * Gets the resolution filter used to select which artifacts of the dependency graph should be resolved. 125 * 126 * @return The resolution filter or {@code null} to resolve all artifacts of the dependency graph. 127 */ 128 public DependencyFilter getFilter() 129 { 130 return filter; 131 } 132 133 /** 134 * Sets the resolution filter used to select which artifacts of the dependency graph should be resolved. For 135 * example, use this filter to restrict resolution to dependencies of a certain scope. 136 * 137 * @param filter The resolution filter, may be {@code null} to resolve all artifacts of the dependency graph. 138 * @return This request for chaining, never {@code null}. 139 */ 140 public DependencyRequest setFilter( DependencyFilter filter ) 141 { 142 this.filter = filter; 143 return this; 144 } 145 146 /** 147 * Gets the trace information that describes the higher level request/operation in which this request is issued. 148 * 149 * @return The trace information about the higher level operation or {@code null} if none. 150 */ 151 public RequestTrace getTrace() 152 { 153 return trace; 154 } 155 156 /** 157 * Sets the trace information that describes the higher level request/operation in which this request is issued. 158 * 159 * @param trace The trace information about the higher level operation, may be {@code null}. 160 * @return This request for chaining, never {@code null}. 161 */ 162 public DependencyRequest setTrace( RequestTrace trace ) 163 { 164 this.trace = trace; 165 return this; 166 } 167 168 @Override 169 public String toString() 170 { 171 if ( root != null ) 172 { 173 return String.valueOf( root ); 174 } 175 return String.valueOf( collectRequest ); 176 } 177 178 }