]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/resolution/VersionRangeResolutionException.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 / VersionRangeResolutionException.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 unparseable or unresolvable version range.
17 */
18 public class VersionRangeResolutionException
19 extends RepositoryException
20 {
21
22 private final transient VersionRangeResult result;
23
24 /**
25 * Creates a new exception with the specified result.
26 *
27 * @param result The version range result at the point the exception occurred, may be {@code null}.
28 */
29 public VersionRangeResolutionException( VersionRangeResult result )
30 {
31 super( getMessage( result ), getCause( result ) );
32 this.result = result;
33 }
34
35 private static String getMessage( VersionRangeResult result )
36 {
37 StringBuilder buffer = new StringBuilder( 256 );
38 buffer.append( "Failed to resolve version range" );
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( VersionRangeResult 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 range result at the point the exception occurred, may be {@code null}.
64 * @param message The detail message, may be {@code null}.
65 */
66 public VersionRangeResolutionException( VersionRangeResult result, String message )
67 {
68 super( message );
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 range 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 VersionRangeResolutionException( VersionRangeResult result, String message, Throwable cause )
80 {
81 super( message, cause );
82 this.result = result;
83 }
84
85 /**
86 * Gets the version range result at the point the exception occurred. Despite being incomplete, callers might want
87 * to use this result to fail gracefully and continue their operation with whatever interim data has been gathered.
88 *
89 * @return The version range result or {@code null} if unknown.
90 */
91 public VersionRangeResult getResult()
92 {
93 return result;
94 }
95
96 }