]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/resolution/ArtifactDescriptorException.java
Merge branch 'master' of https://github.com/argeo/argeo-slc.git
[gpl/argeo-slc.git] / org.argeo.slc.repo / src / org / eclipse / aether / resolution / ArtifactDescriptorException.java
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 an unreadable or unresolvable artifact descriptor.
17 */
18 public class ArtifactDescriptorException
19 extends RepositoryException
20 {
21
22 private final transient ArtifactDescriptorResult result;
23
24 /**
25 * Creates a new exception with the specified result.
26 *
27 * @param result The descriptor result at the point the exception occurred, may be {@code null}.
28 */
29 public ArtifactDescriptorException( ArtifactDescriptorResult result )
30 {
31 super( "Failed to read artifact descriptor"
32 + ( result != null ? " for " + result.getRequest().getArtifact() : "" ), getCause( result ) );
33 this.result = result;
34 }
35
36 /**
37 * Creates a new exception with the specified result and detail message.
38 *
39 * @param result The descriptor result at the point the exception occurred, may be {@code null}.
40 * @param message The detail message, may be {@code null}.
41 */
42 public ArtifactDescriptorException( ArtifactDescriptorResult result, String message )
43 {
44 super( message, getCause( result ) );
45 this.result = result;
46 }
47
48 /**
49 * Creates a new exception with the specified result, detail message and cause.
50 *
51 * @param result The descriptor 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}.
54 */
55 public ArtifactDescriptorException( ArtifactDescriptorResult result, String message, Throwable cause )
56 {
57 super( message, cause );
58 this.result = result;
59 }
60
61 /**
62 * Gets the descriptor 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.
64 *
65 * @return The descriptor result or {@code null} if unknown.
66 */
67 public ArtifactDescriptorResult getResult()
68 {
69 return result;
70 }
71
72 private static Throwable getCause( ArtifactDescriptorResult result )
73 {
74 Throwable cause = null;
75 if ( result != null && !result.getExceptions().isEmpty() )
76 {
77 cause = result.getExceptions().get( 0 );
78 }
79 return cause;
80 }
81
82 }