1 18 19 package org.apache.tools.ant.taskdefs; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import org.apache.tools.ant.BuildException; 24 import org.apache.tools.ant.Project; 25 import org.apache.tools.ant.Task; 26 import org.apache.tools.ant.util.FileUtils; 27 28 34 public class Rename extends Task { 35 36 private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); 37 38 private File src; 39 private File dest; 40 private boolean replace = true; 41 42 43 47 public void setSrc(File src) { 48 this.src = src; 49 } 50 51 55 public void setDest(File dest) { 56 this.dest = dest; 57 } 58 59 63 public void setReplace(String replace) { 64 this.replace = Project.toBoolean(replace); 65 } 66 67 68 73 public void execute() throws BuildException { 74 log("DEPRECATED - The rename task is deprecated. Use move instead."); 75 76 if (dest == null) { 77 throw new BuildException("dest attribute is required", getLocation()); 78 } 79 80 if (src == null) { 81 throw new BuildException("src attribute is required", getLocation()); 82 } 83 84 if (!replace && dest.exists()) { 85 throw new BuildException(dest + " already exists."); 86 } 87 88 try { 89 FILE_UTILS.rename(src, dest); 90 } catch (IOException e) { 91 throw new BuildException("Unable to rename " + src + " to " 92 + dest, e, getLocation()); 93 } 94 } 95 } 96 | Popular Tags |