ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional RenameExtensions.java
Date Mon, 18 Dec 2000 14:27:19 GMT
bodewig     00/12/18 06:26:53

  Modified:    docs     index.html
               src/main/org/apache/tools/ant/taskdefs MatchingTask.java
               src/main/org/apache/tools/ant/taskdefs/optional
                        RenameExtensions.java
  Log:
  Deprecated the optional <renameext> task as its functionality has been
  superseded by the built-in <move> task.
  
  Revision  Changes    Path
  1.176     +4 -1      jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.175
  retrieving revision 1.176
  diff -u -r1.175 -r1.176
  --- index.html	2000/12/16 01:57:25	1.175
  +++ index.html	2000/12/18 14:26:38	1.176
  @@ -29,7 +29,7 @@
   </ul>
   
   <p>Version: @VERSION@</p>
  -<p>$Id: index.html,v 1.175 2000/12/16 01:57:25 donaldp Exp $</p>
  +<p>$Id: index.html,v 1.176 2000/12/18 14:26:38 bodewig Exp $</p>
   
   <hr>
   <h2>Table of Contents</h2>
  @@ -5655,6 +5655,9 @@
   </blockquote>
   <hr>
   <h2><a name="renameexts">RenameExtensions</a></h2>
  +<h3><i>Deprecated</i></h3>
  +<p><i>This task has been deprecated.  Use the <a href="#move">move</a>
  +task with a <a href="#glob-mapper">glob mapper</a> instead.</i></p>
   <h3>Description</h3>
   <p>Renames files in the <code>srcDir</code> directory ending with the
   <code>fromExtension</code> string so that they end with the 
  
  
  
  1.13      +1 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
  
  Index: MatchingTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- MatchingTask.java	2000/11/25 02:38:37	1.12
  +++ MatchingTask.java	2000/12/18 14:26:45	1.13
  @@ -68,7 +68,7 @@
    * @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
    * @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>
    * @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
  - * @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    */
   
   public abstract class MatchingTask extends Task {
  
  
  
  1.6       +39 -50    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java
  
  Index: RenameExtensions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/RenameExtensions.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RenameExtensions.java	2000/11/25 01:10:09	1.5
  +++ RenameExtensions.java	2000/12/18 14:26:49	1.6
  @@ -58,9 +58,6 @@
    * <li>srcDir: </li>
    * <li>replace: </li>
    * </ul>
  - *
  - * @author dIon Gillard <a href="mailto:dion@multitask.com.au">dion@multitask.com.au</a>
  - * @version 1.2
    */
   
   package org.apache.tools.ant.taskdefs.optional;
  @@ -69,10 +66,13 @@
   import java.util.*;
   import org.apache.tools.ant.*;
   import org.apache.tools.ant.taskdefs.*;
  +import org.apache.tools.ant.types.Mapper;
   
   /**
    *
  - * @author  dion
  + * @author dIon Gillard <a href="mailto:dion@multitask.com.au">dion@multitask.com.au</a>
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
  + * @version 1.2
    */
   public class RenameExtensions extends MatchingTask {
   
  @@ -81,10 +81,14 @@
       private boolean replace = false;
       private File srcDir;
   
  +    private Mapper.MapperType globType;
  +
   
       /** Creates new RenameExtensions */
       public RenameExtensions() {
           super();
  +        globType = new Mapper.MapperType();
  +        globType.setValue("glob");
       }
   
       /** store fromExtension **/
  @@ -108,8 +112,8 @@
       /**
        * Set the source dir to find the files to be renamed.
        */
  -    public void setSrcDir(String srcDirName) {
  -        srcDir = project.resolveFile(srcDirName);
  +    public void setSrcDir(File srcDir) {
  +        this.srcDir = srcDir;
       }
   
       /**
  @@ -122,51 +126,36 @@
               throw new BuildException( "srcDir, fromExtension and toExtension " +
                                         "attributes must be set!" );
           }
  -
  -        // scan source and dest dirs to build up rename list
  -        DirectoryScanner ds = getDirectoryScanner(srcDir);
   
  -        String[] files = ds.getIncludedFiles();
  +        log("DEPRECATED - The renameext task is deprecated.  Use move instead.",
  +            Project.MSG_WARN);
  +        log("Replace this with:", Project.MSG_INFO);
  +        log("<move todir=\""+srcDir+"\" overwrite=\""+replace+"\">", 
  +            Project.MSG_INFO);
  +        log("  <fileset dir=\""+srcDir+"\" />", Project.MSG_INFO);
  +        log("  <mapper type=\"glob\"", Project.MSG_INFO);
  +        log("          from=\"*"+fromExtension+"\"", Project.MSG_INFO);
  +        log("          to=\"*"+toExtension+"\" />", Project.MSG_INFO);
  +        log("</move>", Project.MSG_INFO);
  +        log("using the same patterns on <fileset> as you\'ve used here", 
  +            Project.MSG_INFO);
  +
  +        Move move = (Move)project.createTask("move");
  +        move.setOwningTarget(target);
  +        move.setTaskName(getTaskName());
  +        move.setLocation(getLocation());
  +        move.setTodir(srcDir);
  +        move.setOverwrite(replace);
  +
  +        fileset.setDir(srcDir);
  +        move.addFileset(fileset);
  +
  +        Mapper me = move.createMapper();
  +        me.setType(globType);
  +        me.setFrom("*"+fromExtension);
  +        me.setTo("*"+toExtension);
   
  -        Hashtable renameList = scanDir(srcDir, files);
  -
  -        Enumeration e = renameList.keys();
  -        File fromFile = null;
  -        File toFile = null;
  -        while (e.hasMoreElements()) {
  -            fromFile = (File)e.nextElement();
  -            toFile = (File)renameList.get(fromFile);
  -            if (toFile.exists() && replace) toFile.delete();
  -            if (!fromFile.renameTo(toFile)) {
  -                throw new BuildException( "Rename from: '" + fromFile + "' to '" + 
  -                                          toFile + "' failed." );
  -            }
  -        }
  -
  +        move.execute();
       }
  -    private Hashtable scanDir(File srcDir, String[] files) {
  -        Hashtable list = new Hashtable();
  -        for (int i = 0; i < files.length; i++) {
  -            File srcFile = new File(srcDir, files[i]);
  -            String filename = files[i];
  -            // if it's a file that ends in the fromExtension, copy to the rename list
  -            if (filename.toLowerCase().endsWith(fromExtension)) {
  -                File destFile = 
  -                    new File( srcDir, 
  -                              filename.substring(0, filename.lastIndexOf(fromExtension))
+ 
  -                              toExtension );
  -
  -                if (replace || !destFile.exists()) {
  -                    list.put(srcFile, destFile);
  -                } else {
  -                    log( "Rejecting file: '" + srcFile + "' for rename as " + 
  -                         "replace is false and file exists", Project.MSG_VERBOSE );
  -                }
  -            } else {
  -                log( "File '"+ filename + "' doesn't match fromExtension: '" + 
  -                     fromExtension + "'", Project.MSG_VERBOSE );
  -            }
  -        }
  -        return list;
  -    }
  +
   }
  
  
  

Mime
View raw message