Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 217   Methods: 9
NCLOC: 80   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DotnetBaseMatchingTask.java 0% 0% 0% 0%
 1   
 /*
 2   
  *  The Apache Software License, Version 1.1
 3   
  *
 4   
  *  Copyright (c) 2003 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 "The Jakarta Project", "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   
 
 55   
 
 56   
 package org.apache.tools.ant.taskdefs.optional.dotnet;
 57   
 
 58   
 import org.apache.tools.ant.taskdefs.MatchingTask;
 59   
 import org.apache.tools.ant.types.FileSet;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.ant.DirectoryScanner;
 62   
 
 63   
 import java.io.File;
 64   
 import java.util.Vector;
 65   
 import java.util.Hashtable;
 66   
 import java.util.Enumeration;
 67   
 
 68   
 /**
 69   
  * refactoring of some stuff so that different things (like ILASM)
 70   
  * can use shared code.
 71   
  * @author steve loughran
 72   
  */
 73   
 public class DotnetBaseMatchingTask extends MatchingTask {
 74   
     /**
 75   
      *  output file. If not supplied this is derived from the source file
 76   
      */
 77   
     protected File outputFile;
 78   
     /**
 79   
      * filesets of file to compile
 80   
      */
 81   
     protected Vector filesets = new Vector();
 82   
 
 83   
     /**
 84   
      *  source directory upon which the search pattern is applied
 85   
      */
 86   
     protected File srcDir;
 87   
 
 88   
     /**
 89   
     * Overridden because we need to be able to set the srcDir.
 90   
     */
 91  0
     public File getSrcDir() {
 92  0
         return this.srcDir;
 93   
     }
 94   
 
 95   
     /**
 96   
      *  Set the source directory of the files to be compiled.
 97   
      *
 98   
      *@param  srcDirName  The new SrcDir value
 99   
      */
 100  0
     public void setSrcDir(File srcDirName) {
 101  0
         this.srcDir = srcDirName;
 102   
     }
 103   
 
 104   
     /**
 105   
      *  Set the name of exe/library to create.
 106   
      *
 107   
      *@param  file  The new outputFile value
 108   
      */
 109  0
     public void setDestFile(File file) {
 110  0
         outputFile = file;
 111   
     }
 112   
 
 113   
     /**
 114   
      * add a new source directory to the compile
 115   
      * @param src
 116   
      */
 117  0
     public void addSrc(FileSet src) {
 118  0
         filesets.add(src);
 119   
     }
 120   
 
 121   
     /**
 122   
      * get the destination file
 123   
      * @return the dest file or null for not assigned
 124   
      */
 125  0
     public File getDestFile() {
 126  0
         return outputFile;
 127   
     }
 128   
 
 129   
     /**
 130   
      * create the list of files
 131   
      * @param filesToBuild vector to add files to
 132   
      * @param outputTimestamp timestamp to compare against
 133   
      * @return number of files out of date
 134   
      */
 135  0
     protected int buildFileList(NetCommand command, Hashtable filesToBuild, long outputTimestamp) {
 136  0
         int filesOutOfDate=0;
 137  0
         boolean scanImplicitFileset=getSrcDir()!=null || filesets.size()==0;
 138  0
         if(scanImplicitFileset) {
 139   
             //scan for an implicit fileset if there was a srcdir set
 140   
             //or there was no srcDir set but the @
 141  0
             if (getSrcDir() == null) {
 142   
                 //if there is no src dir here, set it
 143  0
                 setSrcDir(getProject().resolveFile("."));
 144   
             }
 145  0
             log("working from source directory " + getSrcDir(),
 146   
                     Project.MSG_VERBOSE);
 147   
             //get dependencies list.
 148  0
             DirectoryScanner scanner = getDirectoryScanner(getSrcDir());
 149  0
             filesOutOfDate = command.scanOneFileset(scanner,
 150   
                     filesToBuild, outputTimestamp);
 151   
         }
 152   
         //get any included source directories
 153  0
         for (int i = 0; i < filesets.size(); i++) {
 154  0
             FileSet fs = (FileSet) filesets.elementAt(i);
 155  0
             filesOutOfDate+= command.scanOneFileset(
 156   
                     fs.getDirectoryScanner(getProject()),
 157   
                     filesToBuild,
 158   
                     outputTimestamp);
 159   
         }
 160   
 
 161  0
         return filesOutOfDate;
 162   
     }
 163   
 
 164   
     /**
 165   
      * add the list of files to a command
 166   
      * @param filesToBuild vector of files
 167   
      * @param command the command to append to
 168   
      */
 169  0
     protected void addFilesToCommand(Hashtable filesToBuild, NetCommand command) {
 170  0
         int count=filesToBuild.size();
 171  0
         log("compiling " + count + " file" + ((count== 1) ? "" : "s"));
 172  0
         Enumeration files=filesToBuild.elements();
 173  0
         while (files.hasMoreElements()) {
 174  0
             File file = (File) files.nextElement();
 175  0
             command.addArgument(file.toString());
 176   
         }
 177   
     }
 178   
 
 179   
     /**
 180   
      * determine the timestamp of the output file
 181   
      * @return a timestamp or 0 for no output file known/exists
 182   
      */
 183  0
     protected long getOutputFileTimestamp() {
 184  0
         long outputTimestamp;
 185  0
         if (getDestFile() != null && getDestFile().exists()) {
 186  0
             outputTimestamp = getDestFile().lastModified();
 187   
         } else {
 188  0
             outputTimestamp = 0;
 189   
         }
 190  0
         return outputTimestamp;
 191   
     }
 192   
 
 193   
     /**
 194   
      * finish off the command by adding all dependent files, execute
 195   
      * @param command
 196   
      */
 197  0
     protected void addFilesAndExecute(NetCommand command, boolean ignoreTimestamps) {
 198  0
         long outputTimestamp = getOutputFileTimestamp();
 199  0
         Hashtable filesToBuild =new Hashtable();
 200  0
         int filesOutOfDate = buildFileList(command,filesToBuild, outputTimestamp);
 201   
 
 202   
         //add the files to the command
 203  0
         addFilesToCommand(filesToBuild, command);
 204   
 
 205   
 
 206   
         //now run the command of exe + settings + files
 207  0
         if (filesOutOfDate > 0) {
 208  0
             command.runCommand();
 209   
         } else {
 210  0
             log("output file is up to date",Project.MSG_VERBOSE);
 211   
         }
 212   
     }
 213   
 
 214   
 
 215   
 
 216   
 }
 217