1 package org.eclipse.aether.resolution; 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 24 /** 25 * Thrown in case of an unreadable or unresolvable artifact descriptor. 26 */ 27 public class ArtifactDescriptorException 28 extends RepositoryException 29 { 30 31 private final transient ArtifactDescriptorResult result; 32 33 /** 34 * Creates a new exception with the specified result. 35 * 36 * @param result The descriptor result at the point the exception occurred, may be {@code null}. 37 */ 38 public ArtifactDescriptorException( ArtifactDescriptorResult result ) 39 { 40 super( "Failed to read artifact descriptor" 41 + ( result != null ? " for " + result.getRequest().getArtifact() : "" ), getCause( result ) ); 42 this.result = result; 43 } 44 45 /** 46 * Creates a new exception with the specified result and detail message. 47 * 48 * @param result The descriptor result at the point the exception occurred, may be {@code null}. 49 * @param message The detail message, may be {@code null}. 50 */ 51 public ArtifactDescriptorException( ArtifactDescriptorResult result, String message ) 52 { 53 super( message, getCause( result ) ); 54 this.result = result; 55 } 56 57 /** 58 * Creates a new exception with the specified result, detail message and cause. 59 * 60 * @param result The descriptor result at the point the exception occurred, may be {@code null}. 61 * @param message The detail message, may be {@code null}. 62 * @param cause The exception that caused this one, may be {@code null}. 63 */ 64 public ArtifactDescriptorException( ArtifactDescriptorResult result, String message, Throwable cause ) 65 { 66 super( message, cause ); 67 this.result = result; 68 } 69 70 /** 71 * Gets the descriptor result at the point the exception occurred. Despite being incomplete, callers might want to 72 * use this result to fail gracefully and continue their operation with whatever interim data has been gathered. 73 * 74 * @return The descriptor result or {@code null} if unknown. 75 */ 76 public ArtifactDescriptorResult getResult() 77 { 78 return result; 79 } 80 81 private static Throwable getCause( ArtifactDescriptorResult result ) 82 { 83 Throwable cause = null; 84 if ( result != null && !result.getExceptions().isEmpty() ) 85 { 86 cause = result.getExceptions().get( 0 ); 87 } 88 return cause; 89 } 90 91 }