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