Coverage Report - org.apache.maven.plugin.dependency.resolvers.ResolvePluginsMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ResolvePluginsMojo
0%
0/44
0%
0/18
7.333
 
 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.artifact.Artifact;
 23  
 import org.apache.maven.artifact.repository.ArtifactRepository;
 24  
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 25  
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 26  
 import org.apache.maven.plugin.MojoExecutionException;
 27  
 import org.apache.maven.plugin.dependency.AbstractResolveMojo;
 28  
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
 29  
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 30  
 import org.apache.maven.plugins.annotations.Mojo;
 31  
 import org.apache.maven.plugins.annotations.Parameter;
 32  
 import org.apache.maven.project.ProjectBuildingException;
 33  
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
 34  
 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
 35  
 import org.codehaus.plexus.util.IOUtil;
 36  
 
 37  
 import java.io.FileWriter;
 38  
 import java.io.IOException;
 39  
 import java.io.Writer;
 40  
 import java.util.HashSet;
 41  
 import java.util.List;
 42  
 import java.util.Set;
 43  
 
 44  
 /**
 45  
  * Goal that resolves all project plugins and reports and their dependencies.
 46  
  *
 47  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 48  
  * @version $Id: ResolvePluginsMojo.java 1400739 2012-10-21 23:05:22Z hboutemy $
 49  
  * @since 2.0
 50  
  */
 51  
 @Mojo( name = "resolve-plugins", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true )
 52  0
 public class ResolvePluginsMojo
 53  
     extends AbstractResolveMojo
 54  
 {
 55  
 
 56  
     /**
 57  
      * Remote repositories which will be searched for plugins.
 58  
      */
 59  
     @Parameter( defaultValue = "${project.pluginArtifactRepositories}", readonly = true, required = true )
 60  
     private List<ArtifactRepository> remotePluginRepositories;
 61  
 
 62  
     /**
 63  
      * If we should exclude transitive dependencies
 64  
      */
 65  
     @Parameter( property = "excludeTransitive", defaultValue = "false" )
 66  
     private boolean excludeTransitive;
 67  
 
 68  
     /**
 69  
      * Main entry into mojo. Gets the list of dependencies and iterates through
 70  
      * displaying the resolved version.
 71  
      *
 72  
      * @throws MojoExecutionException with a message if an error occurs.
 73  
      */
 74  
     public void execute()
 75  
         throws MojoExecutionException
 76  
     {
 77  0
         Writer outputWriter = null;
 78  
 
 79  
         try
 80  
         {
 81  0
             Set<Artifact> plugins = resolvePluginArtifacts();
 82  
 
 83  0
             if ( this.outputFile != null )
 84  
             {
 85  0
                 outputFile.getParentFile().mkdirs();
 86  
 
 87  0
                 outputWriter = new FileWriter( outputFile );
 88  
             }
 89  
 
 90  0
             for ( Artifact plugin : plugins )
 91  
             {
 92  0
                 String logStr = "Plugin Resolved: " + DependencyUtil.getFormattedFileName( plugin, false );
 93  0
                 if ( !silent )
 94  
                 {
 95  0
                     this.getLog().info( logStr );
 96  
                 }
 97  
 
 98  0
                 if ( outputWriter != null )
 99  
                 {
 100  0
                     outputWriter.write( logStr );
 101  0
                     outputWriter.write( "\n" );
 102  
                 }
 103  
 
 104  0
                 if ( !excludeTransitive )
 105  
                 {
 106  0
                     for ( Artifact artifact : resolveArtifactDependencies( plugin ) )
 107  
                     {
 108  0
                         logStr =
 109  
                             "    Plugin Dependency Resolved: " + DependencyUtil.getFormattedFileName( artifact, false );
 110  
 
 111  0
                         if ( !silent )
 112  
                         {
 113  0
                             this.getLog().info( logStr );
 114  
                         }
 115  
 
 116  0
                         if ( outputWriter != null )
 117  
                         {
 118  0
                             outputWriter.write( logStr );
 119  0
                             outputWriter.write( "\n" );
 120  
                         }
 121  
                     }
 122  
                 }
 123  0
             }
 124  
         }
 125  0
         catch ( IOException e )
 126  
         {
 127  0
             throw new MojoExecutionException( "Nested:", e );
 128  
         }
 129  0
         catch ( ArtifactResolutionException e )
 130  
         {
 131  0
             throw new MojoExecutionException( "Nested:", e );
 132  
         }
 133  0
         catch ( ArtifactNotFoundException e )
 134  
         {
 135  0
             throw new MojoExecutionException( "Nested:", e );
 136  
         }
 137  0
         catch ( ProjectBuildingException e )
 138  
         {
 139  0
             throw new MojoExecutionException( "Nested:", e );
 140  
         }
 141  0
         catch ( InvalidDependencyVersionException e )
 142  
         {
 143  0
             throw new MojoExecutionException( "Nested:", e );
 144  
         }
 145  
         finally
 146  
         {
 147  0
             IOUtil.close( outputWriter );
 148  0
         }
 149  
 
 150  0
     }
 151  
 
 152  
     /**
 153  
      * This method resolves the plugin artifacts from the project.
 154  
      *
 155  
      * @return set of resolved plugin artifacts.
 156  
      * @throws ArtifactResolutionException
 157  
      * @throws ArtifactNotFoundException
 158  
      */
 159  
     protected Set<Artifact> resolvePluginArtifacts()
 160  
         throws ArtifactResolutionException, ArtifactNotFoundException
 161  
     {
 162  0
         @SuppressWarnings( "unchecked" ) Set<Artifact> plugins = project.getPluginArtifacts();
 163  0
         @SuppressWarnings( "unchecked" ) Set<Artifact> reports = project.getReportArtifacts();
 164  
 
 165  0
         Set<Artifact> artifacts = new HashSet<Artifact>();
 166  0
         artifacts.addAll( reports );
 167  0
         artifacts.addAll( plugins );
 168  
 
 169  0
         for ( Artifact artifact : artifacts )
 170  
         {
 171  
             // resolve the new artifact
 172  0
             this.resolver.resolve( artifact, this.remotePluginRepositories, this.getLocal() );
 173  
         }
 174  0
         return artifacts;
 175  
     }
 176  
 
 177  
     protected ArtifactsFilter getMarkedArtifactFilter()
 178  
     {
 179  0
         return null;
 180  
     }
 181  
 }