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