001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.transfer;
020
021import org.eclipse.aether.metadata.Metadata;
022import org.eclipse.aether.repository.LocalRepository;
023import org.eclipse.aether.repository.RemoteRepository;
024
025/**
026 * Thrown when metadata was not found in a particular repository.
027 */
028public class MetadataNotFoundException extends MetadataTransferException {
029
030    /**
031     * Creates a new exception with the specified metadata and local repository.
032     *
033     * @param metadata The missing metadata, may be {@code null}.
034     * @param repository The involved local repository, may be {@code null}.
035     */
036    public MetadataNotFoundException(Metadata metadata, LocalRepository repository) {
037        super(metadata, null, "Could not find metadata " + metadata + getString(" in ", repository));
038    }
039
040    private static String getString(String prefix, LocalRepository repository) {
041        if (repository == null) {
042            return "";
043        } else {
044            return prefix + repository.getId() + " (" + repository.getBasePath().toAbsolutePath() + ")";
045        }
046    }
047
048    /**
049     * Creates a new exception with the specified metadata and repository.
050     *
051     * @param metadata The missing metadata, may be {@code null}.
052     * @param repository The involved remote repository, may be {@code null}.
053     */
054    public MetadataNotFoundException(Metadata metadata, RemoteRepository repository) {
055        super(metadata, repository, "Could not find metadata " + metadata + getString(" in ", repository));
056    }
057
058    /**
059     * Creates a new exception with the specified metadata, repository and detail message.
060     *
061     * @param metadata The missing metadata, may be {@code null}.
062     * @param repository The involved remote repository, may be {@code null}.
063     * @param message The detail message, may be {@code null}.
064     */
065    public MetadataNotFoundException(Metadata metadata, RemoteRepository repository, String message) {
066        super(metadata, repository, message);
067    }
068
069    /**
070     * Creates a new exception with the specified metadata, repository and detail message.
071     *
072     * @param metadata The missing metadata, may be {@code null}.
073     * @param repository The involved remote repository, may be {@code null}.
074     * @param message The detail message, may be {@code null}.
075     * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the
076     *            exception actually just occurred.
077     */
078    public MetadataNotFoundException(
079            Metadata metadata, RemoteRepository repository, String message, boolean fromCache) {
080        super(metadata, repository, message, fromCache);
081    }
082
083    /**
084     * Creates a new exception with the specified metadata, repository, detail message and cause.
085     *
086     * @param metadata The missing metadata, may be {@code null}.
087     * @param repository The involved remote repository, may be {@code null}.
088     * @param message The detail message, may be {@code null}.
089     * @param cause The exception that caused this one, may be {@code null}.
090     */
091    public MetadataNotFoundException(Metadata metadata, RemoteRepository repository, String message, Throwable cause) {
092        super(metadata, repository, message, cause);
093    }
094}