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.artifact.Artifact; 022import org.eclipse.aether.artifact.ArtifactProperties; 023import org.eclipse.aether.repository.RemoteRepository; 024 025/** 026 * Thrown when an artifact was not found in a particular repository. 027 */ 028public class ArtifactNotFoundException extends ArtifactTransferException { 029 030 /** 031 * Creates a new exception with the specified artifact and repository. 032 * 033 * @param artifact The missing artifact, may be {@code null}. 034 * @param repository The involved remote repository, may be {@code null}. 035 */ 036 public ArtifactNotFoundException(Artifact artifact, RemoteRepository repository) { 037 super(artifact, repository, getMessage(artifact, repository)); 038 } 039 040 private static String getMessage(Artifact artifact, RemoteRepository repository) { 041 StringBuilder buffer = new StringBuilder(256); 042 buffer.append("Could not find artifact ").append(artifact); 043 buffer.append(getString(" in ", repository)); 044 if (artifact != null) { 045 String localPath = artifact.getProperty(ArtifactProperties.LOCAL_PATH, null); 046 if (localPath != null && repository == null) { 047 buffer.append(" at specified path ").append(localPath); 048 } 049 String downloadUrl = artifact.getProperty(ArtifactProperties.DOWNLOAD_URL, null); 050 if (downloadUrl != null) { 051 buffer.append(", try downloading from ").append(downloadUrl); 052 } 053 } 054 return buffer.toString(); 055 } 056 057 /** 058 * Creates a new exception with the specified artifact, repository and detail message. 059 * 060 * @param artifact The missing artifact, may be {@code null}. 061 * @param repository The involved remote repository, may be {@code null}. 062 * @param message The detail message, may be {@code null}. 063 */ 064 public ArtifactNotFoundException(Artifact artifact, RemoteRepository repository, String message) { 065 super(artifact, repository, message); 066 } 067 068 /** 069 * Creates a new exception with the specified artifact, repository and detail message. 070 * 071 * @param artifact The missing artifact, may be {@code null}. 072 * @param repository The involved remote repository, may be {@code null}. 073 * @param message The detail message, may be {@code null}. 074 * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the 075 * exception actually just occurred. 076 */ 077 public ArtifactNotFoundException( 078 Artifact artifact, RemoteRepository repository, String message, boolean fromCache) { 079 super(artifact, repository, message, fromCache); 080 } 081 082 /** 083 * Creates a new exception with the specified artifact, repository, detail message and cause. 084 * 085 * @param artifact The missing artifact, may be {@code null}. 086 * @param repository The involved remote repository, may be {@code null}. 087 * @param message The detail message, may be {@code null}. 088 * @param cause The exception that caused this one, may be {@code null}. 089 */ 090 public ArtifactNotFoundException(Artifact artifact, RemoteRepository repository, String message, Throwable cause) { 091 super(artifact, repository, message, cause); 092 } 093}