Coverage Report - org.apache.maven.plugin.dependency.UnpackDependenciesMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
UnpackDependenciesMojo
100%
18/18
100%
4/4
1.333
 
 1  
 package org.apache.maven.plugin.dependency;
 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.plugin.MojoExecutionException;
 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.MarkerFileFilter;
 27  
 import org.apache.maven.plugin.dependency.utils.markers.DefaultFileMarkerHandler;
 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.File;
 35  
 
 36  
 /**
 37  
  * Goal that unpacks the project dependencies from the repository to a defined
 38  
  * location.
 39  
  *
 40  
  * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
 41  
  * @version $Id: UnpackDependenciesMojo.java 1400739 2012-10-21 23:05:22Z hboutemy $
 42  
  * @since 1.0
 43  
  */
 44  
 @Mojo( name = "unpack-dependencies", requiresDependencyResolution = ResolutionScope.TEST,
 45  
        defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true )
 46  40
 public class UnpackDependenciesMojo
 47  
     extends AbstractFromDependenciesMojo
 48  
 {
 49  
     /**
 50  
      * A comma separated list of file patterns to include when unpacking the
 51  
      * artifact.  i.e. <code>**\/*.xml,**\/*.properties</code>
 52  
      * NOTE: Excludes patterns override the includes.
 53  
      * (component code = <code>return isIncluded( name ) AND !isExcluded( name );</code>)
 54  
      *
 55  
      * @since 2.0
 56  
      */
 57  
     @Parameter( property = "mdep.unpack.includes" )
 58  
     private String includes;
 59  
 
 60  
     /**
 61  
      * A comma separated list of file patterns to exclude when unpacking the
 62  
      * artifact.  i.e. <code>**\/*.xml,**\/*.properties</code>
 63  
      * NOTE: Excludes patterns override the includes.
 64  
      * (component code = <code>return isIncluded( name ) AND !isExcluded( name );</code>)
 65  
      *
 66  
      * @since 2.0
 67  
      */
 68  
     @Parameter( property = "mdep.unpack.excludes" )
 69  
     private String excludes;
 70  
 
 71  
     /**
 72  
      * Main entry into mojo. This method gets the dependencies and iterates
 73  
      * through each one passing it to DependencyUtil.unpackFile().
 74  
      *
 75  
      * @throws MojoExecutionException with a message if an error occurs.
 76  
      * @see #getDependencies
 77  
      * @see DependencyUtil#unpackFile(Artifact, File, File, ArchiverManager,
 78  
      *      Log)
 79  
      */
 80  
     public void execute()
 81  
         throws MojoExecutionException
 82  
     {
 83  49
         DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact );
 84  
 
 85  46
         for ( Artifact artifact : dss.getResolvedDependencies() )
 86  
         {
 87  
             File destDir;
 88  150
             destDir = DependencyUtil.getFormattedOutputDirectory( useSubDirectoryPerScope, useSubDirectoryPerType,
 89  
                                                                   useSubDirectoryPerArtifact, useRepositoryLayout,
 90  
                                                                   stripVersion, outputDirectory, artifact );
 91  150
             unpack( artifact, destDir, getIncludes(), getExcludes() );
 92  150
             DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler( artifact, this.markersDirectory );
 93  150
             handler.setMarker();
 94  150
         }
 95  
 
 96  46
         for ( Artifact artifact : dss.getSkippedDependencies() )
 97  
         {
 98  3
             getLog().info( artifact.getFile().getName() + " already exists in destination." );
 99  
         }
 100  46
     }
 101  
 
 102  
     protected ArtifactsFilter getMarkedArtifactFilter()
 103  
     {
 104  48
         return new MarkerFileFilter( this.overWriteReleases, this.overWriteSnapshots, this.overWriteIfNewer,
 105  
                                      new DefaultFileMarkerHandler( this.markersDirectory ) );
 106  
     }
 107  
 
 108  
     /**
 109  
      * @return Returns a comma separated list of excluded items
 110  
      */
 111  
     public String getExcludes()
 112  
     {
 113  150
         return DependencyUtil.cleanToBeTokenizedString( this.excludes );
 114  
     }
 115  
 
 116  
     /**
 117  
      * @param excludes A comma separated list of items to exclude
 118  
      *                 i.e. <code>**\/*.xml, **\/*.properties</code>
 119  
      */
 120  
     public void setExcludes( String excludes )
 121  
     {
 122  3
         this.excludes = excludes;
 123  3
     }
 124  
 
 125  
     /**
 126  
      * @return Returns a comma separated list of included items
 127  
      */
 128  
     public String getIncludes()
 129  
     {
 130  150
         return DependencyUtil.cleanToBeTokenizedString( this.includes );
 131  
     }
 132  
 
 133  
     /**
 134  
      * @param includes A comma separated list of items to include
 135  
      *                 i.e. <code>**\/*.xml, **\/*.properties</code>
 136  
      */
 137  
     public void setIncludes( String includes )
 138  
     {
 139  3
         this.includes = includes;
 140  3
     }
 141  
 }