001package org.eclipse.aether.resolution; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.ArrayList; 023import java.util.Collections; 024import java.util.List; 025 026import org.eclipse.aether.RepositorySystem; 027import org.eclipse.aether.RepositorySystemSession; 028import org.eclipse.aether.RequestTrace; 029import org.eclipse.aether.artifact.Artifact; 030import org.eclipse.aether.repository.RemoteRepository; 031 032/** 033 * A request to resolve a version range. 034 * 035 * @see RepositorySystem#resolveVersionRange(RepositorySystemSession, VersionRangeRequest) 036 */ 037public final class VersionRangeRequest 038{ 039 040 private Artifact artifact; 041 042 private List<RemoteRepository> repositories = Collections.emptyList(); 043 044 private String context = ""; 045 046 private RequestTrace trace; 047 048 /** 049 * Creates an uninitialized request. 050 */ 051 public VersionRangeRequest() 052 { 053 // enables default constructor 054 } 055 056 /** 057 * Creates a request with the specified properties. 058 * 059 * @param artifact The artifact whose version range should be resolved, may be {@code null}. 060 * @param repositories The repositories to resolve the version from, may be {@code null}. 061 * @param context The context in which this request is made, may be {@code null}. 062 */ 063 public VersionRangeRequest( Artifact artifact, List<RemoteRepository> repositories, String context ) 064 { 065 setArtifact( artifact ); 066 setRepositories( repositories ); 067 setRequestContext( context ); 068 } 069 070 /** 071 * Gets the artifact whose version range shall be resolved. 072 * 073 * @return The artifact or {@code null} if not set. 074 */ 075 public Artifact getArtifact() 076 { 077 return artifact; 078 } 079 080 /** 081 * Sets the artifact whose version range shall be resolved. 082 * 083 * @param artifact The artifact, may be {@code null}. 084 * @return This request for chaining, never {@code null}. 085 */ 086 public VersionRangeRequest setArtifact( Artifact artifact ) 087 { 088 this.artifact = artifact; 089 return this; 090 } 091 092 /** 093 * Gets the repositories to resolve the version range from. 094 * 095 * @return The repositories, never {@code null}. 096 */ 097 public List<RemoteRepository> getRepositories() 098 { 099 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}