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
.resolution
;
13 import org
.eclipse
.aether
.RepositoryException
;
16 * Thrown in case of an unresolvable metaversion.
18 public class VersionResolutionException
19 extends RepositoryException
22 private final transient VersionResult result
;
25 * Creates a new exception with the specified result.
27 * @param result The version result at the point the exception occurred, may be {@code null}.
29 public VersionResolutionException( VersionResult result
)
31 super( getMessage( result
), getCause( result
) );
35 private static String
getMessage( VersionResult result
)
37 StringBuilder buffer
= new StringBuilder( 256 );
38 buffer
.append( "Failed to resolve version" );
41 buffer
.append( " for " ).append( result
.getRequest().getArtifact() );
42 if ( !result
.getExceptions().isEmpty() )
44 buffer
.append( ": " ).append( result
.getExceptions().iterator().next().getMessage() );
47 return buffer
.toString();
50 private static Throwable
getCause( VersionResult result
)
52 Throwable cause
= null;
53 if ( result
!= null && !result
.getExceptions().isEmpty() )
55 cause
= result
.getExceptions().get( 0 );
61 * Creates a new exception with the specified result and detail message.
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}.
66 public VersionResolutionException( VersionResult result
, String message
)
68 super( message
, getCause( result
) );
73 * Creates a new exception with the specified result, detail message and cause.
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}.
79 public VersionResolutionException( VersionResult result
, String message
, Throwable cause
)
81 super( message
, cause
);
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.
89 * @return The version result or {@code null} if unknown.
91 public VersionResult
getResult()