001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.eclipse.aether.resolution; 020 021import org.eclipse.aether.RepositoryException; 022 023/** 024 * Thrown in case of a unresolvable dependencies. 025 */ 026public class DependencyResolutionException extends RepositoryException { 027 028 private final transient DependencyResult result; 029 030 /** 031 * Creates a new exception with the specified result and cause. 032 * 033 * @param result The dependency result at the point the exception occurred, may be {@code null}. 034 * @param cause The exception that caused this one, may be {@code null}. 035 */ 036 public DependencyResolutionException(DependencyResult result, Throwable cause) { 037 super(getMessage(cause), cause); 038 this.result = result; 039 } 040 041 /** 042 * Creates a new exception with the specified result, detail message and cause. 043 * 044 * @param result The dependency result at the point the exception occurred, may be {@code null}. 045 * @param message The detail message, may be {@code null}. 046 * @param cause The exception that caused this one, may be {@code null}. 047 */ 048 public DependencyResolutionException(DependencyResult result, String message, Throwable cause) { 049 super(message, cause); 050 this.result = result; 051 } 052 053 private static String getMessage(Throwable cause) { 054 String msg = null; 055 if (cause != null) { 056 msg = cause.getMessage(); 057 } 058 if (msg == null || msg.isEmpty()) { 059 msg = "Could not resolve transitive dependencies"; 060 } 061 return msg; 062 } 063 064 /** 065 * Gets the dependency result at the point the exception occurred. Despite being incomplete, callers might want to 066 * use this result to fail gracefully and continue their operation with whatever interim data has been gathered. 067 * 068 * @return The dependency result or {@code null} if unknown. 069 */ 070 public DependencyResult getResult() { 071 return result; 072 } 073}