Coverage Report - org.geotoolkit.maven.jar.PackerMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
PackerMojo
0 %
0/26
0 %
0/6
12
 
 1  
 /*
 2  
  *    Geotoolkit - An Open Source Java GIS Tookit
 3  
  *    http://www.geotoolkit.org
 4  
  *
 5  
  *    (C) 2005-2012, Open Source Geospatial Foundation (OSGeo)
 6  
  *    (C) 2009-2012, Geomatys
 7  
  *
 8  
  *    This library is free software; you can redistribute it and/or
 9  
  *    modify it under the terms of the GNU Lesser General Public
 10  
  *    License as published by the Free Software Foundation;
 11  
  *    version 2.1 of the License.
 12  
  *
 13  
  *    This library is distributed in the hope that it will be useful,
 14  
  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  
  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16  
  *    Lesser General Public License for more details.
 17  
  */
 18  
 package org.geotoolkit.maven.jar;
 19  
 
 20  
 import java.io.File;
 21  
 import java.io.IOException;
 22  
 
 23  
 import org.apache.maven.plugin.AbstractMojo;
 24  
 import org.apache.maven.plugin.MojoExecutionException;
 25  
 import org.apache.maven.project.MavenProject;
 26  
 
 27  
 
 28  
 /**
 29  
  * Merges the binaries produced by <code>JarCollector</code> and compress them using Pack200.
 30  
  * This mojo delegates the work to <code>Packer</code>, which can be invoked from the command
 31  
  * line without Maven. Maven invocation syntax is:
 32  
  *
 33  
  * <blockquote><code>mvn org.geotoolkit.project:geotk-jar-collector:pack --non-recursive</code></blockquote>
 34  
  *
 35  
  * Do not forget the <code>--non-recursive</code> option, otherwise the Mojo will be executed
 36  
  * many time.
 37  
  *
 38  
  * @author Martin Desruisseaux (Geomatys)
 39  
  * @version 3.19
 40  
  *
 41  
  * @since 3.00
 42  
  *
 43  
  * @goal pack
 44  
  * @phase install
 45  
  */
 46  0
 public class PackerMojo extends AbstractMojo {
 47  
     /**
 48  
      * The Maven project running this plugin.
 49  
      *
 50  
      * @parameter expression="${project}"
 51  
      * @required
 52  
      */
 53  
     private MavenProject project;
 54  
 
 55  
     /**
 56  
      * Copies the {@code .jar} files to the collect directory.
 57  
      *
 58  
      * @throws MojoExecutionException if the plugin execution failed.
 59  
      */
 60  
     @Override
 61  
     public void execute() throws MojoExecutionException {
 62  
         /*
 63  
          * Gets the parent "target" directory where JARs are copied.
 64  
          * It should be the "target" directory of the parent pom.xml.
 65  
          */
 66  0
         MavenProject parent = project;
 67  0
         while (parent.hasParent()) {
 68  0
             parent = parent.getParent();
 69  
         }
 70  0
         final String targetDirectory = parent.getBuild().getDirectory();
 71  
         /*
 72  
          * Now packs the JARs.
 73  
          */
 74  0
         final String[] arguments = new String[] {
 75  
             targetDirectory
 76  
         };
 77  
         try {
 78  0
             Packer.main(arguments);
 79  0
         } catch (IllegalArgumentException e) {
 80  0
             throw new MojoExecutionException(e.toString());
 81  0
         } catch (IOException e) {
 82  0
             throw new MojoExecutionException("Error packing the JAR file.", e);
 83  0
         }
 84  
         /*
 85  
          * Packs javadoc.
 86  
          */
 87  0
         final PackFiles pack = new PackFiles(new File(targetDirectory, Packer.PACK_DIRECTORY));
 88  0
         File directory = new File(targetDirectory, "site/apidocs");
 89  0
         if (directory.isDirectory()) try {
 90  0
             pack.pack(directory, "geotk-pending-" + PackerSpecificMojo.VERSION + "-javadoc.zip");
 91  0
         } catch (IOException e) {
 92  0
             throw new MojoExecutionException("Error packing the ZIP file for javadoc.", e);
 93  0
         }
 94  
         /*
 95  
          * Packs source code.
 96  
          */
 97  0
         directory = parent.getBasedir();
 98  0
         if (directory.isDirectory()) try {
 99  0
             pack.pack(directory, "geotk-pending-" + PackerSpecificMojo.VERSION + "-sources.zip");
 100  0
         } catch (IOException e) {
 101  0
             throw new MojoExecutionException("Error packing the ZIP file for source code.", e);
 102  0
         }
 103  0
     }
 104  
 }