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.apache.maven.artifact.resolver;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.repository.ArtifactRepository;
26
27 /**
28 * Exception caused when one or more artifacts can not be resolved because they are not found in the
29 * local or remote repositories.
30 */
31 public class MultipleArtifactsNotFoundException extends ArtifactResolutionException {
32 private final List<Artifact> resolvedArtifacts;
33 private final List<Artifact> missingArtifacts;
34
35 /** @deprecated use {@link #MultipleArtifactsNotFoundException(Artifact, List, List, List)} */
36 @Deprecated
37 public MultipleArtifactsNotFoundException(
38 Artifact originatingArtifact,
39 List<Artifact> missingArtifacts,
40 List<ArtifactRepository> remoteRepositories) {
41 this(originatingArtifact, new ArrayList<Artifact>(), missingArtifacts, remoteRepositories);
42 }
43
44 /**
45 * Create an instance of the exception with allrequired information.
46 *
47 * @param originatingArtifact the artifact that was being resolved
48 * @param resolvedArtifacts artifacts that could be resolved
49 * @param missingArtifacts artifacts that could not be resolved
50 * @param remoteRepositories remote repositories where the missing artifacts were not found
51 */
52 public MultipleArtifactsNotFoundException(
53 Artifact originatingArtifact,
54 List<Artifact> resolvedArtifacts,
55 List<Artifact> missingArtifacts,
56 List<ArtifactRepository> remoteRepositories) {
57 super(constructMessage(missingArtifacts), originatingArtifact, remoteRepositories);
58 this.resolvedArtifacts = resolvedArtifacts;
59 this.missingArtifacts = missingArtifacts;
60 }
61
62 /**
63 * artifacts that could be resolved
64 *
65 * @return {@link List} of {@link Artifact}
66 */
67 public List<Artifact> getResolvedArtifacts() {
68 return resolvedArtifacts;
69 }
70
71 /**
72 * artifacts that could NOT be resolved
73 *
74 * @return {@link List} of {@link Artifact}
75 */
76 public List<Artifact> getMissingArtifacts() {
77 return missingArtifacts;
78 }
79
80 private static String constructMessage(List<Artifact> artifacts) {
81 StringBuilder buffer = new StringBuilder(256);
82
83 buffer.append("Missing:\n");
84 buffer.append("----------\n");
85
86 int counter = 0;
87
88 for (Artifact artifact : artifacts) {
89 String message = (++counter) + ") " + artifact.getId();
90
91 buffer.append(constructMissingArtifactMessage(
92 message,
93 " ",
94 artifact.getGroupId(),
95 artifact.getArtifactId(),
96 artifact.getVersion(),
97 artifact.getType(),
98 artifact.getClassifier(),
99 artifact.getDownloadUrl(),
100 artifact.getDependencyTrail()));
101 }
102
103 buffer.append("----------\n");
104
105 int size = artifacts.size();
106
107 buffer.append(size).append(" required artifact");
108
109 if (size > 1) {
110 buffer.append("s are");
111 } else {
112 buffer.append(" is");
113 }
114
115 buffer.append(" missing.\n\nfor artifact: ");
116
117 return buffer.toString();
118 }
119 }