1 /******************************************************************************* 2 * Copyright (c) 2010, 2011 Sonatype, Inc. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Sonatype, Inc. - initial API and implementation 10 *******************************************************************************/ 11 package org.eclipse.aether.resolution; 12 13 import java.util.ArrayList; 14 import java.util.Collections; 15 import java.util.List; 16 17 import org.eclipse.aether.RepositorySystem; 18 import org.eclipse.aether.RepositorySystemSession; 19 import org.eclipse.aether.RequestTrace; 20 import org.eclipse.aether.artifact.Artifact; 21 import org.eclipse.aether.repository.RemoteRepository; 22 23 /** 24 * A request to resolve a metaversion. 25 * 26 * @see RepositorySystem#resolveVersion(RepositorySystemSession, VersionRequest) 27 */ 28 public final class VersionRequest 29 { 30 31 private Artifact artifact; 32 33 private List<RemoteRepository> repositories = Collections.emptyList(); 34 35 private String context = ""; 36 37 private RequestTrace trace; 38 39 /** 40 * Creates an uninitialized request. 41 */ 42 public VersionRequest() 43 { 44 // enables default constructor 45 } 46 47 /** 48 * Creates a request with the specified properties. 49 * 50 * @param artifact The artifact whose (meta-)version should be resolved, may be {@code null}. 51 * @param repositories The repositories to resolve the version from, may be {@code null}. 52 * @param context The context in which this request is made, may be {@code null}. 53 */ 54 public VersionRequest( Artifact artifact, List<RemoteRepository> repositories, String context ) 55 { 56 setArtifact( artifact ); 57 setRepositories( repositories ); 58 setRequestContext( context ); 59 } 60 61 /** 62 * Gets the artifact whose (meta-)version shall be resolved. 63 * 64 * @return The artifact or {@code null} if not set. 65 */ 66 public Artifact getArtifact() 67 { 68 return artifact; 69 } 70 71 /** 72 * Sets the artifact whose (meta-)version shall be resolved. 73 * 74 * @param artifact The artifact, may be {@code null}. 75 * @return This request for chaining, never {@code null}. 76 */ 77 public VersionRequest setArtifact( Artifact artifact ) 78 { 79 this.artifact = artifact; 80 return this; 81 } 82 83 /** 84 * Gets the repositories to resolve the version from. 85 * 86 * @return The repositories, never {@code null}. 87 */ 88 public List<RemoteRepository> getRepositories() 89 { 90 return repositories; 91 } 92 93 /** 94 * Sets the repositories to resolve the version from. 95 * 96 * @param repositories The repositories, may be {@code null}. 97 * @return This request for chaining, never {@code null}. 98 */ 99 public VersionRequest setRepositories( List<RemoteRepository> repositories ) 100 { 101 if ( repositories == null ) 102 { 103 this.repositories = Collections.emptyList(); 104 } 105 else 106 { 107 this.repositories = repositories; 108 } 109 return this; 110 } 111 112 /** 113 * Adds the specified repository for the resolution. 114 * 115 * @param repository The repository to add, may be {@code null}. 116 * @return This request for chaining, never {@code null}. 117 */ 118 public VersionRequest addRepository( RemoteRepository repository ) 119 { 120 if ( repository != null ) 121 { 122 if ( this.repositories.isEmpty() ) 123 { 124 this.repositories = new ArrayList<RemoteRepository>(); 125 } 126 this.repositories.add( repository ); 127 } 128 return this; 129 } 130 131 /** 132 * Gets the context in which this request is made. 133 * 134 * @return The context, never {@code null}. 135 */ 136 public String getRequestContext() 137 { 138 return context; 139 } 140 141 /** 142 * Sets the context in which this request is made. 143 * 144 * @param context The context, may be {@code null}. 145 * @return This request for chaining, never {@code null}. 146 */ 147 public VersionRequest setRequestContext( String context ) 148 { 149 this.context = ( context != null ) ? context : ""; 150 return this; 151 } 152 153 /** 154 * Gets the trace information that describes the higher level request/operation in which this request is issued. 155 * 156 * @return The trace information about the higher level operation or {@code null} if none. 157 */ 158 public RequestTrace getTrace() 159 { 160 return trace; 161 } 162 163 /** 164 * Sets the trace information that describes the higher level request/operation in which this request is issued. 165 * 166 * @param trace The trace information about the higher level operation, may be {@code null}. 167 * @return This request for chaining, never {@code null}. 168 */ 169 public VersionRequest setTrace( RequestTrace trace ) 170 { 171 this.trace = trace; 172 return this; 173 } 174 175 @Override 176 public String toString() 177 { 178 return getArtifact() + " < " + getRepositories(); 179 } 180 181 }