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.repository.ArtifactRepository; 029 030/** 031 * The result of a version resolution request. 032 * 033 * @see RepositorySystem#resolveVersion(RepositorySystemSession, VersionRequest) 034 */ 035public final class VersionResult 036{ 037 038 private final VersionRequest request; 039 040 private List<Exception> exceptions; 041 042 private String version; 043 044 private ArtifactRepository repository; 045 046 /** 047 * Creates a new result for the specified request. 048 * 049 * @param request The resolution request, must not be {@code null}. 050 */ 051 public VersionResult( VersionRequest request ) 052 { 053 if ( request == null ) 054 { 055 throw new IllegalArgumentException( "version request has not been specified" ); 056 } 057 this.request = request; 058 exceptions = Collections.emptyList(); 059 } 060 061 /** 062 * Gets the resolution request that was made. 063 * 064 * @return The resolution request, never {@code null}. 065 */ 066 public VersionRequest getRequest() 067 { 068 return request; 069 } 070 071 /** 072 * Gets the exceptions that occurred while resolving the version. 073 * 074 * @return The exceptions that occurred, never {@code null}. 075 */ 076 public List<Exception> getExceptions() 077 { 078 return exceptions; 079 } 080 081 /** 082 * Records the specified exception while resolving the version. 083 * 084 * @param exception The exception to record, may be {@code null}. 085 * @return This result for chaining, never {@code null}. 086 */ 087 public VersionResult addException( Exception exception ) 088 { 089 if ( exception != null ) 090 { 091 if ( exceptions.isEmpty() ) 092 { 093 exceptions = new ArrayList<Exception>(); 094 } 095 exceptions.add( exception ); 096 } 097 return this; 098 } 099 100 /** 101 * Gets the resolved version. 102 * 103 * @return The resolved version or {@code null} if the resolution failed. 104 */ 105 public String getVersion() 106 { 107 return version; 108 } 109 110 /** 111 * Sets the resolved version. 112 * 113 * @param version The resolved version, may be {@code null}. 114 * @return This result for chaining, never {@code null}. 115 */ 116 public VersionResult setVersion( String version ) 117 { 118 this.version = version; 119 return this; 120 } 121 122 /** 123 * Gets the repository from which the version was eventually resolved. 124 * 125 * @return The repository from which the version was resolved or {@code null} if unknown. 126 */ 127 public ArtifactRepository getRepository() 128 { 129 return repository; 130 } 131 132 /** 133 * Sets the repository from which the version was resolved. 134 * 135 * @param repository The repository from which the version was resolved, may be {@code null}. 136 * @return This result for chaining, never {@code null}. 137 */ 138 public VersionResult setRepository( ArtifactRepository repository ) 139 { 140 this.repository = repository; 141 return this; 142 } 143 144 @Override 145 public String toString() 146 { 147 return getVersion() + " @ " + getRepository(); 148 } 149 150}