Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 195   Methods: 8
NCLOC: 77   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FilenameSelector.java 66.7% 84.8% 100% 81.4%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 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.types.selectors;
 56   
 
 57   
 import java.io.File;
 58   
 import org.apache.tools.ant.Project;
 59   
 import org.apache.tools.ant.types.Parameter;
 60   
 
 61   
 /**
 62   
  * Selector that filters files based on the filename.
 63   
  *
 64   
  * @author <a href="mailto:bruce@callenish.com">Bruce Atherton</a>
 65   
  * @since 1.5
 66   
  */
 67   
 public class FilenameSelector extends BaseExtendSelector {
 68   
 
 69   
     private String pattern = null;
 70   
     private boolean casesensitive = true;
 71   
     private boolean negated = false;
 72   
     public final static String NAME_KEY = "name";
 73   
     public final static String CASE_KEY = "casesensitive";
 74   
     public final static String NEGATE_KEY = "negate";
 75   
 
 76  73
     public FilenameSelector() {
 77   
     }
 78   
 
 79  130
     public String toString() {
 80  130
         StringBuffer buf = new StringBuffer("{filenameselector name: ");
 81  130
         buf.append(pattern);
 82  130
         buf.append(" negate: ");
 83  130
         if (negated) {
 84  0
             buf.append("true");
 85   
         } else {
 86  130
             buf.append("false");
 87   
         }
 88  130
         buf.append(" casesensitive: ");
 89  130
         if (casesensitive) {
 90  130
             buf.append("true");
 91   
         } else {
 92  0
             buf.append("false");
 93   
         }
 94  130
         buf.append("}");
 95  130
         return buf.toString();
 96   
     }
 97   
 
 98   
     /**
 99   
      * The name of the file, or the pattern for the name, that
 100   
      * should be used for selection.
 101   
      *
 102   
      * @param pattern the file pattern that any filename must match
 103   
      *                against in order to be selected.
 104   
      */
 105  70
     public void setName(String pattern) {
 106  70
         pattern = pattern.replace('/',File.separatorChar).replace('\\',
 107   
                 File.separatorChar);
 108  70
         if (pattern.endsWith(File.separator)) {
 109  0
             pattern += "**";
 110   
         }
 111  70
         this.pattern = pattern;
 112   
     }
 113   
 
 114   
     /**
 115   
      * Whether to ignore case when checking filenames.
 116   
      *
 117   
      * @param casesensitive whether to pay attention to case sensitivity
 118   
      */
 119  1
     public void setCasesensitive(boolean casesensitive) {
 120  1
         this.casesensitive = casesensitive;
 121   
     }
 122   
 
 123   
     /**
 124   
      * You can optionally reverse the selection of this selector,
 125   
      * thereby emulating an &lt;exclude&gt; tag, by setting the attribute
 126   
      * negate to true. This is identical to surrounding the selector
 127   
      * with &lt;not&gt;&lt;/not&gt;.
 128   
      *
 129   
      * @param negated whether to negate this selection
 130   
      */
 131  1
     public void setNegate(boolean negated) {
 132  1
         this.negated = negated;
 133   
     }
 134   
 
 135   
     /**
 136   
      * When using this as a custom selector, this method will be called.
 137   
      * It translates each parameter into the appropriate setXXX() call.
 138   
      *
 139   
      * @param parameters the complete set of parameters for this selector
 140   
      */
 141  2
     public void setParameters(Parameter[] parameters) {
 142  2
         super.setParameters(parameters);
 143  2
         if (parameters != null) {
 144  2
             for (int i = 0; i < parameters.length; i++) {
 145  2
                 String paramname = parameters[i].getName();
 146  2
                 if (NAME_KEY.equalsIgnoreCase(paramname)) {
 147  1
                     setName(parameters[i].getValue());
 148   
                 }
 149  1
                 else if (CASE_KEY.equalsIgnoreCase(paramname)) {
 150  0
                     setCasesensitive(Project.toBoolean(
 151   
                         parameters[i].getValue()));
 152   
                 }
 153  1
                 else if (NEGATE_KEY.equalsIgnoreCase(paramname)) {
 154  0
                     setNegate(Project.toBoolean(parameters[i].getValue()));
 155   
                 }
 156   
                 else {
 157  1
                     setError("Invalid parameter " + paramname);
 158   
                 }
 159   
             }
 160   
         }
 161   
     }
 162   
 
 163   
     /**
 164   
      * Checks to make sure all settings are kosher. In this case, it
 165   
      * means that the name attribute has been set.
 166   
      *
 167   
      */
 168  330036
     public void verifySettings() {
 169  330036
         if (pattern == null) {
 170  1
             setError("The name attribute is required");
 171   
         }
 172   
     }
 173   
 
 174   
     /**
 175   
      * The heart of the matter. This is where the selector gets to decide
 176   
      * on the inclusion of a file in a particular fileset. Most of the work
 177   
      * for this selector is offloaded into SelectorUtils, a static class
 178   
      * that provides the same services for both FilenameSelector and
 179   
      * DirectoryScanner.
 180   
      *
 181   
      * @param basedir the base directory the scan is being done from
 182   
      * @param filename is the name of the file to check
 183   
      * @param file is a java.io.File object the selector can use
 184   
      * @return whether the file should be selected or not
 185   
      */
 186  10772
     public boolean isSelected(File basedir, String filename, File file) {
 187  10772
         validate();
 188   
 
 189  10769
         return (SelectorUtils.matchPath(pattern,filename,
 190   
                 casesensitive) == !(negated));
 191   
     }
 192   
 
 193   
 }
 194   
 
 195