Coverage Report - org.apache.maven.plugin.dependency.utils.resolvers.DefaultArtifactsResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultArtifactsResolver
100%
24/24
67%
4/6
4.5
 
 1  
 package org.apache.maven.plugin.dependency.utils.resolvers;
 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  
 /**
 23  
  * 
 24  
  * 
 25  
  */
 26  
 
 27  
 import java.util.HashSet;
 28  
 import java.util.Iterator;
 29  
 import java.util.List;
 30  
 import java.util.Set;
 31  
 
 32  
 import org.apache.maven.artifact.Artifact;
 33  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 34  
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 35  
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 36  
 import org.apache.maven.artifact.resolver.ArtifactResolver;
 37  
 import org.apache.maven.plugin.MojoExecutionException;
 38  
 import org.apache.maven.plugin.logging.Log;
 39  
 
 40  
 /**
 41  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 42  
  * @version $Id: DefaultArtifactsResolver.java 728546 2008-12-21 22:56:51Z bentmann $
 43  
  */
 44  
 public class DefaultArtifactsResolver
 45  
     implements ArtifactsResolver
 46  
 {
 47  
     ArtifactResolver resolver;
 48  
 
 49  
     ArtifactRepository local;
 50  
 
 51  
     List remoteRepositories;
 52  
 
 53  
     boolean stopOnFailure;
 54  
 
 55  
     public DefaultArtifactsResolver( ArtifactResolver theResolver, ArtifactRepository theLocal,
 56  
                                     List theRemoteRepositories, boolean theStopOnFailure )
 57  8
     {
 58  8
         this.resolver = theResolver;
 59  8
         this.local = theLocal;
 60  8
         this.remoteRepositories = theRemoteRepositories;
 61  8
         this.stopOnFailure = theStopOnFailure;
 62  8
     }
 63  
 
 64  
     /*
 65  
      * (non-Javadoc)
 66  
      * 
 67  
      * @see org.apache.mojo.dependency.utils.resolvers.ArtifactsResolver#resolve(java.util.Set,
 68  
      *      org.apache.maven.plugin.logging.Log)
 69  
      */
 70  
     public Set resolve( Set artifacts, Log log )
 71  
         throws MojoExecutionException
 72  
     {
 73  
 
 74  8
         Set resolvedArtifacts = new HashSet();
 75  8
         Iterator iter = artifacts.iterator();
 76  36
         while ( iter.hasNext() )
 77  
         {
 78  32
             Artifact artifact = (Artifact) iter.next();
 79  
             try
 80  
             {
 81  32
                 resolver.resolve( artifact, remoteRepositories, local );
 82  28
                 resolvedArtifacts.add( artifact );
 83  
             }
 84  2
             catch ( ArtifactResolutionException ex )
 85  
             {
 86  
                 // an error occurred during resolution, log it an continue
 87  2
                 log.debug( "error resolving: " + artifact.getId() );
 88  2
                 log.debug( ex );
 89  2
                 if ( stopOnFailure )
 90  
                 {
 91  2
                     throw new MojoExecutionException( "error resolving: " + artifact.getId(), ex );
 92  
                 }
 93  
             }
 94  2
             catch ( ArtifactNotFoundException ex )
 95  
             {
 96  
                 // not found, log it and continue
 97  2
                 log.debug( "not found in any repository: " + artifact.getId() );
 98  2
                 if ( stopOnFailure )
 99  
                 {
 100  2
                     throw new MojoExecutionException( "not found in any repository: " + artifact.getId(), ex );
 101  
                 }
 102  28
             }
 103  28
         }
 104  4
         return resolvedArtifacts;
 105  
     }
 106  
 
 107  
 }