View Javadoc
1   package org.eclipse.aether.transfer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.eclipse.aether.artifact.Artifact;
23  import org.eclipse.aether.artifact.ArtifactProperties;
24  import org.eclipse.aether.repository.RemoteRepository;
25  
26  /**
27   * Thrown when an artifact was not found in a particular repository.
28   */
29  public class ArtifactNotFoundException
30      extends ArtifactTransferException
31  {
32  
33      /**
34       * Creates a new exception with the specified artifact and repository.
35       * 
36       * @param artifact The missing artifact, may be {@code null}.
37       * @param repository The involved remote repository, may be {@code null}.
38       */
39      public ArtifactNotFoundException( Artifact artifact, RemoteRepository repository )
40      {
41          super( artifact, repository, getMessage( artifact, repository ) );
42      }
43  
44      private static String getMessage( Artifact artifact, RemoteRepository repository )
45      {
46          StringBuilder buffer = new StringBuilder( 256 );
47          buffer.append( "Could not find artifact " ).append( artifact );
48          buffer.append( getString( " in ", repository ) );
49          if ( artifact != null )
50          {
51              String localPath = artifact.getProperty( ArtifactProperties.LOCAL_PATH, null );
52              if ( localPath != null && repository == null )
53              {
54                  buffer.append( " at specified path " ).append( localPath );
55              }
56              String downloadUrl = artifact.getProperty( ArtifactProperties.DOWNLOAD_URL, null );
57              if ( downloadUrl != null )
58              {
59                  buffer.append( ", try downloading from " ).append( downloadUrl );
60              }
61          }
62          return buffer.toString();
63      }
64  
65      /**
66       * Creates a new exception with the specified artifact, repository and detail message.
67       * 
68       * @param artifact The missing artifact, may be {@code null}.
69       * @param repository The involved remote repository, may be {@code null}.
70       * @param message The detail message, may be {@code null}.
71       */
72      public ArtifactNotFoundException( Artifact artifact, RemoteRepository repository, String message )
73      {
74          super( artifact, repository, message );
75      }
76  
77      /**
78       * Creates a new exception with the specified artifact, repository and detail message.
79       * 
80       * @param artifact The missing artifact, may be {@code null}.
81       * @param repository The involved remote repository, may be {@code null}.
82       * @param message The detail message, may be {@code null}.
83       * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the
84       *            exception actually just occurred.
85       */
86      public ArtifactNotFoundException( Artifact artifact, RemoteRepository repository, String message, boolean fromCache )
87      {
88          super( artifact, repository, message, fromCache );
89      }
90  
91      /**
92       * Creates a new exception with the specified artifact, repository, detail message and cause.
93       * 
94       * @param artifact The missing artifact, may be {@code null}.
95       * @param repository The involved remote repository, may be {@code null}.
96       * @param message The detail message, may be {@code null}.
97       * @param cause The exception that caused this one, may be {@code null}.
98       */
99      public ArtifactNotFoundException( Artifact artifact, RemoteRepository repository, String message, Throwable cause )
100     {
101         super( artifact, repository, message, cause );
102     }
103 
104 }