View Javadoc
1   /*******************************************************************************
2    * Copyright (c) 2010, 2014 Sonatype, Inc.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *    Sonatype, Inc. - initial API and implementation
10   *******************************************************************************/
11  package org.eclipse.aether.resolution;
12  
13  import org.eclipse.aether.RepositoryException;
14  
15  /**
16   * Thrown in case of a unresolvable dependencies.
17   */
18  public class DependencyResolutionException
19      extends RepositoryException
20  {
21  
22      private final transient DependencyResult result;
23  
24      /**
25       * Creates a new exception with the specified result and cause.
26       * 
27       * @param result The dependency result at the point the exception occurred, may be {@code null}.
28       * @param cause The exception that caused this one, may be {@code null}.
29       */
30      public DependencyResolutionException( DependencyResult result, Throwable cause )
31      {
32          super( getMessage( cause ), cause );
33          this.result = result;
34      }
35  
36      /**
37       * Creates a new exception with the specified result, detail message and cause.
38       * 
39       * @param result The dependency result at the point the exception occurred, may be {@code null}.
40       * @param message The detail message, may be {@code null}.
41       * @param cause The exception that caused this one, may be {@code null}.
42       */
43      public DependencyResolutionException( DependencyResult result, String message, Throwable cause )
44      {
45          super( message, cause );
46          this.result = result;
47      }
48  
49      private static String getMessage( Throwable cause )
50      {
51          String msg = null;
52          if ( cause != null )
53          {
54              msg = cause.getMessage();
55          }
56          if ( msg == null || msg.length() <= 0 )
57          {
58              msg = "Could not resolve transitive dependencies";
59          }
60          return msg;
61      }
62  
63      /**
64       * Gets the dependency result at the point the exception occurred. Despite being incomplete, callers might want to
65       * use this result to fail gracefully and continue their operation with whatever interim data has been gathered.
66       * 
67       * @return The dependency result or {@code null} if unknown.
68       */
69      public DependencyResult getResult()
70      {
71          return result;
72      }
73  
74  }