Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 172   Methods: 7
NCLOC: 91   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Copydir.java 88.9% 86.8% 57.1% 84.1%
 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   
 
 55   
 package org.apache.tools.ant.taskdefs;
 56   
 
 57   
 import java.io.File;
 58   
 import java.io.IOException;
 59   
 import java.util.Enumeration;
 60   
 import java.util.Hashtable;
 61   
 import org.apache.tools.ant.BuildException;
 62   
 import org.apache.tools.ant.DirectoryScanner;
 63   
 import org.apache.tools.ant.Project;
 64   
 
 65   
 /**
 66   
  * Copies a directory.
 67   
  *
 68   
  * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
 69   
  *
 70   
  * @since Ant 1.1
 71   
  *
 72   
  * @deprecated The copydir task is deprecated since Ant 1.2.  Use copy instead.
 73   
  */
 74   
 
 75   
 public class Copydir extends MatchingTask {
 76   
 
 77   
     private File srcDir;
 78   
     private File destDir;
 79   
     private boolean filtering = false;
 80   
     private boolean flatten = false;
 81   
     private boolean forceOverwrite = false;
 82   
     private Hashtable filecopyList = new Hashtable();
 83   
 
 84  6
     public void setSrc(File src) {
 85  6
         srcDir = src;
 86   
     }
 87   
 
 88  6
     public void setDest(File dest) {
 89  6
         destDir = dest;
 90   
     }
 91   
 
 92  0
     public void setFiltering(boolean filter) {
 93  0
         filtering = filter;
 94   
     }
 95   
 
 96  0
     public void setFlatten(boolean flatten) {
 97  0
         this.flatten = flatten;
 98   
     }
 99   
 
 100  0
     public void setForceoverwrite(boolean force) {
 101  0
         forceOverwrite = force;
 102   
     }
 103   
 
 104  8
     public void execute() throws BuildException {
 105  8
         log("DEPRECATED - The copydir task is deprecated.  Use copy instead.");
 106   
 
 107  8
         if (srcDir == null) {
 108  2
             throw new BuildException("src attribute must be set!", 
 109   
                                      getLocation());
 110   
         }
 111   
 
 112  6
         if (!srcDir.exists()) {
 113  0
             throw new BuildException("srcdir " + srcDir.toString()
 114   
                                      + " does not exist!", getLocation());
 115   
         }
 116   
 
 117  6
         if (destDir == null) {
 118  1
             throw new BuildException("The dest attribute must be set.", 
 119   
                                      getLocation());
 120   
         }
 121   
 
 122  5
         if (srcDir.equals(destDir)) {
 123  1
             log("Warning: src == dest", Project.MSG_WARN);
 124   
         }
 125   
 
 126  5
         DirectoryScanner ds = super.getDirectoryScanner(srcDir);
 127   
 
 128  5
         try {
 129  5
             String[] files = ds.getIncludedFiles();
 130  5
             scanDir(srcDir, destDir, files);
 131  5
             if (filecopyList.size() > 0) {
 132  4
                 log("Copying " + filecopyList.size() + " file"
 133   
                     + (filecopyList.size() == 1 ? "" : "s")
 134   
                     + " to " + destDir.getAbsolutePath());
 135  4
                 Enumeration enum = filecopyList.keys();
 136  4
                 while (enum.hasMoreElements()) {
 137  688
                     String fromFile = (String) enum.nextElement();
 138  688
                     String toFile = (String) filecopyList.get(fromFile);
 139  688
                     try {
 140  688
                         getProject().copyFile(fromFile, toFile, filtering,
 141   
                                          forceOverwrite);
 142   
                     } catch (IOException ioe) {
 143  1
                         String msg = "Failed to copy " + fromFile + " to " 
 144   
                             + toFile + " due to " + ioe.getMessage();
 145  1
                         throw new BuildException(msg, ioe, getLocation());
 146   
                     }
 147   
                 }
 148   
             }
 149   
         } finally {
 150  5
             filecopyList.clear();
 151   
         }
 152   
     }
 153   
 
 154  5
     private void scanDir(File from, File to, String[] files) {
 155  5
         for (int i = 0; i < files.length; i++) {
 156  1145
             String filename = files[i];
 157  1145
             File srcFile = new File(from, filename);
 158  1145
             File destFile;
 159  1145
             if (flatten) {
 160  0
                 destFile = new File(to, new File(filename).getName());
 161   
             } else {
 162  1145
                 destFile = new File(to, filename);
 163   
             }
 164  1145
             if (forceOverwrite ||
 165   
                 (srcFile.lastModified() > destFile.lastModified())) {
 166  916
                 filecopyList.put(srcFile.getAbsolutePath(),
 167   
                                  destFile.getAbsolutePath());
 168   
             }
 169   
         }
 170   
     }
 171   
 }
 172