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
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.aether
.collection
;
13 import org
.eclipse
.aether
.RepositoryException
;
16 * Thrown in case of bad artifact descriptors, version ranges or other issues encountered during calculation of the
19 public class DependencyCollectionException
20 extends RepositoryException
23 private final transient CollectResult result
;
26 * Creates a new exception with the specified result.
28 * @param result The collection result at the point the exception occurred, may be {@code null}.
30 public DependencyCollectionException( CollectResult result
)
32 super( "Failed to collect dependencies for " + getSource( result
), getCause( result
) );
37 * Creates a new exception with the specified result and detail message.
39 * @param result The collection result at the point the exception occurred, may be {@code null}.
40 * @param message The detail message, may be {@code null}.
42 public DependencyCollectionException( CollectResult result
, String message
)
44 super( message
, getCause( result
) );
49 * Creates a new exception with the specified result, detail message and cause.
51 * @param result The collection result at the point the exception occurred, may be {@code null}.
52 * @param message The detail message, may be {@code null}.
53 * @param cause The exception that caused this one, may be {@code null}.
55 public DependencyCollectionException( CollectResult result
, String message
, Throwable cause
)
57 super( message
, cause
);
62 * Gets the collection result at the point the exception occurred. Despite being incomplete, callers might want to
63 * use this result to fail gracefully and continue their operation with whatever interim data has been gathered.
65 * @return The collection result or {@code null} if unknown.
67 public CollectResult
getResult()
72 private static String
getSource( CollectResult result
)
79 CollectRequest request
= result
.getRequest();
80 if ( request
.getRoot() != null )
82 return request
.getRoot().toString();
84 if ( request
.getRootArtifact() != null )
86 return request
.getRootArtifact().toString();
89 return request
.getDependencies().toString();
92 private static Throwable
getCause( CollectResult result
)
94 Throwable cause
= null;
95 if ( result
!= null && !result
.getExceptions().isEmpty() )
97 cause
= result
.getExceptions().get( 0 );