Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 153   Methods: 13
NCLOC: 66   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Attrib.java 0% 0% 0% 0%
 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.taskdefs.optional.windows;
 56   
 
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.taskdefs.ExecuteOn;
 59   
 import org.apache.tools.ant.taskdefs.condition.Os;
 60   
 import org.apache.tools.ant.types.FileSet;
 61   
 
 62   
 import java.io.File;
 63   
 
 64   
 /**
 65   
  * Attrib equivalent for Win32 environments.
 66   
  * Note: Attrib parameters /S and /D are not handled.
 67   
  *
 68   
  * @author skanga@bigfoot.com
 69   
  * @author <a href="mailto:Jerome@jeromelacoste.com">Jerome Lacoste</a>
 70   
  *
 71   
  * @since Ant 1.6
 72   
  */
 73   
 public class Attrib extends ExecuteOn {
 74   
 
 75   
     private static final String ATTR_READONLY = "R";
 76   
     private static final String ATTR_ARCHIVE  = "A";
 77   
     private static final String ATTR_SYSTEM   = "S";
 78   
     private static final String ATTR_HIDDEN   = "H";                  
 79   
     private static final String SET    = "+";                  
 80   
     private static final String UNSET  = "-";                 
 81   
     
 82   
     private boolean haveAttr = false;
 83   
 
 84  0
     public Attrib() {
 85  0
         super.setExecutable("attrib");
 86  0
         super.setParallel(false);
 87   
     }
 88   
 
 89  0
     public void setFile(File src) {
 90  0
         FileSet fs = new FileSet();
 91  0
         fs.setFile(src);
 92  0
         addFileset(fs);
 93   
     }
 94   
 
 95   
     /** set the ReadOnly file attribute */  
 96  0
     public void setReadonly(boolean value) { 
 97  0
         addArg(value, ATTR_READONLY); 
 98   
     }
 99   
 
 100   
     /** set the Archive file attribute */  
 101  0
     public void setArchive(boolean value) {  
 102  0
         addArg(value, ATTR_ARCHIVE); 
 103   
     }
 104   
 
 105   
     /** set the System file attribute */      
 106  0
     public void setSystem(boolean value) {   
 107  0
         addArg(value, ATTR_SYSTEM); 
 108   
     }
 109   
 
 110   
     /** set the Hidden file attribute */      
 111  0
     public void setHidden(boolean value) {   
 112  0
         addArg(value, ATTR_HIDDEN); 
 113   
     }
 114   
     
 115  0
     protected void checkConfiguration() {
 116  0
         if (!haveAttr()) {
 117  0
             throw new BuildException("Missing attribute parameter", 
 118   
                                      getLocation());
 119   
         }
 120  0
         super.checkConfiguration();
 121   
     }
 122   
 
 123  0
     public void setExecutable(String e) {
 124  0
         throw new BuildException(taskType + 
 125   
                                  " doesn\'t support the executable attribute",
 126   
                                  getLocation());
 127   
     }
 128   
 
 129  0
     public void setCommand(String e) {
 130  0
         throw new BuildException(taskType + 
 131   
                                  " doesn\'t support the command attribute",
 132   
                                  getLocation());
 133   
     }
 134   
 
 135  0
     protected boolean isValidOs() {
 136  0
         return Os.isFamily("windows") && super.isValidOs();
 137   
     }
 138   
 
 139  0
     private static String getSignString(boolean attr) { 
 140  0
         return (attr == true ? SET : UNSET);
 141   
     }
 142   
       
 143  0
     private void addArg(boolean sign, String attribute) {
 144  0
         createArg().setValue(getSignString(sign) + attribute);
 145  0
         haveAttr = true;
 146   
     }
 147   
     
 148  0
     private boolean haveAttr() {
 149  0
         return haveAttr;    
 150   
     }
 151   
 
 152   
 }
 153