Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 172   Methods: 6
NCLOC: 62   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RenameExtensions.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000,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   
  * Task to rename files based on extension. This task has the following
 56   
  * properties which can be set:
 57   
  * <ul>
 58   
  * <li>fromExtension: </li>
 59   
  * <li>toExtension: </li>
 60   
  * <li>srcDir: </li>
 61   
  * <li>replace: </li>
 62   
  * </ul>
 63   
  */
 64   
 
 65   
 package org.apache.tools.ant.taskdefs.optional;
 66   
 
 67   
 import java.io.File;
 68   
 import org.apache.tools.ant.BuildException;
 69   
 import org.apache.tools.ant.Project;
 70   
 import org.apache.tools.ant.taskdefs.MatchingTask;
 71   
 import org.apache.tools.ant.taskdefs.Move;
 72   
 import org.apache.tools.ant.types.Mapper;
 73   
 
 74   
 /**
 75   
  *
 76   
  * @author dIon Gillard <a href="mailto:dion@multitask.com.au">dion@multitask.com.au</a>
 77   
  * @author Stefan Bodewig
 78   
  * @version 1.2
 79   
  *
 80   
  * @deprecated Use &lt;move&gt; instead
 81   
  */
 82   
 public class RenameExtensions extends MatchingTask {
 83   
 
 84   
     private String fromExtension = "";
 85   
     private String toExtension = "";
 86   
     private boolean replace = false;
 87   
     private File srcDir;
 88   
 
 89   
     private Mapper.MapperType globType;
 90   
 
 91   
 
 92   
     /** Creates new RenameExtensions */
 93  0
     public RenameExtensions() {
 94  0
         super();
 95  0
         globType = new Mapper.MapperType();
 96  0
         globType.setValue("glob");
 97   
     }
 98   
 
 99   
     /**
 100   
      * The string that files must end in to be renamed
 101   
      **/
 102  0
     public void setFromExtension(String from) {
 103  0
         fromExtension = from;
 104   
     }
 105   
 
 106   
     /** 
 107   
      * The string that renamed files will end with on
 108   
      * completion
 109   
      */
 110  0
     public void setToExtension(String to) {
 111  0
         toExtension = to;
 112   
     }
 113   
 
 114   
     /**
 115   
      * store replace attribute - this determines whether the target file
 116   
      * should be overwritten if present
 117   
      */
 118  0
     public void setReplace(boolean replace) {
 119  0
         this.replace = replace;
 120   
     }
 121   
 
 122   
     /**
 123   
      * Set the source dir to find the files to be renamed.
 124   
      */
 125  0
     public void setSrcDir(File srcDir) {
 126  0
         this.srcDir = srcDir;
 127   
     }
 128   
 
 129   
     /**
 130   
      * Executes the task.
 131   
      */
 132  0
     public void execute() throws BuildException {
 133   
 
 134   
         // first off, make sure that we've got a from and to extension
 135  0
         if (fromExtension == null || toExtension == null || srcDir == null) {
 136  0
             throw new BuildException("srcDir, fromExtension and toExtension " 
 137   
                 + "attributes must be set!");
 138   
         }
 139   
 
 140  0
         log("DEPRECATED - The renameext task is deprecated.  Use move instead.",
 141   
             Project.MSG_WARN);
 142  0
         log("Replace this with:", Project.MSG_INFO);
 143  0
         log("<move todir=\"" + srcDir + "\" overwrite=\"" + replace + "\">",
 144   
             Project.MSG_INFO);
 145  0
         log("  <fileset dir=\"" + srcDir + "\" />", Project.MSG_INFO);
 146  0
         log("  <mapper type=\"glob\"", Project.MSG_INFO);
 147  0
         log("          from=\"*" + fromExtension + "\"", Project.MSG_INFO);
 148  0
         log("          to=\"*" + toExtension + "\" />", Project.MSG_INFO);
 149  0
         log("</move>", Project.MSG_INFO);
 150  0
         log("using the same patterns on <fileset> as you\'ve used here", 
 151   
             Project.MSG_INFO);
 152   
 
 153  0
         Move move = (Move) getProject().createTask("move");
 154  0
         move.setOwningTarget(getOwningTarget());
 155  0
         move.setTaskName(getTaskName());
 156  0
         move.setLocation(getLocation());
 157  0
         move.setTodir(srcDir);
 158  0
         move.setOverwrite(replace);
 159   
 
 160  0
         fileset.setDir(srcDir);
 161  0
         move.addFileset(fileset);
 162   
 
 163  0
         Mapper me = move.createMapper();
 164  0
         me.setType(globType);
 165  0
         me.setFrom("*" + fromExtension);
 166  0
         me.setTo("*" + toExtension);
 167   
 
 168  0
         move.execute();
 169   
     }
 170   
 
 171   
 }
 172