1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.eclipse.aether.resolution;
20
21 import org.eclipse.aether.RepositoryException;
22
23 /**
24 * Thrown in case of a unresolvable dependencies.
25 */
26 public class DependencyResolutionException extends RepositoryException {
27
28 private final transient DependencyResult result;
29
30 /**
31 * Creates a new exception with the specified result and cause.
32 *
33 * @param result The dependency result at the point the exception occurred, may be {@code null}.
34 * @param cause The exception that caused this one, may be {@code null}.
35 */
36 public DependencyResolutionException(DependencyResult result, Throwable cause) {
37 super(getMessage(cause), cause);
38 this.result = result;
39 }
40
41 /**
42 * Creates a new exception with the specified result, detail message and cause.
43 *
44 * @param result The dependency result at the point the exception occurred, may be {@code null}.
45 * @param message The detail message, may be {@code null}.
46 * @param cause The exception that caused this one, may be {@code null}.
47 */
48 public DependencyResolutionException(DependencyResult result, String message, Throwable cause) {
49 super(message, cause);
50 this.result = result;
51 }
52
53 private static String getMessage(Throwable cause) {
54 String msg = null;
55 if (cause != null) {
56 msg = cause.getMessage();
57 }
58 if (msg == null || msg.isEmpty()) {
59 msg = "Could not resolve transitive dependencies";
60 }
61 return msg;
62 }
63
64 /**
65 * Gets the dependency result at the point the exception occurred. Despite being incomplete, callers might want to
66 * use this result to fail gracefully and continue their operation with whatever interim data has been gathered.
67 *
68 * @return The dependency result or {@code null} if unknown.
69 */
70 public DependencyResult getResult() {
71 return result;
72 }
73 }