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