001package org.eclipse.aether.transfer; 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 org.eclipse.aether.RepositoryException; 023import org.eclipse.aether.metadata.Metadata; 024import org.eclipse.aether.repository.RemoteRepository; 025 026/** 027 * Thrown when metadata could not be uploaded/downloaded to/from a particular remote repository. 028 */ 029public class MetadataTransferException 030 extends RepositoryException 031{ 032 033 private final transient Metadata metadata; 034 035 private final transient RemoteRepository repository; 036 037 private final boolean fromCache; 038 039 static String getString( String prefix, RemoteRepository repository ) 040 { 041 if ( repository == null ) 042 { 043 return ""; 044 } 045 else 046 { 047 return prefix + repository.getId() + " (" + repository.getUrl() + ")"; 048 } 049 } 050 051 /** 052 * Creates a new exception with the specified metadata, repository and detail message. 053 * 054 * @param metadata The untransferable metadata, may be {@code null}. 055 * @param repository The involved remote repository, may be {@code null}. 056 * @param message The detail message, may be {@code null}. 057 */ 058 public MetadataTransferException( Metadata metadata, RemoteRepository repository, String message ) 059 { 060 this( metadata, repository, message, false ); 061 } 062 063 /** 064 * Creates a new exception with the specified metadata, repository and detail message. 065 * 066 * @param metadata The untransferable metadata, may be {@code null}. 067 * @param repository The involved remote repository, may be {@code null}. 068 * @param message The detail message, may be {@code null}. 069 * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the 070 * exception actually just occurred. 071 */ 072 public MetadataTransferException( Metadata metadata, RemoteRepository repository, String message, boolean fromCache ) 073 { 074 super( message ); 075 this.metadata = metadata; 076 this.repository = repository; 077 this.fromCache = fromCache; 078 } 079 080 /** 081 * Creates a new exception with the specified metadata, repository and cause. 082 * 083 * @param metadata The untransferable metadata, may be {@code null}. 084 * @param repository The involved remote repository, may be {@code null}. 085 * @param cause The exception that caused this one, may be {@code null}. 086 */ 087 public MetadataTransferException( Metadata metadata, RemoteRepository repository, Throwable cause ) 088 { 089 this( metadata, repository, "Could not transfer metadata " + metadata + getString( " from/to ", repository ) 090 + getMessage( ": ", cause ), cause ); 091 } 092 093 /** 094 * Creates a new exception with the specified metadata, repository, detail message and cause. 095 * 096 * @param metadata The untransferable metadata, may be {@code null}. 097 * @param repository The involved remote repository, may be {@code null}. 098 * @param message The detail message, may be {@code null}. 099 * @param cause The exception that caused this one, may be {@code null}. 100 */ 101 public MetadataTransferException( Metadata metadata, RemoteRepository repository, String message, Throwable cause ) 102 { 103 super( message, cause ); 104 this.metadata = metadata; 105 this.repository = repository; 106 this.fromCache = false; 107 } 108 109 /** 110 * Gets the metadata that could not be transferred. 111 * 112 * @return The troublesome metadata or {@code null} if unknown. 113 */ 114 public Metadata getMetadata() 115 { 116 return metadata; 117 } 118 119 /** 120 * Gets the remote repository involved in the transfer. 121 * 122 * @return The involved remote repository or {@code null} if unknown. 123 */ 124 public RemoteRepository getRepository() 125 { 126 return repository; 127 } 128 129 /** 130 * Indicates whether this exception actually just occurred or was played back from the error cache. 131 * 132 * @return {@code true} if the exception was played back from the error cache, {@code false} if the exception 133 * actually occurred just now. 134 */ 135 public boolean isFromCache() 136 { 137 return fromCache; 138 } 139 140}