1 package org.eclipse.aether.transfer; 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 org.eclipse.aether.RepositoryException; 23 import org.eclipse.aether.artifact.Artifact; 24 import org.eclipse.aether.repository.RemoteRepository; 25 26 /** 27 * Thrown when an artifact could not be uploaded/downloaded to/from a particular remote repository. 28 */ 29 public class ArtifactTransferException 30 extends RepositoryException 31 { 32 33 private final transient Artifact artifact; 34 35 private final transient RemoteRepository repository; 36 37 private final boolean fromCache; 38 39 static String getString( String prefix, RemoteRepository repository ) 40 { 41 if ( repository == null ) 42 { 43 return ""; 44 } 45 else 46 { 47 return prefix + repository.getId() + " (" + repository.getUrl() + ")"; 48 } 49 } 50 51 /** 52 * Creates a new exception with the specified artifact, repository and detail message. 53 * 54 * @param artifact The untransferable artifact, may be {@code null}. 55 * @param repository The involved remote repository, may be {@code null}. 56 * @param message The detail message, may be {@code null}. 57 */ 58 public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message ) 59 { 60 this( artifact, repository, message, false ); 61 } 62 63 /** 64 * Creates a new exception with the specified artifact, repository and detail message. 65 * 66 * @param artifact The untransferable artifact, may be {@code null}. 67 * @param repository The involved remote repository, may be {@code null}. 68 * @param message The detail message, may be {@code null}. 69 * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the 70 * exception actually just occurred. 71 */ 72 public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message, 73 boolean fromCache ) 74 { 75 super( message ); 76 this.artifact = artifact; 77 this.repository = repository; 78 this.fromCache = fromCache; 79 } 80 81 /** 82 * Creates a new exception with the specified artifact, repository and cause. 83 * 84 * @param artifact The untransferable artifact, may be {@code null}. 85 * @param repository The involved remote repository, may be {@code null}. 86 * @param cause The exception that caused this one, may be {@code null}. 87 */ 88 public ArtifactTransferException( Artifact artifact, RemoteRepository repository, Throwable cause ) 89 { 90 this( artifact, repository, "Could not transfer artifact " + artifact + getString( " from/to ", repository ) 91 + getMessage( ": ", cause ), cause ); 92 } 93 94 /** 95 * Creates a new exception with the specified artifact, repository, detail message and cause. 96 * 97 * @param artifact The untransferable artifact, may be {@code null}. 98 * @param repository The involved remote repository, may be {@code null}. 99 * @param message The detail message, may be {@code null}. 100 * @param cause The exception that caused this one, may be {@code null}. 101 */ 102 public ArtifactTransferException( Artifact artifact, RemoteRepository repository, String message, Throwable cause ) 103 { 104 super( message, cause ); 105 this.artifact = artifact; 106 this.repository = repository; 107 this.fromCache = false; 108 } 109 110 /** 111 * Gets the artifact that could not be transferred. 112 * 113 * @return The troublesome artifact or {@code null} if unknown. 114 */ 115 public Artifact getArtifact() 116 { 117 return artifact; 118 } 119 120 /** 121 * Gets the remote repository involved in the transfer. 122 * 123 * @return The involved remote repository or {@code null} if unknown. 124 */ 125 public RemoteRepository getRepository() 126 { 127 return repository; 128 } 129 130 /** 131 * Indicates whether this exception actually just occurred or was played back from the error cache. 132 * 133 * @return {@code true} if the exception was played back from the error cache, {@code false} if the exception 134 * actually occurred just now. 135 */ 136 public boolean isFromCache() 137 { 138 return fromCache; 139 } 140 141 }