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