Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 255   Methods: 15
NCLOC: 90   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DependScanner.java 100% 83.8% 40% 75.8%
 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.types.optional.depend;
 55   
 
 56   
 import java.io.File;
 57   
 import java.util.Enumeration;
 58   
 import java.util.Hashtable;
 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.Path;
 63   
 import org.apache.tools.ant.util.depend.DependencyAnalyzer;
 64   
 
 65   
 
 66   
 /**
 67   
  * An interface used to describe the actions required by any type of 
 68   
  * directory scanner.
 69   
  *
 70   
  * @author Conor MacNeill
 71   
  * @author <a href="mailto:hengels@innovidata.com">Holger Engels</a>
 72   
  */
 73   
 public class DependScanner extends DirectoryScanner {
 74   
     /**
 75   
      * The name of the analyzer to use by default.
 76   
      */
 77   
     public static final String DEFAULT_ANALYZER_CLASS
 78   
         = "org.apache.tools.ant.util.depend.bcel.FullAnalyzer";
 79   
 
 80   
     /**
 81   
      * The base directory for the scan
 82   
      */
 83   
     private File basedir;
 84   
     
 85   
     /**
 86   
      * The root classes to drive the search for dependent classes
 87   
      */
 88   
     private Vector rootClasses;
 89   
     
 90   
     /**
 91   
      * The names of the classes to include in the fileset
 92   
      */
 93   
     private Vector included;
 94   
 
 95   
     /**
 96   
      * The parent scanner which gives the basic set of files. Only files which 
 97   
      * are in this set and which can be reached from a root class will end
 98   
      * up being included in the result set
 99   
      */
 100   
     private DirectoryScanner parentScanner;
 101   
     
 102   
     /**
 103   
      * Create a DependScanner, using the given scanner to provide the basic 
 104   
      * set of files from which class files come.
 105   
      *
 106   
      * @param parentScanner the DirectoryScanner which returns the files from 
 107   
      *        which class files must come.
 108   
      */
 109  10
     public DependScanner(DirectoryScanner parentScanner) {
 110  10
         this.parentScanner = parentScanner;
 111   
     }
 112   
     
 113   
     /**
 114   
      * Sets the basedir for scanning. This is the directory that is scanned
 115   
      * recursively.
 116   
      *
 117   
      * @param basedir the basedir for scanning
 118   
      */
 119  10
     public void setBasedir(File basedir) {
 120  10
         this.basedir = basedir;
 121   
     }
 122   
 
 123   
     /**
 124   
      * Gets the basedir that is used for scanning.
 125   
      *
 126   
      * @return the basedir that is used for scanning
 127   
      */
 128  0
     public File getBasedir() { return basedir; }
 129   
 
 130   
     /**
 131   
      * Sets the root classes to be used to drive the scan.
 132   
      *
 133   
      * @param rootClasses the rootClasses to be used for this scan
 134   
      */
 135  10
     public void setRootClasses(Vector rootClasses) {
 136  10
         this.rootClasses = rootClasses;
 137   
     }
 138   
 
 139   
     /**
 140   
      * Get the names of the class files, baseClass depends on
 141   
      *
 142   
      * @return the names of the files
 143   
      */
 144  10
     public String[] getIncludedFiles() {
 145  10
         int count = included.size();
 146  10
         String[] files = new String[count];
 147  10
         for (int i = 0; i < count; i++) {
 148  26
             files[i] = (String) included.elementAt(i); 
 149   
         }
 150  10
         return files;
 151   
     }
 152   
 
 153   
     /**
 154   
      * Scans the base directory for files that baseClass depends on
 155   
      *
 156   
      * @exception IllegalStateException when basedir was set incorrecly
 157   
      */
 158  10
     public void scan() throws IllegalStateException {
 159  10
         included = new Vector();
 160  10
         String analyzerClassName = DEFAULT_ANALYZER_CLASS;
 161  10
         DependencyAnalyzer analyzer = null;
 162  10
         try {
 163  10
             Class analyzerClass = Class.forName(analyzerClassName);
 164  10
             analyzer = (DependencyAnalyzer) analyzerClass.newInstance();
 165   
         } catch (Exception e) {
 166  0
             throw new BuildException("Unable to load dependency analyzer: " 
 167   
                 + analyzerClassName, e);
 168   
         }
 169  10
         analyzer.addClassPath(new Path(null, basedir.getPath()));
 170   
         
 171  10
         for (Enumeration e = rootClasses.elements(); e.hasMoreElements();) {
 172  10
             String rootClass = (String) e.nextElement();
 173  10
             analyzer.addRootClass(rootClass);
 174   
         }
 175   
 
 176  10
         Enumeration e = analyzer.getClassDependencies();
 177   
 
 178  10
         String[] parentFiles = parentScanner.getIncludedFiles();
 179  10
         Hashtable parentSet = new Hashtable();
 180  10
         for (int i = 0; i < parentFiles.length; ++i) {
 181  34
             parentSet.put(parentFiles[i], parentFiles[i]);
 182   
         }
 183   
 
 184  10
         while (e.hasMoreElements()) {
 185  56
             String classname = (String) e.nextElement();
 186  56
             String filename = classname.replace('.', File.separatorChar);
 187  56
             filename = filename + ".class";
 188  56
             File depFile = new File(basedir, filename);
 189  56
             if (depFile.exists() && parentSet.containsKey(filename)) {
 190   
                 // This is included
 191  26
                 included.addElement(filename);
 192   
             }
 193   
         }
 194   
     }
 195   
 
 196   
     /**
 197   
      * @see DirectoryScanner#addDefaultExcludes
 198   
      */
 199  0
     public void addDefaultExcludes() {
 200   
     }
 201   
     
 202   
     /**
 203   
      * @see DirectoryScanner#getExcludedDirectories
 204   
      */
 205  0
     public String[] getExcludedDirectories() { 
 206  0
         return null; 
 207   
     }
 208   
     
 209   
     /**
 210   
      * @see DirectoryScanner#getExcludedFiles
 211   
      */
 212  0
     public String[] getExcludedFiles() { 
 213  0
         return null; 
 214   
     }
 215   
     
 216   
     /**
 217   
      * @see DirectoryScanner#getIncludedDirectories
 218   
      */
 219  1
     public String[] getIncludedDirectories() { 
 220  1
         return new String[0]; 
 221   
     }
 222   
     
 223   
     /**
 224   
      * @see DirectoryScanner#getNotIncludedDirectories
 225   
      */
 226  0
     public String[] getNotIncludedDirectories() { 
 227  0
         return null; 
 228   
     }
 229   
     
 230   
     /**
 231   
      * @see DirectoryScanner#getNotIncludedFiles
 232   
      */
 233  0
     public String[] getNotIncludedFiles() { 
 234  0
         return null; 
 235   
     }
 236   
 
 237   
     /**
 238   
      * @see DirectoryScanner#setExcludes
 239   
      */
 240  0
     public void setExcludes(String[] excludes) {
 241   
     }
 242   
     
 243   
     /**
 244   
      * @see DirectoryScanner#setIncludes
 245   
      */
 246  0
     public void setIncludes(String[] includes) {
 247   
     }
 248   
     
 249   
     /**
 250   
      * @see DirectoryScanner#setCaseSensitive
 251   
      */
 252  0
     public void setCaseSensitive(boolean isCaseSensitive) {
 253   
     }
 254   
 }
 255