Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 178   Methods: 9
NCLOC: 50   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FacadeTaskHelper.java 100% 100% 100% 100%
 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.util.facade;
 56   
 
 57   
 import java.util.Enumeration;
 58   
 import java.util.Vector;
 59   
 
 60   
 /**
 61   
  * Helper class for facade implementations - encapsulates treatment of
 62   
  * explicit implementation choices, magic properties and
 63   
  * implementation specific command line arguments.
 64   
  *
 65   
  * @author Stefan Bodewig
 66   
  *
 67   
  * @version $Revision: 1.5 $
 68   
  *
 69   
  * @since Ant 1.5
 70   
  */
 71   
 public class FacadeTaskHelper {
 72   
 
 73   
     /**
 74   
      * Command line arguments.
 75   
      */
 76   
     private Vector args = new Vector();
 77   
 
 78   
     /**
 79   
      * The explicitly chosen implementation.
 80   
      */
 81   
     private String userChoice;
 82   
 
 83   
     /**
 84   
      * The magic property to consult.
 85   
      */
 86   
     private String magicValue;
 87   
 
 88   
     /**
 89   
      * The default value.
 90   
      */
 91   
     private String defaultValue;
 92   
 
 93   
     /**
 94   
      * @param defaultValue The default value for the implementation.
 95   
      * Must not be null.
 96   
      */
 97  30
     public FacadeTaskHelper(String defaultValue) {
 98  30
         this(defaultValue, null);
 99   
     }
 100   
 
 101   
     /**
 102   
      * @param defaultValue The default value for the implementation.
 103   
      * Must not be null.
 104   
      * @param magic the value of a magic property that may hold a user
 105   
      * choice.  May be null.
 106   
      */
 107  32
     public FacadeTaskHelper(String defaultValue, String magicValue) {
 108  32
         this.defaultValue = defaultValue;
 109  32
         this.magicValue = magicValue;
 110   
     }
 111   
 
 112   
     /**
 113   
      * Used to set the value of the magic property.
 114   
      */
 115  224
     public void setMagicValue(String magicValue) {
 116  224
         this.magicValue = magicValue;
 117   
     }
 118   
 
 119   
     /**
 120   
      * Used for explicit user choices.
 121   
      */
 122  53
     public void setImplementation(String userChoice) {
 123  53
         this.userChoice = userChoice;
 124   
     }
 125   
 
 126   
     /**
 127   
      * Retrieves the implementation.
 128   
      */
 129  234
     public String getImplementation() {
 130  234
         return userChoice != null ? userChoice
 131   
                                   : (magicValue != null ? magicValue
 132   
                                                         : defaultValue);
 133   
     }
 134   
 
 135   
     /**
 136   
      * Retrieves the explicit user choice
 137   
      */
 138  24
     public String getExplicitChoice() {
 139  24
         return userChoice;
 140   
     }
 141   
 
 142   
     /**
 143   
      * Command line argument.
 144   
      */
 145  3
     public void addImplementationArgument(ImplementationSpecificArgument arg) {
 146  3
         args.addElement(arg);
 147   
     }
 148   
 
 149   
     /**
 150   
      * Retrieves the command line arguments enabled for the current
 151   
      * facade implementation.
 152   
      */
 153  29
     public String[] getArgs() {
 154  29
         Vector tmp = new Vector(args.size());
 155  29
         for (Enumeration enum = args.elements(); enum.hasMoreElements();) {
 156  10
             ImplementationSpecificArgument arg = 
 157   
                 ((ImplementationSpecificArgument) enum.nextElement());
 158  10
             String[] curr = arg.getParts(getImplementation());
 159  10
             for (int i = 0; i < curr.length; i++) {
 160  7
                 tmp.addElement(curr[i]);
 161   
             }
 162   
         }
 163  29
         String[] res = new String[tmp.size()];
 164  29
         tmp.copyInto(res);
 165  29
         return res;
 166   
     }
 167   
 
 168   
     /**
 169   
      * Tests whether the implementation has been chosen by the user
 170   
      * (either via a magic property or explicitly.
 171   
      *
 172   
      * @since Ant 1.5.2
 173   
      */
 174  9
     public boolean hasBeenSet() {
 175  9
         return userChoice != null || magicValue != null;
 176   
     }
 177   
 }
 178