Paul, This task would be improved by making the attributes use meaningful names rather than numbers (as it is, every usage of the task in a build file would probably have to be commented to state what is being done).
Ant provides a useful enumerated type mechanism for just this purpose, called EnumeratedAttribute. Take a look at the source for Echo for an example of its use. Phil :n) On Thu, 2003-10-09 at 16:18, [EMAIL PROTECTED] wrote: > > > -------Original Message------- > > From: Ant Users List > Date: 08 October 2003 18:03:45 > To: user@ant.apache.org > Subject: Java Add On for Ant to fix filename + extension case issues > > > Notes: > > This code expects a filename.ext format because we are dealing with > PeopleSoft > cobol source that needs to be in the format FILENAME.cbl and SQR > source that > needs to be lower case. Now we can use ant to convert Windows based > source > to unix thanks to ant + a bit of java code added. > > You need this your build.xml file > > <taskdef name="fixfilecase" classname="AntXtra.FixFileCase"/> > > Then for COBOL: > > <!-- fix uppercase filename lower case extension --> > <fixfilecase srcdir="${build}" mask="1" action="1"/> > <fixfilecase srcdir="${build}" mask="2" action="2"/> > > For SQR: > > <fixfilecase srcdir="${build}" mask="3" action="2"/> > > > And the source: > > package AntXtra; > > import org.apache.tools.ant.taskdefs.MatchingTask; > import org.apache.tools.ant.BuildException; > import org.apache.tools.ant.DirectoryScanner; > > import java.io.File; > import java.io.IOException; > > /** > * Converts file names providing lowercase/uppercase functionality. > * <p> > * This task can take the following arguments: > * <ul> > * <li>srcdir > * <li>mask > * <li>action > * </ul> > * <p> > * > * @author Paul Gilligan<a > href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED] > net</a> > * @version 1.0 > */ > > public class FixFileCase extends MatchingTask { > > public static final int FILENAME = 1; > public static final int EXTENSION = 2; > public static final int BOTH = 3; > > public static final int UPPER = 1; > public static final int LOWER = 2; > > private File srcDir = null; > private int mask = BOTH; > private int action = UPPER; > > /** > * Set the source dir to find the source text files. > */ > public void setSrcdir(File srcDir) { > this.srcDir = srcDir; > } > > /** > * Set the mask for processing file names and or extensions > */ > public void setMask(int mask) { > this.mask = mask; > } > > /** > * Set the action for processing file names and or extensions > */ > public void setAction(int action) { > this.action = action; > } > > > /** > * Executes the task. > */ > public void execute() throws BuildException { > // Make sure that we've got a good srcdir > > if (srcDir == null) { > throw new BuildException("srcdir attribute must be set!"); > } > if (!srcDir.exists()) { > throw new BuildException("srcdir does not exist!"); > } > if (!srcDir.isDirectory()) { > throw new BuildException("srcdir is not a directory!"); > } > > // Check the for vaild mask > switch (mask) { > case FILENAME: log("Fixing Filename only"); break; > case EXTENSION: log("Fixing Extension only"); break; > case BOTH: log("Fixing Filename and Extension"); break; > default: throw new BuildException("invalid mask, must be 1, 2 or 3!"); > } > > // Check the for vaild action > switch (action) { > case UPPER: log("with upper case action"); break; > case LOWER: log("with lower case action"); break; > default: throw new BuildException("invalid action, must be 1 or 2!"); > } > > DirectoryScanner ds = super.getDirectoryScanner(srcDir); > String[] files = ds.getIncludedFiles(); > > for (int i = 0; i < files.length; i++) { > > // try for an extension > String n = files[i].substring(0, files[i].lastIndexOf(".")); > String e = files[i].substring(files[i].lastIndexOf(".")+1); > > switch(action) > { > case UPPER: > { > switch(mask) { > case FILENAME: n = n.toUpperCase(); break; > case EXTENSION: e = e.toUpperCase(); break; > case BOTH: n = n.toUpperCase(); e = e.toUpperCase(); break; > } > } > break; > > case LOWER: > { > switch(mask) { > case FILENAME: n = n.toLowerCase(); break; > case EXTENSION: e = e.toLowerCase(); break; > case BOTH: n = n.toLowerCase(); e = e.toLowerCase(); break; > } > } > break; > } > > File src = new File(srcDir, files[i]); > File dst = new File(srcDir, n+"."+e); > > boolean renamed = src.renameTo(dst); > > if(!renamed) { > log("source "+src+" destination "+dst+" not renamed!"); > } > } // (int i = 0; i < files.length; i++) { > } > } > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > . > > > > ____________________________________________________ > IncrediMail - Email has finally evolved - Click Here -- Phil Weighill-Smith <[EMAIL PROTECTED]> Volantis Systems