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 a unresolvable dependencies.
26 */
27 public class DependencyResolutionException
28 extends RepositoryException
29 {
30
31 private final transient DependencyResult result;
32
33 /**
34 * Creates a new exception with the specified result and cause.
35 *
36 * @param result The dependency result at the point the exception occurred, may be {@code null}.
37 * @param cause The exception that caused this one, may be {@code null}.
38 */
39 public DependencyResolutionException( DependencyResult result, Throwable cause )
40 {
41 super( getMessage( cause ), cause );
42 this.result = result;
43 }
44
45 /**
46 * Creates a new exception with the specified result, detail message and cause.
47 *
48 * @param result The dependency result at the point the exception occurred, may be {@code null}.
49 * @param message The detail message, may be {@code null}.
50 * @param cause The exception that caused this one, may be {@code null}.
51 */
52 public DependencyResolutionException( DependencyResult result, String message, Throwable cause )
53 {
54 super( message, cause );
55 this.result = result;
56 }
57
58 private static String getMessage( Throwable cause )
59 {
60 String msg = null;
61 if ( cause != null )
62 {
63 msg = cause.getMessage();
64 }
65 if ( msg == null || msg.length() <= 0 )
66 {
67 msg = "Could not resolve transitive dependencies";
68 }
69 return msg;
70 }
71
72 /**
73 * Gets the dependency result at the point the exception occurred. Despite being incomplete, callers might want to
74 * use this result to fail gracefully and continue their operation with whatever interim data has been gathered.
75 *
76 * @return The dependency result or {@code null} if unknown.
77 */
78 public DependencyResult getResult()
79 {
80 return result;
81 }
82
83 }