Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 173   Methods: 6
NCLOC: 61   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MappingSelector.java 78.6% 84% 83.3% 82.2%
 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   
 
 55   
 package org.apache.tools.ant.types.selectors;
 56   
 
 57   
 import org.apache.tools.ant.types.Mapper;
 58   
 import org.apache.tools.ant.BuildException;
 59   
 import org.apache.tools.ant.taskdefs.condition.Os;
 60   
 import org.apache.tools.ant.util.IdentityMapper;
 61   
 import org.apache.tools.ant.util.FileNameMapper;
 62   
 
 63   
 import java.io.File;
 64   
 
 65   
 /**
 66   
  * A mapping selector is an abstract class adding mapping support to the base
 67   
  * selector
 68   
  */
 69   
 public abstract class MappingSelector extends BaseSelector {
 70   
     protected File targetdir = null;
 71   
     protected Mapper mapperElement = null;
 72   
     protected FileNameMapper map = null;
 73   
     protected int granularity = 0;
 74   
 
 75  11
     public MappingSelector() {
 76  11
         if (Os.isFamily("dos")) {
 77  0
             granularity = 2000;
 78   
         }
 79   
     }
 80   
 
 81   
 
 82   
     /**
 83   
      * The name of the file or directory which is checked for out-of-date
 84   
      * files.
 85   
      *
 86   
      * @param targetdir the directory to scan looking for files.
 87   
      */
 88  8
     public void setTargetdir(File targetdir) {
 89  8
         this.targetdir = targetdir;
 90   
     }
 91   
 
 92   
     /**
 93   
      * Defines the FileNameMapper to use (nested mapper element).
 94   
      */
 95  8
     public Mapper createMapper() throws BuildException {
 96  8
         if (mapperElement != null) {
 97  1
             throw new BuildException("Cannot define more than one mapper");
 98   
         }
 99  7
         mapperElement = new Mapper(getProject());
 100  7
         return mapperElement;
 101   
     }
 102   
 
 103   
     /**
 104   
      * Checks to make sure all settings are kosher. In this case, it
 105   
      * means that the dest attribute has been set and we have a mapper.
 106   
      */
 107  109
     public void verifySettings() {
 108  109
         if (targetdir == null) {
 109  1
             setError("The targetdir attribute is required.");
 110   
         }
 111  109
         if (mapperElement == null) {
 112  25
             map = new IdentityMapper();
 113   
         }
 114   
         else {
 115  84
             map = mapperElement.getImplementation();
 116   
         }
 117  109
         if (map == null) {
 118  0
             setError("Could not set <mapper> element.");
 119   
         }
 120   
     }
 121   
 
 122   
     /**
 123   
      * The heart of the matter. This is where the selector gets to decide
 124   
      * on the inclusion of a file in a particular fileset.
 125   
      *
 126   
      * @param basedir the base directory the scan is being done from
 127   
      * @param filename is the name of the file to check
 128   
      * @param file is a java.io.File object the selector can use
 129   
      * @return whether the file should be selected or not
 130   
      */
 131  110
     public boolean isSelected(File basedir, String filename, File file) {
 132   
 
 133   
         // throw BuildException on error
 134  110
         validate();
 135   
 
 136   
         // Determine file whose out-of-dateness is to be checked
 137  108
         String[] destfiles = map.mapFileName(filename);
 138   
         // If filename does not match the To attribute of the mapper
 139   
         // then filter it out of the files we are considering
 140  108
         if (destfiles == null) {
 141  36
             return false;
 142   
         }
 143   
         // Sanity check
 144  72
         if (destfiles.length != 1 || destfiles[0] == null) {
 145  0
             throw new BuildException("Invalid destination file results for "
 146   
                 + targetdir.getName() + " with filename " + filename);
 147   
         }
 148  72
         String destname = destfiles[0];
 149  72
         File destfile = new File(targetdir,destname);
 150   
 
 151  72
         boolean selected = selectionTest(file, destfile);
 152  72
         return selected;
 153   
     }
 154   
 
 155   
     /**
 156   
      * this test is our selection test that compared the file with the destfile
 157   
      * @param srcfile file to test; may be null
 158   
      * @param destfile destination file
 159   
      * @return
 160   
      */
 161   
     protected abstract boolean selectionTest(File srcfile, File destfile);
 162   
 
 163   
     /**
 164   
      * Sets the number of milliseconds leeway we will give before we consider
 165   
      * a file out of date. Defaults to 2000 on MS-DOS derivatives as the FAT file
 166   
      * system.
 167   
      */
 168  0
     public void setGranularity(int granularity) {
 169  0
         this.granularity = granularity;
 170   
     }
 171   
 
 172   
 }
 173