Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 213   Methods: 10
NCLOC: 87   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JlinkTask.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000,2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.jlink;
 55   
 
 56   
 import java.io.File;
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.Project;
 59   
 import org.apache.tools.ant.taskdefs.MatchingTask;
 60   
 import org.apache.tools.ant.types.Path;
 61   
 
 62   
 /**
 63   
  * This class defines objects that can link together various jar and
 64   
  * zip files. 
 65   
  *
 66   
  * <p>It is basically a wrapper for the jlink code written originally
 67   
  * by <a href="mailto:beard@netscape.com">Patrick Beard</a>.  The
 68   
  * classes org.apache.tools.ant.taskdefs.optional.jlink.Jlink and
 69   
  * org.apache.tools.ant.taskdefs.optional.jlink.ClassNameReader
 70   
  * support this class.</p>
 71   
  *
 72   
  * <p>For example:
 73   
  * <code>
 74   
  * <pre>
 75   
  * &lt;jlink compress=&quot;false&quot; outfile=&quot;out.jar&quot;/&gt;
 76   
  *   &lt;mergefiles&gt;
 77   
  *     &lt;pathelement path=&quot;${build.dir}/mergefoo.jar&quot;/&gt;
 78   
  *     &lt;pathelement path=&quot;${build.dir}/mergebar.jar&quot;/&gt;
 79   
  *   &lt;/mergefiles&gt;
 80   
  *   &lt;addfiles&gt;
 81   
  *     &lt;pathelement path=&quot;${build.dir}/mac.jar&quot;/&gt;
 82   
  *     &lt;pathelement path=&quot;${build.dir}/pc.zip&quot;/&gt;
 83   
  *   &lt;/addfiles&gt;
 84   
  * &lt;/jlink&gt;
 85   
  * </pre>
 86   
  * </code>
 87   
  *
 88   
  * @author <a href="mailto:matthew.k.heun@gaerospace.com">Matthew Kuperus Heun</a>
 89   
  * @ant.task ignore="true"
 90   
  */
 91   
 public class JlinkTask extends MatchingTask {
 92   
 
 93   
     /**
 94   
      * The output file for this run of jlink. Usually a jar or zip file.
 95   
      */
 96  0
     public  void setOutfile(File outfile) {
 97  0
         this.outfile = outfile;
 98   
     }
 99   
 
 100   
     /**
 101   
      * Establishes the object that contains the files to
 102   
      * be merged into the output.
 103   
      */
 104  0
     public  Path createMergefiles() {
 105  0
         if (this.mergefiles == null) {
 106  0
             this.mergefiles = new Path(getProject());
 107   
         }
 108  0
         return this.mergefiles.createPath();
 109   
     }
 110   
 
 111   
     /**
 112   
      * Sets the files to be merged into the output.
 113   
      */
 114  0
     public  void setMergefiles(Path mergefiles) {
 115  0
         if (this.mergefiles == null) {
 116  0
             this.mergefiles = mergefiles;
 117   
         } else {
 118  0
             this.mergefiles.append(mergefiles);
 119   
         }
 120   
     }
 121   
 
 122   
     /**
 123   
      * Establishes the object that contains the files to
 124   
      * be added to the output.
 125   
      */
 126  0
     public  Path createAddfiles() {
 127  0
         if (this.addfiles == null) {
 128  0
             this.addfiles = new Path(getProject());
 129   
         }
 130  0
         return this.addfiles.createPath();
 131   
     }
 132   
 
 133   
     /**
 134   
      * Sets the files to be added into the output.
 135   
      */
 136  0
     public  void setAddfiles(Path addfiles) {
 137  0
         if (this.addfiles == null) {
 138  0
             this.addfiles = addfiles;
 139   
         } else {
 140  0
             this.addfiles.append(addfiles);
 141   
         }
 142   
     }
 143   
 
 144   
     /**
 145   
      * Defines whether or not the output should be compacted.
 146   
      */
 147  0
     public  void setCompress(boolean compress) {
 148  0
         this.compress = compress;
 149   
     }
 150   
 
 151   
     /**
 152   
      * Does the adding and merging.
 153   
      */
 154  0
     public  void execute() throws BuildException {
 155   
         //Be sure everything has been set.
 156  0
         if (outfile == null) {
 157  0
             throw new BuildException("outfile attribute is required! " 
 158   
                 + "Please set.");
 159   
         }
 160  0
         if (!haveAddFiles() && !haveMergeFiles()) {
 161  0
             throw new BuildException("addfiles or mergefiles required! " 
 162   
                 + "Please set.");
 163   
         }
 164  0
         log("linking:     " + outfile.getPath());
 165  0
         log("compression: " + compress, Project.MSG_VERBOSE);
 166  0
         jlink linker = new jlink();
 167  0
         linker.setOutfile(outfile.getPath());
 168  0
         linker.setCompression(compress);
 169  0
         if (haveMergeFiles()) {
 170  0
             log("merge files: " + mergefiles.toString(), Project.MSG_VERBOSE);
 171  0
             linker.addMergeFiles(mergefiles.list());
 172   
         }
 173  0
         if (haveAddFiles()) {
 174  0
             log("add files: " + addfiles.toString(), Project.MSG_VERBOSE);
 175  0
             linker.addAddFiles(addfiles.list());
 176   
         }
 177  0
         try  {
 178  0
             linker.link();
 179   
         } catch (Exception ex) {
 180  0
             throw new BuildException(ex, getLocation());
 181   
         }
 182   
     }
 183   
 
 184  0
     private boolean haveAddFiles(){
 185  0
         return haveEntries(addfiles);
 186   
     }
 187   
 
 188  0
     private boolean haveMergeFiles(){
 189  0
         return haveEntries(mergefiles);
 190   
     }
 191   
 
 192  0
     private boolean haveEntries(Path p){
 193  0
         if (p == null){
 194  0
             return false;
 195   
         }
 196  0
         if (p.size() > 0){
 197  0
             return true;
 198   
         }
 199  0
         return false;
 200   
     }
 201   
 
 202   
     private  File outfile = null;
 203   
 
 204   
     private  Path mergefiles = null;
 205   
 
 206   
     private  Path addfiles = null;
 207   
 
 208   
     private  boolean compress = false;
 209   
 
 210   
 }
 211   
 
 212   
 
 213