1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.eclipse.aether.resolution;
20
21 import org.eclipse.aether.RepositorySystem;
22 import org.eclipse.aether.RequestTrace;
23 import org.eclipse.aether.artifact.Artifact;
24 import org.eclipse.aether.collection.CollectRequest;
25 import org.eclipse.aether.graph.DependencyFilter;
26 import org.eclipse.aether.graph.DependencyNode;
27
28 /**
29 * A request to resolve transitive dependencies. This request can either be supplied with a {@link CollectRequest} to
30 * calculate the transitive dependencies or with an already resolved dependency graph.
31 *
32 * @see RepositorySystem#resolveDependencies(org.eclipse.aether.RepositorySystemSession, DependencyRequest)
33 * @see Artifact#getFile()
34 */
35 public final class DependencyRequest {
36
37 private DependencyNode root;
38
39 private CollectRequest collectRequest;
40
41 private DependencyFilter filter;
42
43 private RequestTrace trace;
44
45 /**
46 * Creates an uninitialized request. Note that either {@link #setRoot(DependencyNode)} or
47 * {@link #setCollectRequest(CollectRequest)} must eventually be called to create a valid request.
48 */
49 public DependencyRequest() {
50 // enables default constructor
51 }
52
53 /**
54 * Creates a request for the specified dependency graph and with the given resolution filter.
55 *
56 * @param node The root node of the dependency graph whose artifacts should be resolved, may be {@code null}.
57 * @param filter The resolution filter to use, may be {@code null}.
58 */
59 public DependencyRequest(DependencyNode node, DependencyFilter filter) {
60 setRoot(node);
61 setFilter(filter);
62 }
63
64 /**
65 * Creates a request for the specified collect request and with the given resolution filter.
66 *
67 * @param request The collect request used to calculate the dependency graph whose artifacts should be resolved, may
68 * be {@code null}.
69 * @param filter The resolution filter to use, may be {@code null}.
70 */
71 public DependencyRequest(CollectRequest request, DependencyFilter filter) {
72 setCollectRequest(request);
73 setFilter(filter);
74 }
75
76 /**
77 * Gets the root node of the dependency graph whose artifacts should be resolved.
78 *
79 * @return The root node of the dependency graph or {@code null} if none.
80 */
81 public DependencyNode getRoot() {
82 return root;
83 }
84
85 /**
86 * Sets the root node of the dependency graph whose artifacts should be resolved. When this request is processed,
87 * the nodes of the given dependency graph will be updated to refer to the resolved artifacts. Eventually, either
88 * {@link #setRoot(DependencyNode)} or {@link #setCollectRequest(CollectRequest)} must be called to create a valid
89 * request.
90 *
91 * @param root The root node of the dependency graph, may be {@code null}.
92 * @return This request for chaining, never {@code null}.
93 */
94 public DependencyRequest setRoot(DependencyNode root) {
95 this.root = root;
96 return this;
97 }
98
99 /**
100 * Gets the collect request used to calculate the dependency graph whose artifacts should be resolved.
101 *
102 * @return The collect request or {@code null} if none.
103 */
104 public CollectRequest getCollectRequest() {
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 this.collectRequest = collectRequest;
119 return this;
120 }
121
122 /**
123 * Gets the resolution filter used to select which artifacts of the dependency graph should be resolved.
124 *
125 * @return The resolution filter or {@code null} to resolve all artifacts of the dependency graph.
126 */
127 public DependencyFilter getFilter() {
128 return filter;
129 }
130
131 /**
132 * Sets the resolution filter used to select which artifacts of the dependency graph should be resolved. For
133 * example, use this filter to restrict resolution to dependencies of a certain scope.
134 *
135 * @param filter The resolution filter, may be {@code null} to resolve all artifacts of the dependency graph.
136 * @return This request for chaining, never {@code null}.
137 */
138 public DependencyRequest setFilter(DependencyFilter filter) {
139 this.filter = filter;
140 return this;
141 }
142
143 /**
144 * Gets the trace information that describes the higher level request/operation in which this request is issued.
145 *
146 * @return The trace information about the higher level operation or {@code null} if none.
147 */
148 public RequestTrace getTrace() {
149 return trace;
150 }
151
152 /**
153 * Sets the trace information that describes the higher level request/operation in which this request is issued.
154 *
155 * @param trace The trace information about the higher level operation, may be {@code null}.
156 * @return This request for chaining, never {@code null}.
157 */
158 public DependencyRequest setTrace(RequestTrace trace) {
159 this.trace = trace;
160 return this;
161 }
162
163 @Override
164 public String toString() {
165 if (root != null) {
166 return String.valueOf(root);
167 }
168 return String.valueOf(collectRequest);
169 }
170 }