001package org.eclipse.aether.resolution;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 * 
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 * 
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.eclipse.aether.RepositoryException;
023
024/**
025 * Thrown in case of a unresolvable dependencies.
026 */
027public class DependencyResolutionException
028    extends RepositoryException
029{
030
031    private final transient DependencyResult result;
032
033    /**
034     * Creates a new exception with the specified result and cause.
035     * 
036     * @param result The dependency result at the point the exception occurred, may be {@code null}.
037     * @param cause The exception that caused this one, may be {@code null}.
038     */
039    public DependencyResolutionException( DependencyResult result, Throwable cause )
040    {
041        super( getMessage( cause ), cause );
042        this.result = result;
043    }
044
045    /**
046     * Creates a new exception with the specified result, detail message and cause.
047     * 
048     * @param result The dependency result at the point the exception occurred, may be {@code null}.
049     * @param message The detail message, may be {@code null}.
050     * @param cause The exception that caused this one, may be {@code null}.
051     */
052    public DependencyResolutionException( DependencyResult result, String message, Throwable cause )
053    {
054        super( message, cause );
055        this.result = result;
056    }
057
058    private static String getMessage( Throwable cause )
059    {
060        String msg = null;
061        if ( cause != null )
062        {
063            msg = cause.getMessage();
064        }
065        if ( msg == null || msg.length() <= 0 )
066        {
067            msg = "Could not resolve transitive dependencies";
068        }
069        return msg;
070    }
071
072    /**
073     * Gets the dependency result at the point the exception occurred. Despite being incomplete, callers might want to
074     * use this result to fail gracefully and continue their operation with whatever interim data has been gathered.
075     * 
076     * @return The dependency result or {@code null} if unknown.
077     */
078    public DependencyResult getResult()
079    {
080        return result;
081    }
082
083}