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