Coverage Report - org.apache.maven.plugin.assembly.mojos.UnpackMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
UnpackMojo
0%
0/27
0%
0/14
11
 
 1  
 package org.apache.maven.plugin.assembly.mojos;
 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.AbstractMojo;
 24  
 import org.apache.maven.plugin.MojoExecutionException;
 25  
 import org.apache.maven.plugin.MojoFailureException;
 26  
 import org.apache.maven.plugin.assembly.archive.ArchiveExpansionException;
 27  
 import org.apache.maven.plugin.assembly.utils.AssemblyFileUtils;
 28  
 import org.apache.maven.plugins.annotations.Component;
 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.project.MavenProject;
 33  
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 34  
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 35  
 
 36  
 import java.io.File;
 37  
 import java.util.Iterator;
 38  
 import java.util.LinkedHashSet;
 39  
 import java.util.Set;
 40  
 
 41  
 /**
 42  
  * Unpack project dependencies. Currently supports dependencies of type jar and zip.
 43  
  *
 44  
  * @version $Id: UnpackMojo.java 1359773 2012-07-10 16:43:50Z tchemit $
 45  
  * @deprecated Use org.apache.maven.plugins:maven-dependency-plugin goal: unpack or unpack-dependencies instead.
 46  
  */
 47  
 @Mojo( name = "unpack", requiresDependencyResolution = ResolutionScope.TEST, inheritByDefault = false )
 48  
 @Deprecated
 49  0
 public class UnpackMojo
 50  
     extends AbstractMojo
 51  
 {
 52  
 
 53  
     /**
 54  
      */
 55  
     @Component
 56  
     private MavenProject project;
 57  
 
 58  
     /**
 59  
      */
 60  
     @Component
 61  
     private ArchiverManager archiverManager;
 62  
 
 63  
     /**
 64  
      * Directory to unpack JARs into if needed
 65  
      */
 66  
     @Parameter( defaultValue = "${project.build.directory}/assembly/work", required = true )
 67  
     protected File workDirectory;
 68  
 
 69  
     /**
 70  
      * Unpacks the archive file.
 71  
      *
 72  
      * @throws MojoExecutionException
 73  
      */
 74  
     public void execute()
 75  
         throws MojoExecutionException, MojoFailureException
 76  
     {
 77  0
         final Set<Artifact> dependencies = new LinkedHashSet<Artifact>();
 78  
 
 79  0
         if ( project.getArtifact() != null && project.getArtifact().getFile() != null )
 80  
         {
 81  0
             dependencies.add( project.getArtifact() );
 82  
         }
 83  
 
 84  
         @SuppressWarnings( "unchecked" )
 85  0
         final Set<Artifact> projectArtifacts = project.getArtifacts();
 86  0
         if ( projectArtifacts != null )
 87  
         {
 88  0
             dependencies.addAll( projectArtifacts );
 89  
         }
 90  
 
 91  0
         for ( final Iterator<Artifact> j = dependencies.iterator(); j.hasNext(); )
 92  
         {
 93  0
             final Artifact artifact = j.next();
 94  
 
 95  0
             final String name = artifact.getFile().getName();
 96  
 
 97  0
             final File tempLocation = new File( workDirectory, name.substring( 0, name.lastIndexOf( '.' ) ) );
 98  0
             boolean process = false;
 99  0
             if ( !tempLocation.exists() )
 100  
             {
 101  0
                 tempLocation.mkdirs();
 102  0
                 process = true;
 103  
             }
 104  0
             else if ( artifact.getFile().lastModified() > tempLocation.lastModified() )
 105  
             {
 106  0
                 process = true;
 107  
             }
 108  
 
 109  0
             if ( process )
 110  
             {
 111  0
                 final File file = artifact.getFile();
 112  
                 try
 113  
                 {
 114  0
                     AssemblyFileUtils.unpack( file, tempLocation, archiverManager );
 115  
                 }
 116  0
                 catch ( final NoSuchArchiverException e )
 117  
                 {
 118  0
                     getLog().info( "Skip unpacking dependency file with unknown extension: " + file.getPath() );
 119  
                 }
 120  0
                 catch ( final ArchiveExpansionException e )
 121  
                 {
 122  0
                     throw new MojoExecutionException( "Error unpacking dependency file: " + file, e );
 123  0
                 }
 124  
             }
 125  0
         }
 126  0
     }
 127  
 
 128  
 }