View Javadoc
1   /*******************************************************************************
2    * Copyright (c) 2010, 2014 Sonatype, Inc.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *    Sonatype, Inc. - initial API and implementation
10   *******************************************************************************/
11  package org.eclipse.aether.transfer;
12  
13  import org.eclipse.aether.artifact.Artifact;
14  import org.eclipse.aether.artifact.ArtifactProperties;
15  import org.eclipse.aether.repository.RemoteRepository;
16  
17  /**
18   * Thrown when an artifact was not found in a particular repository.
19   */
20  public class ArtifactNotFoundException
21      extends ArtifactTransferException
22  {
23  
24      /**
25       * Creates a new exception with the specified artifact and repository.
26       * 
27       * @param artifact The missing artifact, may be {@code null}.
28       * @param repository The involved remote repository, may be {@code null}.
29       */
30      public ArtifactNotFoundException( Artifact artifact, RemoteRepository repository )
31      {
32          super( artifact, repository, getMessage( artifact, repository ) );
33      }
34  
35      private static String getMessage( Artifact artifact, RemoteRepository repository )
36      {
37          StringBuilder buffer = new StringBuilder( 256 );
38          buffer.append( "Could not find artifact " ).append( artifact );
39          buffer.append( getString( " in ", repository ) );
40          if ( artifact != null )
41          {
42              String localPath = artifact.getProperty( ArtifactProperties.LOCAL_PATH, null );
43              if ( localPath != null && repository == null )
44              {
45                  buffer.append( " at specified path " ).append( localPath );
46              }
47              String downloadUrl = artifact.getProperty( ArtifactProperties.DOWNLOAD_URL, null );
48              if ( downloadUrl != null )
49              {
50                  buffer.append( ", try downloading from " ).append( downloadUrl );
51              }
52          }
53          return buffer.toString();
54      }
55  
56      /**
57       * Creates a new exception with the specified artifact, repository and detail message.
58       * 
59       * @param artifact The missing artifact, may be {@code null}.
60       * @param repository The involved remote repository, may be {@code null}.
61       * @param message The detail message, may be {@code null}.
62       */
63      public ArtifactNotFoundException( Artifact artifact, RemoteRepository repository, String message )
64      {
65          super( artifact, repository, message );
66      }
67  
68      /**
69       * Creates a new exception with the specified artifact, repository and detail message.
70       * 
71       * @param artifact The missing artifact, may be {@code null}.
72       * @param repository The involved remote repository, may be {@code null}.
73       * @param message The detail message, may be {@code null}.
74       * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the
75       *            exception actually just occurred.
76       */
77      public ArtifactNotFoundException( Artifact artifact, RemoteRepository repository, String message, boolean fromCache )
78      {
79          super( artifact, repository, message, fromCache );
80      }
81  
82      /**
83       * Creates a new exception with the specified artifact, repository, detail message and cause.
84       * 
85       * @param artifact The missing artifact, may be {@code null}.
86       * @param repository The involved remote repository, may be {@code null}.
87       * @param message The detail message, may be {@code null}.
88       * @param cause The exception that caused this one, may be {@code null}.
89       */
90      public ArtifactNotFoundException( Artifact artifact, RemoteRepository repository, String message, Throwable cause )
91      {
92          super( artifact, repository, message, cause );
93      }
94  
95  }