Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 165   Methods: 1
NCLOC: 72   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ResourceUtils.java 83.3% 90% 100% 87.8%
 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 "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.util;
 55   
 
 56   
 import org.apache.tools.ant.Project;
 57   
 import org.apache.tools.ant.ProjectComponent;
 58   
 import org.apache.tools.ant.taskdefs.condition.Os;
 59   
 import org.apache.tools.ant.types.Resource;
 60   
 import org.apache.tools.ant.types.ResourceFactory;
 61   
 
 62   
 import java.io.File;
 63   
 import java.util.Vector;
 64   
 
 65   
 /**
 66   
  * this class provides utility methods to process resources
 67   
  *
 68   
  * @author <a href="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</a>
 69   
  * @since Ant 1.5.2
 70   
  */
 71   
 public class ResourceUtils {
 72   
 
 73   
     /**                                                                      {
 74   
      * tells which source files should be reprocessed based on the
 75   
      * last modification date of target files
 76   
      * @param logTo where to send (more or less) interesting output
 77   
      * @param source array of resources bearing relative path and last
 78   
      * modification date
 79   
      * @param mapper filename mapper indicating how to find the target
 80   
      * files
 81   
      * @param targets object able to map as a resource a relative path
 82   
      * at <b>destination</b>
 83   
      * @return array containing the source files which need to be
 84   
      * copied or processed, because the targets are out of date or do
 85   
      * not exist
 86   
      */
 87  96
     public static Resource[] selectOutOfDateSources(ProjectComponent logTo,
 88   
                                                     Resource[] source,
 89   
                                                     FileNameMapper mapper,
 90   
                                                     ResourceFactory targets) {
 91  96
         long now = (new java.util.Date()).getTime();
 92   
 
 93   
         /*
 94   
           If we're on Windows, we have to munge the time up to 2 secs to
 95   
           be able to check file modification times.
 96   
           (Windows has a max resolution of two secs for modification times)
 97   
           Actually this is a feature of the FAT file system, NTFS does
 98   
           not have it, so if we could reliably passively test for an NTFS
 99   
           file systems we could turn this off...
 100   
         */
 101  96
         if (Os.isFamily("windows")) {
 102  0
             now += 2000;
 103   
         }
 104   
 
 105  96
         Vector vresult = new Vector();
 106  96
         for (int counter = 0; counter < source.length; counter++) {
 107  1498
             if (source[counter].getLastModified() > now) {
 108  0
                 logTo.log("Warning: " + source[counter].getName() 
 109   
                          + " modified in the future.", 
 110   
                          Project.MSG_WARN);
 111   
             }
 112   
 
 113  1498
             String[] targetnames = 
 114   
                 mapper.mapFileName(source[counter].getName()
 115   
                                    .replace('/', File.separatorChar));
 116  1498
             if (targetnames != null) {
 117  1465
                 boolean added = false;
 118  1465
                 StringBuffer targetList = new StringBuffer();
 119  1465
                 for (int ctarget = 0; !added && ctarget < targetnames.length; 
 120   
                      ctarget++) {
 121  1465
                     Resource atarget = 
 122   
                         targets.getResource(targetnames[ctarget]
 123   
                                             .replace(File.separatorChar, '/'));
 124   
                     // if the target does not exist, or exists and
 125   
                     // is older than the source, then we want to
 126   
                     // add the resource to what needs to be copied
 127  1465
                     if (!atarget.isExists()) {
 128  404
                         logTo.log(source[counter].getName() + " added as " 
 129   
                                   + atarget.getName()
 130   
                                   + " doesn\'t exist.", Project.MSG_VERBOSE);
 131  404
                         vresult.addElement(source[counter]);
 132  404
                         added = true;
 133  1061
                     } else if (atarget.getLastModified() 
 134   
                                < source[counter].getLastModified()) {
 135  5
                         logTo.log(source[counter].getName() + " added as " 
 136   
                                   + atarget.getName()
 137   
                                   + " is outdated.", Project.MSG_VERBOSE);
 138  5
                         vresult.addElement(source[counter]);
 139  5
                         added = true;
 140   
                     } else {
 141  1056
                         if (targetList.length() > 0) {
 142  0
                             targetList.append(", ");
 143   
                         }
 144  1056
                         targetList.append(atarget.getName());
 145   
                     }
 146   
                 }
 147   
 
 148  1465
                 if (!added) {
 149  1056
                     logTo.log(source[counter].getName() 
 150   
                               + " omitted as " + targetList.toString()
 151   
                               + (targetnames.length == 1 ? " is" : " are ")
 152   
                               + " up to date.", Project.MSG_VERBOSE);
 153   
                 }
 154   
             } else {
 155  33
                 logTo.log(source[counter].getName() 
 156   
                           + " skipped - don\'t know how to handle it",
 157   
                           Project.MSG_VERBOSE);
 158   
             }
 159   
         }
 160  96
         Resource[] result= new Resource[vresult.size()];
 161  96
         vresult.copyInto(result);
 162  96
         return result;
 163   
     }
 164   
 }
 165