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.List;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.repository.ArtifactRepository;
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 static final String LS = System.lineSeparator();
36
37 private final List<Artifact> resolvedArtifacts;
38 private final List<Artifact> missingArtifacts;
39
40 /**
41 * @param originatingArtifact the artifact that was being resolved
42 * @param missingArtifacts artifacts that could not be resolved
43 * @param remoteRepositories remote repositories where the missing artifacts were not found
44 * @deprecated use {@link #MultipleArtifactsNotFoundException(Artifact, List, List, List)}
45 */
46 @Deprecated
47 public MultipleArtifactsNotFoundException( Artifact originatingArtifact,
48 List<Artifact> missingArtifacts,
49 List<ArtifactRepository> remoteRepositories )
50 {
51 this( originatingArtifact, new ArrayList<>(), missingArtifacts, remoteRepositories );
52 }
53
54 /**
55 * Create an instance of the exception with all required information.
56 *
57 * @param originatingArtifact the artifact that was being resolved
58 * @param resolvedArtifacts artifacts that could be resolved
59 * @param missingArtifacts artifacts that could not be resolved
60 * @param remoteRepositories remote repositories where the missing artifacts were not found
61 */
62 public MultipleArtifactsNotFoundException( Artifact originatingArtifact,
63 List<Artifact> resolvedArtifacts,
64 List<Artifact> missingArtifacts,
65 List<ArtifactRepository> remoteRepositories )
66 {
67 super( constructMessage( missingArtifacts ), originatingArtifact, remoteRepositories );
68 this.resolvedArtifacts = resolvedArtifacts;
69 this.missingArtifacts = missingArtifacts;
70 }
71
72 /**
73 * artifacts that could be resolved
74 *
75 * @return {@link List} of {@link Artifact}
76 */
77 public List<Artifact> getResolvedArtifacts()
78 {
79 return resolvedArtifacts;
80 }
81
82 /**
83 * artifacts that could NOT be resolved
84 *
85 * @return {@link List} of {@link Artifact}
86 */
87 public List<Artifact> getMissingArtifacts()
88 {
89 return missingArtifacts;
90 }
91
92 private static String constructMessage( List<Artifact> artifacts )
93 {
94 StringBuilder buffer = new StringBuilder( 256 );
95
96 buffer.append( "Missing:" ).append( LS );
97 buffer.append( "----------" ).append( LS );
98
99 int counter = 0;
100
101 for ( Artifact artifact : artifacts )
102 {
103 String message = ( ++counter ) + ") " + artifact.getId();
104
105 buffer.append( constructMissingArtifactMessage( message, " ", artifact.getGroupId(),
106 artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(),
107 artifact.getDownloadUrl(), artifact.getDependencyTrail() ) );
108 }
109
110 buffer.append( "----------" ).append( LS );
111
112 int size = artifacts.size();
113
114 buffer.append( size ).append( " required artifact" );
115
116 if ( size > 1 )
117 {
118 buffer.append( "s are" );
119 }
120 else
121 {
122 buffer.append( " is" );
123 }
124
125 buffer.append( " missing." ).append( LS ).append( LS ).append( "for artifact: " );
126
127 return buffer.toString();
128 }
129
130 }