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