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, null, repository));
38 }
39
40 /**
41 * Creates a new exception with the specified system artifact and expected local path.
42 *
43 * @param artifact The missing artifact, may be {@code null}.
44 * @param localPath The expected local path of missing artifact, may be {@code null}.
45 *
46 * @since 2.0.0
47 */
48 public ArtifactNotFoundException(Artifact artifact, String localPath) {
49 super(artifact, null, getMessage(artifact, localPath, null));
50 }
51
52 private static String getMessage(Artifact artifact, String localPath, RemoteRepository repository) {
53 StringBuilder buffer = new StringBuilder(256);
54 buffer.append("Could not find artifact ").append(artifact);
55 buffer.append(getString(" in ", repository));
56 if (artifact != null) {
57 if (localPath != null && repository == null) {
58 buffer.append(" at specified path ").append(localPath);
59 }
60 String downloadUrl = artifact.getProperty(ArtifactProperties.DOWNLOAD_URL, null);
61 if (downloadUrl != null) {
62 buffer.append(", try downloading from ").append(downloadUrl);
63 }
64 }
65 return buffer.toString();
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 */
75 public ArtifactNotFoundException(Artifact artifact, RemoteRepository repository, String message) {
76 super(artifact, repository, message);
77 }
78
79 /**
80 * Creates a new exception with the specified artifact, repository and detail message.
81 *
82 * @param artifact The missing artifact, may be {@code null}.
83 * @param repository The involved remote repository, may be {@code null}.
84 * @param message The detail message, may be {@code null}.
85 * @param fromCache {@code true} if the exception was played back from the error cache, {@code false} if the
86 * exception actually just occurred.
87 */
88 public ArtifactNotFoundException(
89 Artifact artifact, RemoteRepository repository, String message, boolean fromCache) {
90 super(artifact, repository, message, fromCache);
91 }
92
93 /**
94 * Creates a new exception with the specified artifact, repository, detail message and cause.
95 *
96 * @param artifact The missing artifact, may be {@code null}.
97 * @param repository The involved remote repository, may be {@code null}.
98 * @param message The detail message, may be {@code null}.
99 * @param cause The exception that caused this one, may be {@code null}.
100 */
101 public ArtifactNotFoundException(Artifact artifact, RemoteRepository repository, String message, Throwable cause) {
102 super(artifact, repository, message, cause);
103 }
104 }