001package org.apache.archiva.policies; 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.apache.archiva.common.ArchivaException; 023 024import java.util.Collections; 025import java.util.Map; 026 027/** 028 * One or more exceptions occurred downloading from a remote repository during the proxy phase. 029 */ 030public class ProxyDownloadException 031 extends ArchivaException 032{ 033 /** 034 * A list of failures keyed by repository ID. 035 */ 036 private final Map<String, Exception> failures; 037 038 public ProxyDownloadException( String message, String repositoryId, Exception cause ) 039 { 040 super( constructMessage( message, Collections.singletonMap( repositoryId, cause ) ), cause ); 041 042 failures = Collections.singletonMap( repositoryId, cause ); 043 } 044 045 public ProxyDownloadException( String message, Map<String, Exception> failures ) 046 { 047 super( constructMessage( message, failures ) ); 048 049 this.failures = failures; 050 } 051 052 private static String constructMessage( String message, Map<String, Exception> failures ) 053 { 054 StringBuilder msg = new StringBuilder( message ); 055 msg.append( ":" ); 056 for ( Map.Entry<String, Exception> entry : failures.entrySet() ) 057 { 058 msg.append( "\n\t" ).append( entry.getKey() ).append( ": " ).append( entry.getValue().getMessage() ); 059 } 060 return msg.toString(); 061 } 062 063 public Map<String, Exception> getFailures() 064 { 065 return failures; 066 } 067}