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( 256 );
88  
89          buffer.append( "Missing:\n" );
90          buffer.append( "----------\n" );
91  
92          int counter = 0;
93  
94          for ( Artifact artifact : artifacts )
95          {
96              String message = ( ++counter ) + ") " + artifact.getId();
97  
98              buffer.append( constructMissingArtifactMessage( message, "  ", artifact.getGroupId(),
99                      artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(),
100                     artifact.getDownloadUrl(), 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         {
111             buffer.append( "s are" );
112         }
113         else
114         {
115             buffer.append( " is" );
116         }
117 
118         buffer.append( " missing.\n\nfor artifact: " );
119 
120         return buffer.toString();
121     }
122 
123 }