Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 231   Methods: 8
NCLOC: 71   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
VAJImport.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-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.ide;
 55   
 
 56   
 
 57   
 import java.lang.reflect.Field;
 58   
 import java.util.Enumeration;
 59   
 import java.util.Vector;
 60   
 import org.apache.tools.ant.BuildException;
 61   
 import org.apache.tools.ant.DirectoryScanner;
 62   
 import org.apache.tools.ant.types.FileSet;
 63   
 
 64   
 /**
 65   
  * Import source, class files, and resources to the Visual Age for Java
 66   
  * workspace.
 67   
  * <p>
 68   
  * Example:
 69   
  * <pre>
 70   
  * &lt;vajimport project="MyVAProject"&gt;
 71   
  *   &lt;fileset dir="src"&gt;
 72   
  *     &lt;include name="org/foo/subsystem1/**" /&gt;
 73   
  *     &lt;exclude name="/org/foo/subsystem1/test/**" /&gt;
 74   
  *  &lt;/fileset&gt;
 75   
  * &lt;/vajexport&gt;
 76   
  * </pre>
 77   
  * import all source and resource files from the "src" directory
 78   
  * which start with 'org.foo.subsystem1', except of these starting with
 79   
  * 'org.foo.subsystem1.test' into the project MyVAProject.
 80   
  * </p>
 81   
  * <p>If MyVAProject isn't loaded into the Workspace, a new edition is
 82   
  * created in the repository and automatically loaded into the Workspace.
 83   
  * There has to be at least one nested FileSet element.
 84   
  * </p>
 85   
  * <p>There are attributes to choose which items to export:
 86   
  * <table border="1" cellpadding="2" cellspacing="0">
 87   
  * <tr>
 88   
  *   <td valign="top"><b>Attribute</b></td>
 89   
  *   <td valign="top"><b>Description</b></td>
 90   
  *   <td align="center" valign="top"><b>Required</b></td>
 91   
  * </tr>
 92   
  * <tr>
 93   
  *   <td valign="top">project</td>
 94   
  *   <td valign="top">the name of the Project to import to</td>
 95   
  *   <td align="center" valign="top">Yes</td>
 96   
  * </tr>
 97   
  * <tr>
 98   
  *   <td valign="top">importSources</td>
 99   
  *   <td valign="top">import Java sources, defaults to "yes"</td>
 100   
  *   <td align="center" valign="top">No</td>
 101   
  * </tr>
 102   
  * <tr>
 103   
  *   <td valign="top">importResources</td>
 104   
  *   <td valign="top">import resource files (anything that doesn't
 105   
  *                    end with .java or .class), defaults to "yes"</td>
 106   
  *   <td align="center" valign="top">No</td>
 107   
  * </tr>
 108   
  * <tr>
 109   
  *   <td valign="top">importClasses</td>
 110   
  *   <td valign="top">import class files, defaults to "no"</td>
 111   
  *   <td align="center" valign="top">No</td>
 112   
  * </tr>
 113   
  * </table>
 114   
  *
 115   
  * @author Glenn McAllister, inspired by a similar task written by Peter Kelley
 116   
  */
 117   
 public class VAJImport extends VAJTask {
 118   
     protected Vector filesets = new Vector();
 119   
     protected boolean importSources = true;
 120   
     protected boolean importResources = true;
 121   
     protected boolean importClasses = false;
 122   
     protected String importProject = null;
 123   
     protected boolean useDefaultExcludes = true;
 124   
 
 125   
 
 126   
     /**
 127   
      * The VisualAge for Java Project name to import into.
 128   
      */
 129  0
     public void setProject(String projectName) {
 130  0
         this.importProject = projectName;
 131   
     }
 132   
 
 133   
     /**
 134   
      * Adds a set of files (nested fileset attribute).
 135   
      */
 136  0
     public void addFileset(FileSet set) {
 137  0
         filesets.addElement(set);
 138   
     }
 139   
 
 140   
     /**
 141   
      * Flag to import .class files; optional, default false.
 142   
      */
 143  0
     public void setImportClasses(boolean importClasses) {
 144  0
         this.importClasses = importClasses;
 145   
     }
 146   
 
 147   
     /**
 148   
      * Import resource files (anything that doesn't end in
 149   
      * .class or .java); optional, default true.
 150   
      */
 151  0
     public void setImportResources(boolean importResources) {
 152  0
         this.importResources = importResources;
 153   
     }
 154   
 
 155   
     /**
 156   
      * Import .java files; optional, default true.
 157   
      */
 158  0
     public void setImportSources(boolean importSources) {
 159  0
         this.importSources = importSources;
 160   
     }
 161   
 
 162   
     /**
 163   
      * Sets whether default exclusions should be used or not.
 164   
      *
 165   
      * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
 166   
      *                           should be used, "false"|"off"|"no" when they
 167   
      *                           shouldn't be used.
 168   
      */
 169  0
     public void setDefaultexcludes(boolean useDefaultExcludes) {
 170  0
         this.useDefaultExcludes = useDefaultExcludes;
 171   
     }
 172   
 
 173   
     /**
 174   
      * Do the import.
 175   
      */
 176  0
     public void execute() throws BuildException {
 177  0
         if (filesets.size() == 0) {
 178  0
             throw new BuildException("At least one fileset is required!");
 179   
         }
 180   
 
 181  0
         if (importProject == null || "".equals(importProject)) {
 182  0
             throw new BuildException("The VisualAge for Java Project name is required!");
 183   
         }
 184   
 
 185  0
         for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
 186  0
             importFileset((FileSet) e.nextElement());
 187   
         }
 188   
     }
 189   
 
 190   
     /**
 191   
      * Import all files from the fileset into the Project in the
 192   
      * Workspace.
 193   
      */
 194  0
     protected void importFileset(FileSet fileset) {
 195  0
         DirectoryScanner ds = fileset.getDirectoryScanner(this.getProject());
 196  0
         if (ds.getIncludedFiles().length == 0) {
 197  0
             return;
 198   
         }
 199   
 
 200  0
         String[] includes = null;
 201  0
         String[] excludes = null;
 202   
 
 203   
         // Hack to get includes and excludes. We could also use getIncludedFiles,
 204   
         // but that would result in very long HTTP-requests.
 205   
         // Therefore we want to send the patterns only to the remote tool server
 206   
         // and let him figure out the files.
 207  0
         try {
 208  0
             Class directoryScanner = ds.getClass();
 209   
 
 210  0
             Field includesField = directoryScanner.getDeclaredField("includes");
 211  0
             includesField.setAccessible(true);
 212  0
             includes = (String[]) includesField.get(ds);
 213   
 
 214  0
             Field excludesField = directoryScanner.getDeclaredField("excludes");
 215  0
             excludesField.setAccessible(true);
 216  0
             excludes = (String[]) excludesField.get(ds);
 217   
         } catch (NoSuchFieldException nsfe) {
 218  0
             throw new BuildException(
 219   
                 "DirectoryScanner.includes or .excludes missing" + nsfe.getMessage());
 220   
         } catch (IllegalAccessException iae) {
 221  0
             throw new BuildException(
 222   
                 "Access to DirectoryScanner.includes or .excludes not allowed");
 223   
         }
 224   
 
 225  0
         getUtil().importFiles(importProject, ds.getBasedir(),
 226   
                 includes, excludes,
 227   
                 importClasses, importResources, importSources,
 228   
                 useDefaultExcludes);
 229   
     }
 230   
 }
 231