View Javadoc
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 java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.eclipse.aether.RequestTrace;
26  import org.eclipse.aether.artifact.Artifact;
27  import org.eclipse.aether.repository.RemoteRepository;
28  
29  /**
30   * A request to resolve a version range.
31   *
32   * @see org.eclipse.aether.RepositorySystem#resolveVersionRange(org.eclipse.aether.RepositorySystemSession,
33   *  VersionRangeRequest)
34   */
35  public final class VersionRangeRequest {
36  
37      private Artifact artifact;
38  
39      private List<RemoteRepository> repositories = Collections.emptyList();
40  
41      private String context = "";
42  
43      private RequestTrace trace;
44  
45      /**
46       * Creates an uninitialized request.
47       */
48      public VersionRangeRequest() {
49          // enables default constructor
50      }
51  
52      /**
53       * Creates a request with the specified properties.
54       *
55       * @param artifact The artifact whose version range should be resolved, may be {@code null}.
56       * @param repositories The repositories to resolve the version from, may be {@code null}.
57       * @param context The context in which this request is made, may be {@code null}.
58       */
59      public VersionRangeRequest(Artifact artifact, List<RemoteRepository> repositories, String context) {
60          setArtifact(artifact);
61          setRepositories(repositories);
62          setRequestContext(context);
63      }
64  
65      /**
66       * Gets the artifact whose version range shall be resolved.
67       *
68       * @return The artifact or {@code null} if not set.
69       */
70      public Artifact getArtifact() {
71          return artifact;
72      }
73  
74      /**
75       * Sets the artifact whose version range shall be resolved.
76       *
77       * @param artifact The artifact, may be {@code null}.
78       * @return This request for chaining, never {@code null}.
79       */
80      public VersionRangeRequest setArtifact(Artifact artifact) {
81          this.artifact = artifact;
82          return this;
83      }
84  
85      /**
86       * Gets the repositories to resolve the version range from.
87       *
88       * @return The repositories, never {@code null}.
89       */
90      public List<RemoteRepository> getRepositories() {
91          return repositories;
92      }
93  
94      /**
95       * Sets the repositories to resolve the version range from.
96       *
97       * @param repositories The repositories, may be {@code null}.
98       * @return This request for chaining, never {@code null}.
99       */
100     public VersionRangeRequest setRepositories(List<RemoteRepository> repositories) {
101         if (repositories == null) {
102             this.repositories = Collections.emptyList();
103         } else {
104             this.repositories = repositories;
105         }
106         return this;
107     }
108 
109     /**
110      * Adds the specified repository for the resolution.
111      *
112      * @param repository The repository to add, may be {@code null}.
113      * @return This request for chaining, never {@code null}.
114      */
115     public VersionRangeRequest addRepository(RemoteRepository repository) {
116         if (repository != null) {
117             if (this.repositories.isEmpty()) {
118                 this.repositories = new ArrayList<>();
119             }
120             this.repositories.add(repository);
121         }
122         return this;
123     }
124 
125     /**
126      * Gets the context in which this request is made.
127      *
128      * @return The context, never {@code null}.
129      */
130     public String getRequestContext() {
131         return context;
132     }
133 
134     /**
135      * Sets the context in which this request is made.
136      *
137      * @param context The context, may be {@code null}.
138      * @return This request for chaining, never {@code null}.
139      */
140     public VersionRangeRequest setRequestContext(String context) {
141         this.context = (context != null) ? context : "";
142         return this;
143     }
144 
145     /**
146      * Gets the trace information that describes the higher level request/operation in which this request is issued.
147      *
148      * @return The trace information about the higher level operation or {@code null} if none.
149      */
150     public RequestTrace getTrace() {
151         return trace;
152     }
153 
154     /**
155      * Sets the trace information that describes the higher level request/operation in which this request is issued.
156      *
157      * @param trace The trace information about the higher level operation, may be {@code null}.
158      * @return This request for chaining, never {@code null}.
159      */
160     public VersionRangeRequest setTrace(RequestTrace trace) {
161         this.trace = trace;
162         return this;
163     }
164 
165     @Override
166     public String toString() {
167         return getArtifact() + " < " + getRepositories();
168     }
169 }