1 18 28 29 package org.apache.tools.ant.taskdefs.optional; 30 31 import java.io.File ; 32 import org.apache.tools.ant.BuildException; 33 import org.apache.tools.ant.Project; 34 import org.apache.tools.ant.taskdefs.MatchingTask; 35 import org.apache.tools.ant.taskdefs.Move; 36 import org.apache.tools.ant.types.Mapper; 37 38 45 public class RenameExtensions extends MatchingTask { 46 47 private String fromExtension = ""; 48 private String toExtension = ""; 49 private boolean replace = false; 50 private File srcDir; 51 52 private Mapper.MapperType globType; 53 54 55 56 public RenameExtensions() { 57 super(); 58 globType = new Mapper.MapperType(); 59 globType.setValue("glob"); 60 } 61 62 67 public void setFromExtension(String from) { 68 fromExtension = from; 69 } 70 71 77 public void setToExtension(String to) { 78 toExtension = to; 79 } 80 81 87 public void setReplace(boolean replace) { 88 this.replace = replace; 89 } 90 91 96 public void setSrcDir(File srcDir) { 97 this.srcDir = srcDir; 98 } 99 100 105 public void execute() throws BuildException { 106 107 if (fromExtension == null || toExtension == null || srcDir == null) { 109 throw new BuildException("srcDir, fromExtension and toExtension " 110 + "attributes must be set!"); 111 } 112 113 log("DEPRECATED - The renameext task is deprecated. Use move instead.", 114 Project.MSG_WARN); 115 log("Replace this with:", Project.MSG_INFO); 116 log("<move todir=\"" + srcDir + "\" overwrite=\"" + replace + "\">", 117 Project.MSG_INFO); 118 log(" <fileset dir=\"" + srcDir + "\" />", Project.MSG_INFO); 119 log(" <mapper type=\"glob\"", Project.MSG_INFO); 120 log(" from=\"*" + fromExtension + "\"", Project.MSG_INFO); 121 log(" to=\"*" + toExtension + "\" />", Project.MSG_INFO); 122 log("</move>", Project.MSG_INFO); 123 log("using the same patterns on <fileset> as you\'ve used here", 124 Project.MSG_INFO); 125 126 Move move = new Move(); 127 move.bindToOwner(this); 128 move.setOwningTarget(getOwningTarget()); 129 move.setTaskName(getTaskName()); 130 move.setLocation(getLocation()); 131 move.setTodir(srcDir); 132 move.setOverwrite(replace); 133 134 fileset.setDir(srcDir); 135 move.addFileset(fileset); 136 137 Mapper me = move.createMapper(); 138 me.setType(globType); 139 me.setFrom("*" + fromExtension); 140 me.setTo("*" + toExtension); 141 142 move.execute(); 143 } 144 145 } 146 | Popular Tags |