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