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