FileDocCategorySizeDatePackage
RenameExtensions.javaAPI DocApache Ant 1.704449Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional

RenameExtensions

public class RenameExtensions extends org.apache.tools.ant.taskdefs.MatchingTask
version
1.2
deprecated
since 1.5.x. Use <move> instead

Fields Summary
private String
fromExtension
private String
toExtension
private boolean
replace
private File
srcDir
private Mapper.MapperType
globType
Constructors Summary
public RenameExtensions()
Creates new RenameExtensions



        
      
        super();
        globType = new Mapper.MapperType();
        globType.setValue("glob");
    
Methods Summary
public voidexecute()
Executes the task.

throws
BuildException is there is a problem in the task execution.


        // first off, make sure that we've got a from and to extension
        if (fromExtension == null || toExtension == null || srcDir == null) {
            throw new BuildException("srcDir, fromExtension and toExtension "
                + "attributes must be set!");
        }

        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 = new Move();
        move.bindToOwner(this);
        move.setOwningTarget(getOwningTarget());
        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);

        move.execute();
    
public voidsetFromExtension(java.lang.String from)
The string that files must end in to be renamed

param
from the extension of files being renamed.

        fromExtension = from;
    
public voidsetReplace(boolean replace)
store replace attribute - this determines whether the target file should be overwritten if present

param
replace if true overwrite any target files that exist.

        this.replace = replace;
    
public voidsetSrcDir(java.io.File srcDir)
Set the source dir to find the files to be renamed.

param
srcDir the source directory.

        this.srcDir = srcDir;
    
public voidsetToExtension(java.lang.String to)
The string that renamed files will end with on completion

param
to the extension of the renamed files.

        toExtension = to;