Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 207   Methods: 9
NCLOC: 68   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
ClassfileSet.java 20% 35.7% 33.3% 31.9%
 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.util.Enumeration;
 57   
 import java.util.Vector;
 58   
 import org.apache.tools.ant.DirectoryScanner;
 59   
 import org.apache.tools.ant.Project;
 60   
 import org.apache.tools.ant.types.FileSet;
 61   
 
 62   
 /**
 63   
  * A ClassfileSet is a FileSet, that enlists all classes that depend on a
 64   
  * certain set of root classes.
 65   
  *
 66   
  * A ClassfileSet extends FileSets. The
 67   
  * nested FileSet attribute provides the domain, that is used for searching
 68   
  * for dependent classes
 69   
  *
 70   
  * @author <a href="mailto:hengels@innovidata.com">Holger Engels</a>
 71   
  */
 72   
 public class ClassfileSet extends FileSet {
 73   
     /** 
 74   
      * The list of root classes for this class file set. These are the 
 75   
      * classes which must be included in the fileset and which are the 
 76   
      * starting point for the dependency search.
 77   
      */
 78   
     private Vector rootClasses = new Vector();
 79   
 
 80   
     /**
 81   
      * The list of filesets which contain root classes
 82   
      */
 83   
     private Vector rootFileSets = new Vector();
 84   
     
 85   
     /**
 86   
      * Inner class used to contain info about root classes
 87   
      */
 88   
     public static class ClassRoot {
 89   
         /** The name of the root class */
 90   
         private String rootClass;
 91   
         
 92   
         /** 
 93   
          * Set the root class name 
 94   
          *
 95   
          * @param name the name of the root class 
 96   
          */
 97  0
         public void setClassname(String name) {
 98  0
             this.rootClass = name;
 99   
         }
 100   
         
 101   
         /**
 102   
          * Get the name of the root class
 103   
          *
 104   
          * @return the name of the root class.
 105   
          */
 106  0
         public String getClassname() {
 107  0
             return rootClass;
 108   
         }
 109   
     }
 110   
 
 111   
     /**
 112   
      * Default constructor
 113   
      */
 114  5
     public ClassfileSet() {
 115   
     }
 116   
     
 117   
     /**
 118   
      * Add a fileset to which contains a collection of root classes used to 
 119   
      * drive the search from classes 
 120   
      *
 121   
      * @param rootFileSet a root file set to be used to search for dependent
 122   
      * classes
 123   
      */
 124  0
     public void addRootFileset(FileSet rootFileSet) {
 125  0
         rootFileSets.addElement(rootFileSet);
 126   
     }
 127   
     
 128   
     /**
 129   
      * Create a ClassfileSet from another ClassfileSet
 130   
      *
 131   
      * @param s the other classfileset
 132   
      */
 133  0
     protected ClassfileSet(ClassfileSet s) {
 134  0
         super(s);
 135  0
         rootClasses = (Vector) s.rootClasses.clone();
 136   
     }
 137   
 
 138   
     /**
 139   
      * Set the root class attribute
 140   
      *
 141   
      * @param rootClass the name of the root class.
 142   
      */
 143  5
     public void setRootClass(String rootClass) {
 144  5
         rootClasses.addElement(rootClass);
 145   
     }
 146   
 
 147   
     /**
 148   
      * Return the DirectoryScanner associated with this FileSet.
 149   
      *
 150   
      * @param p the project used to resolve dirs, etc.
 151   
      *
 152   
      * @return a dependency scanner.
 153   
      */
 154  10
     public DirectoryScanner getDirectoryScanner(Project p) {
 155  10
         if (isReference()) {
 156  0
             return getRef(p).getDirectoryScanner(p);
 157   
         }
 158   
 
 159  10
         Vector allRootClasses = (Vector) rootClasses.clone();
 160  10
         for (Enumeration e = rootFileSets.elements(); e.hasMoreElements();) {
 161  0
             FileSet additionalRootSet = (FileSet) e.nextElement();
 162  0
             DirectoryScanner additionalScanner
 163   
                 = additionalRootSet.getDirectoryScanner(p);
 164  0
             String[] files = additionalScanner.getIncludedFiles();
 165  0
             for (int i = 0; i < files.length; ++i) {
 166  0
                 if (files[i].endsWith(".class")) {
 167  0
                     String classFilePath 
 168   
                         = files[i].substring(0, files[i].length() - 6);
 169  0
                     String className 
 170   
                         = classFilePath.replace('/', '.').replace('\\', '.');
 171  0
                     allRootClasses.addElement(className);
 172   
                 }
 173   
             }
 174   
         }    
 175   
                 
 176   
         
 177  10
         DirectoryScanner parentScanner = super.getDirectoryScanner(p);
 178  10
         DependScanner scanner = new DependScanner(parentScanner);
 179  10
         scanner.setBasedir(getDir(p));
 180  10
         scanner.setRootClasses(allRootClasses);
 181  10
         scanner.scan();
 182  10
         return scanner;
 183   
     } 
 184   
     
 185   
     /** 
 186   
      * Add a nested root class definition to this class file set
 187   
      *
 188   
      * @param root the configured class root.
 189   
      */
 190  0
     public void addConfiguredRoot(ClassRoot root) {
 191  0
         rootClasses.addElement(root.getClassname());    
 192   
     }
 193   
 
 194   
     /**
 195   
      * Clone this data type.
 196   
      *
 197   
      * @return a clone of the class file set
 198   
      */
 199  0
     public Object clone() {
 200  0
         if (isReference()) {
 201  0
             return new ClassfileSet((ClassfileSet) getRef(getProject()));
 202   
         } else {
 203  0
             return new ClassfileSet(this);
 204   
         }
 205   
     }
 206   
 }
 207