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; 025import static java.util.Objects.requireNonNull; 026 027import org.eclipse.aether.RepositorySystem; 028import org.eclipse.aether.repository.ArtifactRepository; 029 030/** 031 * The result of a version resolution request. 032 * 033 * @see RepositorySystem#resolveVersion(org.eclipse.aether.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 this.request = requireNonNull( request, "version request cannot be null" ); 054 exceptions = Collections.emptyList(); 055 } 056 057 /** 058 * Gets the resolution request that was made. 059 * 060 * @return The resolution request, never {@code null}. 061 */ 062 public VersionRequest getRequest() 063 { 064 return request; 065 } 066 067 /** 068 * Gets the exceptions that occurred while resolving the version. 069 * 070 * @return The exceptions that occurred, never {@code null}. 071 */ 072 public List<Exception> getExceptions() 073 { 074 return exceptions; 075 } 076 077 /** 078 * Records the specified exception while resolving the version. 079 * 080 * @param exception The exception to record, may be {@code null}. 081 * @return This result for chaining, never {@code null}. 082 */ 083 public VersionResult addException( Exception exception ) 084 { 085 if ( exception != null ) 086 { 087 if ( exceptions.isEmpty() ) 088 { 089 exceptions = new ArrayList<>(); 090 } 091 exceptions.add( exception ); 092 } 093 return this; 094 } 095 096 /** 097 * Gets the resolved version. 098 * 099 * @return The resolved version or {@code null} if the resolution failed. 100 */ 101 public String getVersion() 102 { 103 return version; 104 } 105 106 /** 107 * Sets the resolved version. 108 * 109 * @param version The resolved version, may be {@code null}. 110 * @return This result for chaining, never {@code null}. 111 */ 112 public VersionResult setVersion( String version ) 113 { 114 this.version = version; 115 return this; 116 } 117 118 /** 119 * Gets the repository from which the version was eventually resolved. 120 * 121 * @return The repository from which the version was resolved or {@code null} if unknown. 122 */ 123 public ArtifactRepository getRepository() 124 { 125 return repository; 126 } 127 128 /** 129 * Sets the repository from which the version was resolved. 130 * 131 * @param repository The repository from which the version was resolved, may be {@code null}. 132 * @return This result for chaining, never {@code null}. 133 */ 134 public VersionResult setRepository( ArtifactRepository repository ) 135 { 136 this.repository = repository; 137 return this; 138 } 139 140 @Override 141 public String toString() 142 { 143 return getVersion() + " @ " + getRepository(); 144 } 145 146}