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