Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 296   Methods: 23
NCLOC: 103   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BaseSelectorContainer.java 75% 61.5% 47.8% 59.5%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002-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 java.io.File;
 58   
 import java.util.Enumeration;
 59   
 import java.util.Vector;
 60   
 import org.apache.tools.ant.BuildException;
 61   
 import org.apache.tools.ant.Project;
 62   
 
 63   
 /**
 64   
  * This is the base class for selectors that can contain other selectors.
 65   
  *
 66   
  * @author <a href="mailto:bruce@callenish.com">Bruce Atherton</a>
 67   
  * @since 1.5
 68   
  */
 69   
 public abstract class BaseSelectorContainer extends BaseSelector
 70   
         implements SelectorContainer {
 71   
 
 72   
     private Vector selectorsList = new Vector();
 73   
 
 74   
     /**
 75   
      * Default constructor.
 76   
      */
 77  88
     public BaseSelectorContainer() {
 78   
     }
 79   
 
 80   
     /**
 81   
      * Indicates whether there are any selectors here.
 82   
      */
 83  100
     public boolean hasSelectors() {
 84  100
         return !(selectorsList.isEmpty());
 85   
     }
 86   
 
 87   
     /**
 88   
      * Gives the count of the number of selectors in this container
 89   
      */
 90  171552
     public int selectorCount() {
 91  171552
         return selectorsList.size();
 92   
     }
 93   
 
 94   
     /**
 95   
      * Returns the set of selectors as an array.
 96   
      */
 97  0
     public FileSelector[] getSelectors(Project p) {
 98  0
         FileSelector[] result = new FileSelector[selectorsList.size()];
 99  0
         selectorsList.copyInto(result);
 100  0
         return result;
 101   
     }
 102   
 
 103   
     /**
 104   
      * Returns an enumerator for accessing the set of selectors.
 105   
      */
 106  255603
     public Enumeration selectorElements() {
 107  255603
         return selectorsList.elements();
 108   
     }
 109   
 
 110   
     /**
 111   
      * Convert the Selectors within this container to a string. This will
 112   
      * just be a helper class for the subclasses that put their own name
 113   
      * around the contents listed here.
 114   
      *
 115   
      * @return comma separated list of Selectors contained in this one
 116   
      */
 117  99
     public String toString() {
 118  99
         StringBuffer buf = new StringBuffer();
 119  99
         Enumeration e = selectorElements();
 120  99
         if (e.hasMoreElements()) {
 121  99
             while(e.hasMoreElements()) {
 122  193
                 buf.append(e.nextElement().toString());
 123  193
                 if (e.hasMoreElements()) {
 124  94
                     buf.append(", ");
 125   
                 }
 126   
             }
 127   
         }
 128   
 
 129  99
         return buf.toString();
 130   
     }
 131   
 
 132   
     /**
 133   
      * Add a new selector into this container.
 134   
      *
 135   
      * @param selector the new selector to add
 136   
      */
 137  115
     public void appendSelector(FileSelector selector) {
 138  115
         selectorsList.addElement(selector);
 139   
     }
 140   
 
 141   
     /**
 142   
      * <p>This implementation validates the container by calling
 143   
      * verifySettings() and then validates each contained selector
 144   
      * provided that the selector implements the validate interface.
 145   
      * </p>
 146   
      * <p>Ordinarily, this will validate all the elements of a selector
 147   
      * container even if the isSelected() method of some elements is
 148   
      * never called. This has two effects:</p>
 149   
      * <ul>
 150   
      * <li>Validation will often occur twice.
 151   
      * <li>Since it is not required that selectors derive from
 152   
      * BaseSelector, there could be selectors in the container whose
 153   
      * error conditions are not detected if their isSelected() call
 154   
      * is never made.
 155   
      * </ul>
 156   
      */
 157  241179
     public void validate() {
 158  241179
         verifySettings();
 159  241179
         String errmsg = getError();
 160  241179
         if (errmsg != null) {
 161  0
             throw new BuildException(errmsg);
 162   
         }
 163  241179
         Enumeration e = selectorElements();
 164  241179
         while(e.hasMoreElements()) {
 165  511522
             Object o = e.nextElement();
 166  511522
             if (o instanceof BaseSelector) {
 167  511522
                 ((BaseSelector)o).validate();
 168   
             }
 169   
         }
 170   
     }
 171   
 
 172   
 
 173   
     /**
 174   
      * Method that each selector will implement to create their selection
 175   
      * behaviour. This is what makes SelectorContainer abstract.
 176   
      *
 177   
      * @param basedir the base directory the scan is being done from
 178   
      * @param filename the name of the file to check
 179   
      * @param file a java.io.File object for the filename that the selector
 180   
      * can use
 181   
      * @return whether the file should be selected or not
 182   
      */
 183   
     public abstract boolean isSelected(File basedir, String filename,
 184   
                                        File file);
 185   
 
 186   
 
 187   
     /* Methods below all add specific selectors */
 188   
 
 189   
     /**
 190   
      * add a "Select" selector entry on the selector list
 191   
      */
 192  35
     public void addSelector(SelectSelector selector) {
 193  35
         appendSelector(selector);
 194   
     }
 195   
 
 196   
     /**
 197   
      * add an "And" selector entry on the selector list
 198   
      */
 199  0
     public void addAnd(AndSelector selector) {
 200  0
         appendSelector(selector);
 201   
     }
 202   
 
 203   
     /**
 204   
      * add an "Or" selector entry on the selector list
 205   
      */
 206  14
     public void addOr(OrSelector selector) {
 207  14
         appendSelector(selector);
 208   
     }
 209   
 
 210   
     /**
 211   
      * add a "Not" selector entry on the selector list
 212   
      */
 213  1
     public void addNot(NotSelector selector) {
 214  1
         appendSelector(selector);
 215   
     }
 216   
 
 217   
     /**
 218   
      * add a "None" selector entry on the selector list
 219   
      */
 220  0
     public void addNone(NoneSelector selector) {
 221  0
         appendSelector(selector);
 222   
     }
 223   
 
 224   
     /**
 225   
      * add a majority selector entry on the selector list
 226   
      */
 227  0
     public void addMajority(MajoritySelector selector) {
 228  0
         appendSelector(selector);
 229   
     }
 230   
 
 231   
     /**
 232   
      * add a selector date entry on the selector list
 233   
      */
 234  0
     public void addDate(DateSelector selector) {
 235  0
         appendSelector(selector);
 236   
     }
 237   
 
 238   
     /**
 239   
      * add a selector size entry on the selector list
 240   
      */
 241  0
     public void addSize(SizeSelector selector) {
 242  0
         appendSelector(selector);
 243   
     }
 244   
 
 245   
     /**
 246   
      * add a selector filename entry on the selector list
 247   
      */
 248  65
     public void addFilename(FilenameSelector selector) {
 249  65
         appendSelector(selector);
 250   
     }
 251   
 
 252   
     /**
 253   
      * add an extended selector entry on the selector list
 254   
      */
 255  0
     public void addCustom(ExtendSelector selector) {
 256  0
         appendSelector(selector);
 257   
     }
 258   
 
 259   
     /**
 260   
      * add a contains selector entry on the selector list
 261   
      */
 262  0
     public void addContains(ContainsSelector selector) {
 263  0
         appendSelector(selector);
 264   
     }
 265   
 
 266   
     /**
 267   
      * add a present selector entry on the selector list
 268   
      */
 269  0
     public void addPresent(PresentSelector selector) {
 270  0
         appendSelector(selector);
 271   
     }
 272   
 
 273   
     /**
 274   
      * add a depth selector entry on the selector list
 275   
      */
 276  0
     public void addDepth(DepthSelector selector) {
 277  0
         appendSelector(selector);
 278   
     }
 279   
 
 280   
     /**
 281   
      * add a depends selector entry on the selector list
 282   
      */
 283  0
     public void addDepend(DependSelector selector) {
 284  0
         appendSelector(selector);
 285   
     }
 286   
 
 287   
     /**
 288   
      * adds a different selector to the selector list
 289   
      */
 290  0
     public void addDifferent(DifferentSelector selector) {
 291  0
         appendSelector(selector);
 292   
     }
 293   
 
 294   
 }
 295   
 
 296