Coverage Report - org.apache.maven.plugin.dependency.resolvers.ResolveDependencySourcesMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ResolveDependencySourcesMojo
0%
0/28
0%
0/6
3.5
 
 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 java.io.IOException;
 23  
 import java.util.Iterator;
 24  
 
 25  
 import org.apache.maven.artifact.Artifact;
 26  
 import org.apache.maven.plugin.MojoExecutionException;
 27  
 import org.apache.maven.plugin.dependency.AbstractResolveMojo;
 28  
 import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
 29  
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
 30  
 import org.apache.maven.plugin.dependency.utils.filters.ResolveFileFilter;
 31  
 import org.apache.maven.plugin.dependency.utils.markers.SourcesFileMarkerHandler;
 32  
 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
 33  
 
 34  
 /**
 35  
  * Goal that resolves the project source dependencies from the repository.
 36  
  * 
 37  
  * @goal sources
 38  
  * @phase generate-sources
 39  
  * @requiresDependencyResolution test
 40  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 41  
  * @version $Id: ResolveDependencySourcesMojo.java 728546 2008-12-21 22:56:51Z bentmann $
 42  
  * @since 2.0-alpha2
 43  
  */
 44  0
 public class ResolveDependencySourcesMojo
 45  
     extends AbstractResolveMojo
 46  
 {
 47  
 
 48  
     private static final String SOURCE_TYPE = "java-source";
 49  
 
 50  
     private static final String SOURCE_CLASSIFIER = "sources";
 51  
 
 52  
     /**
 53  
      * Only used to store results for integration test validation
 54  
      */
 55  
     DependencyStatusSets results;
 56  
     
 57  
     /**
 58  
      * Main entry into mojo. Gets the list of dependencies and iterates through
 59  
      * resolving the source jars.
 60  
      * 
 61  
      * @throws MojoExecutionException
 62  
      *             with a message if an error occurs.
 63  
      * 
 64  
      */
 65  
     public void execute()
 66  
         throws MojoExecutionException
 67  
     {
 68  0
         this.classifier = SOURCE_CLASSIFIER;
 69  0
         this.type = SOURCE_TYPE;
 70  
         // get sets of dependencies
 71  0
         results = this.getDependencySets( false );
 72  
         
 73  0
         SourcesFileMarkerHandler handler = new SourcesFileMarkerHandler(this.markersDirectory);
 74  0
         handler.setResolved( true );
 75  
         
 76  0
         Iterator iter = results.getResolvedDependencies().iterator();
 77  0
         while (iter.hasNext())
 78  
         {
 79  0
             Artifact artifact = (Artifact) iter.next();
 80  0
             handler.setArtifact( artifact );
 81  0
             handler.setMarker();
 82  0
         }
 83  
         
 84  0
         handler.setResolved( false );
 85  0
         iter = results.getUnResolvedDependencies().iterator();
 86  0
         while (iter.hasNext())
 87  
         {
 88  0
             Artifact artifact = (Artifact) iter.next();
 89  0
             handler.setArtifact( artifact );
 90  0
             handler.setMarker();
 91  0
         }
 92  
 
 93  0
         String output = results.getOutput( outputAbsoluteArtifactFilename, false );
 94  
         try
 95  
         {
 96  0
             if ( outputFile == null )
 97  
             {
 98  0
                 DependencyUtil.log( output, getLog() );
 99  
             }
 100  
             else
 101  
             {
 102  0
                 DependencyUtil.write( output, outputFile, getLog() );
 103  
             }
 104  
         }
 105  0
         catch ( IOException e )
 106  
         {
 107  0
             throw new MojoExecutionException(e.getMessage(),e);
 108  0
         }
 109  0
     }
 110  
 
 111  
     protected ArtifactsFilter getMarkedArtifactFilter()
 112  
     {
 113  0
         return new ResolveFileFilter( new SourcesFileMarkerHandler( this.markersDirectory ) );
 114  
     }
 115  
 }