001 package org.apache.maven.artifact.resolver;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.ArrayList;
023 import java.util.List;
024
025 import org.apache.maven.artifact.Artifact;
026 import org.apache.maven.artifact.repository.ArtifactRepository;
027
028 /**
029 * Exception caused when one or more artifacts can not be resolved because they are not found in the
030 * local or remote repositories.
031 */
032 public class MultipleArtifactsNotFoundException
033 extends ArtifactResolutionException
034 {
035 private final List<Artifact> resolvedArtifacts;
036 private final List<Artifact> missingArtifacts;
037
038 /** @deprecated use {@link #MultipleArtifactsNotFoundException(Artifact, List, List, List)} */
039 @Deprecated
040 public MultipleArtifactsNotFoundException( Artifact originatingArtifact,
041 List<Artifact> missingArtifacts,
042 List<ArtifactRepository> remoteRepositories )
043 {
044 this( originatingArtifact, new ArrayList<Artifact>(), missingArtifacts, remoteRepositories );
045 }
046
047 /**
048 * Create an instance of the exception with allrequired information.
049 *
050 * @param originatingArtifact the artifact that was being resolved
051 * @param resolvedArtifacts artifacts that could be resolved
052 * @param missingArtifacts artifacts that could not be resolved
053 * @param remoteRepositories remote repositories where the missing artifacts were not found
054 */
055 public MultipleArtifactsNotFoundException( Artifact originatingArtifact,
056 List<Artifact> resolvedArtifacts,
057 List<Artifact> missingArtifacts,
058 List<ArtifactRepository> remoteRepositories )
059 {
060 super( constructMessage( missingArtifacts ), originatingArtifact, remoteRepositories );
061 this.resolvedArtifacts = resolvedArtifacts;
062 this.missingArtifacts = missingArtifacts;
063 }
064
065 /**
066 * artifacts that could be resolved
067 *
068 * @return {@link List} of {@link Artifact}
069 */
070 public List<Artifact> getResolvedArtifacts()
071 {
072 return resolvedArtifacts;
073 }
074
075 /**
076 * artifacts that could NOT be resolved
077 *
078 * @return {@link List} of {@link Artifact}
079 */
080 public List<Artifact> getMissingArtifacts()
081 {
082 return missingArtifacts;
083 }
084
085 private static String constructMessage( List<Artifact> artifacts )
086 {
087 StringBuilder buffer = new StringBuilder( "Missing:\n" );
088
089 buffer.append( "----------\n" );
090
091 int counter = 0;
092
093 for ( Artifact artifact : artifacts )
094 {
095 String message = ( ++counter ) + ") " + artifact.getId();
096
097 buffer.append( constructMissingArtifactMessage( message, " ", artifact.getGroupId(),
098 artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(),
099 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 }