]> git.argeo.org Git - gpl/argeo-slc.git/blob - cms/org.argeo.slc.repo/src/org/eclipse/aether/resolution/VersionResolutionException.java
Clarify SLC project structure.
[gpl/argeo-slc.git] / cms / org.argeo.slc.repo / src / org / eclipse / aether / resolution / VersionResolutionException.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 unresolvable metaversion.
17 */
18 public class VersionResolutionException
19 extends RepositoryException
20 {
21
22 private final transient VersionResult result;
23
24 /**
25 * Creates a new exception with the specified result.
26 *
27 * @param result The version result at the point the exception occurred, may be {@code null}.
28 */
29 public VersionResolutionException( VersionResult result )
30 {
31 super( getMessage( result ), getCause( result ) );
32 this.result = result;
33 }
34
35 private static String getMessage( VersionResult result )
36 {
37 StringBuilder buffer = new StringBuilder( 256 );
38 buffer.append( "Failed to resolve version" );
39 if ( result != null )
40 {
41 buffer.append( " for " ).append( result.getRequest().getArtifact() );
42 if ( !result.getExceptions().isEmpty() )
43 {
44 buffer.append( ": " ).append( result.getExceptions().iterator().next().getMessage() );
45 }
46 }
47 return buffer.toString();
48 }
49
50 private static Throwable getCause( VersionResult result )
51 {
52 Throwable cause = null;
53 if ( result != null && !result.getExceptions().isEmpty() )
54 {
55 cause = result.getExceptions().get( 0 );
56 }
57 return cause;
58 }
59
60 /**
61 * Creates a new exception with the specified result and detail message.
62 *
63 * @param result The version result at the point the exception occurred, may be {@code null}.
64 * @param message The detail message, may be {@code null}.
65 */
66 public VersionResolutionException( VersionResult result, String message )
67 {
68 super( message, getCause( result ) );
69 this.result = result;
70 }
71
72 /**
73 * Creates a new exception with the specified result, detail message and cause.
74 *
75 * @param result The version result at the point the exception occurred, may be {@code null}.
76 * @param message The detail message, may be {@code null}.
77 * @param cause The exception that caused this one, may be {@code null}.
78 */
79 public VersionResolutionException( VersionResult result, String message, Throwable cause )
80 {
81 super( message, cause );
82 this.result = result;
83 }
84
85 /**
86 * Gets the version result at the point the exception occurred. Despite being incomplete, callers might want to use
87 * this result to fail gracefully and continue their operation with whatever interim data has been gathered.
88 *
89 * @return The version result or {@code null} if unknown.
90 */
91 public VersionResult getResult()
92 {
93 return result;
94 }
95
96 }