001package org.eclipse.aether.repository;
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 an unsupported local repository type.
026 */
027public class NoLocalRepositoryManagerException
028    extends RepositoryException
029{
030
031    private final transient LocalRepository repository;
032
033    /**
034     * Creates a new exception with the specified repository.
035     * 
036     * @param repository The local repository for which no support is available, may be {@code null}.
037     */
038    public NoLocalRepositoryManagerException( LocalRepository repository )
039    {
040        this( repository, toMessage( repository ) );
041    }
042
043    /**
044     * Creates a new exception with the specified repository and detail message.
045     * 
046     * @param repository The local repository for which no support is available, may be {@code null}.
047     * @param message The detail message, may be {@code null}.
048     */
049    public NoLocalRepositoryManagerException( LocalRepository repository, String message )
050    {
051        super( message );
052        this.repository = repository;
053    }
054
055    /**
056     * Creates a new exception with the specified repository and cause.
057     * 
058     * @param repository The local repository for which no support is available, may be {@code null}.
059     * @param cause The exception that caused this one, may be {@code null}.
060     */
061    public NoLocalRepositoryManagerException( LocalRepository repository, Throwable cause )
062    {
063        this( repository, toMessage( repository ), cause );
064    }
065
066    /**
067     * Creates a new exception with the specified repository, detail message and cause.
068     * 
069     * @param repository The local repository for which no support is available, may be {@code null}.
070     * @param message The detail message, may be {@code null}.
071     * @param cause The exception that caused this one, may be {@code null}.
072     */
073    public NoLocalRepositoryManagerException( LocalRepository repository, String message, Throwable cause )
074    {
075        super( message, cause );
076        this.repository = repository;
077    }
078
079    private static String toMessage( LocalRepository repository )
080    {
081        if ( repository != null )
082        {
083            return "No manager available for local repository (" + repository.getBasedir().getAbsolutePath()
084                + ") of type " + repository.getContentType();
085        }
086        else
087        {
088            return "No manager available for local repository";
089        }
090    }
091
092    /**
093     * Gets the local repository whose content type is not supported.
094     * 
095     * @return The unsupported local repository or {@code null} if unknown.
096     */
097    public LocalRepository getRepository()
098    {
099        return repository;
100    }
101
102}