Coverage Report - org.apache.maven.plugin.dependency.resolvers.ResolveDependenciesMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ResolveDependenciesMojo
75%
9/12
50%
1/2
2
 
 1  
 package org.apache.maven.plugin.dependency.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  
 import org.apache.maven.plugin.MojoExecutionException;
 23  
 import org.apache.maven.plugin.dependency.AbstractResolveMojo;
 24  
 import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
 25  
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
 26  
 import org.apache.maven.plugin.dependency.utils.filters.ResolveFileFilter;
 27  
 import org.apache.maven.plugin.dependency.utils.markers.SourcesFileMarkerHandler;
 28  
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 29  
 import org.apache.maven.plugins.annotations.Mojo;
 30  
 import org.apache.maven.plugins.annotations.Parameter;
 31  
 import org.apache.maven.plugins.annotations.ResolutionScope;
 32  
 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
 33  
 
 34  
 import java.io.IOException;
 35  
 
 36  
 /**
 37  
  * Goal that resolves the project dependencies from the repository.
 38  
  *
 39  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 40  
  * @version $Id: ResolveDependenciesMojo.java 1400739 2012-10-21 23:05:22Z hboutemy $
 41  
  * @since 2.0
 42  
  */
 43  
 @Mojo( name = "resolve", requiresDependencyResolution = ResolutionScope.TEST,
 44  
        defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true )
 45  2
 public class ResolveDependenciesMojo
 46  
     extends AbstractResolveMojo
 47  
 {
 48  
 
 49  
     /**
 50  
      * If we should display the scope when resolving
 51  
      *
 52  
      * @since 2.0-alpha-2
 53  
      */
 54  
     @Parameter( property = "mdep.outputScope", defaultValue = "true" )
 55  
     protected boolean outputScope;
 56  
 
 57  
     /**
 58  
      * Only used to store results for integration test validation
 59  
      */
 60  
     DependencyStatusSets results;
 61  
 
 62  
     /**
 63  
      * Main entry into mojo. Gets the list of dependencies and iterates through displaying the resolved version.
 64  
      *
 65  
      * @throws MojoExecutionException with a message if an error occurs.
 66  
      */
 67  
     public void execute()
 68  
         throws MojoExecutionException
 69  
     {
 70  
         // get sets of dependencies
 71  2
         results = this.getDependencySets( false );
 72  
 
 73  2
         String output = results.getOutput( outputAbsoluteArtifactFilename, outputScope );
 74  
         try
 75  
         {
 76  2
             if ( outputFile == null )
 77  
             {
 78  2
                 DependencyUtil.log( output, getLog() );
 79  
             }
 80  
             else
 81  
             {
 82  0
                 DependencyUtil.write( output, outputFile, appendOutput, getLog() );
 83  
             }
 84  
         }
 85  0
         catch ( IOException e )
 86  
         {
 87  0
             throw new MojoExecutionException( e.getMessage(), e );
 88  2
         }
 89  2
     }
 90  
 
 91  
     /**
 92  
      * @return Returns the results.
 93  
      */
 94  
     public DependencyStatusSets getResults()
 95  
     {
 96  2
         return this.results;
 97  
     }
 98  
 
 99  
     protected ArtifactsFilter getMarkedArtifactFilter()
 100  
     {
 101  2
         return new ResolveFileFilter( new SourcesFileMarkerHandler( this.markersDirectory ) );
 102  
     }
 103  
 }