DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13027>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13027 Execute target in multiple build files Summary: Execute target in multiple build files Product: Ant Version: unspecified Platform: Other OS/Version: Other Status: NEW Severity: Enhancement Priority: Other Component: Core tasks AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] When working with a modular application, it is preferred to have an independent ant script for each module, which are typically arranged in various subdirectories. In order to build those modules with ant today, it is necessary to create a lot of repetitive code in the "master" build script, calling the build for each module manually. To tackle this, we created our own optional replacement for the "ant" task which we called "antdelegate". It allows you to add a fileset containing build files, and the specified target will be called in those build files. The code follows. Btw. it would be a good idea to add protected accessors to private members in order to make it easier to extend existing tasks. package com.decode.ant; import org.apache.tools.ant.taskdefs.Ant; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.FileSet; import java.util.*; import java.io.File; import java.io.IOException; public class AntDelegate extends Ant{ private String thetarget=""; private List filesets = new LinkedList(); public void execute() throws BuildException { Iterator it = filesets.iterator(); while (it.hasNext()){ log("Fileset 1", Project.MSG_VERBOSE); execFileset((FileSet)(it.next())); } } private void execFileset(FileSet fileSet) throws BuildException { DirectoryScanner ds = fileSet.getDirectoryScanner(project); File fromDir = fileSet.getDir(project); String[] buildFiles = ds.getIncludedFiles(); for(int j=0;j<buildFiles.length;j++){ String filename = null; try { filename = fromDir.getCanonicalPath()+ File.separator+ buildFiles[j]; } catch (IOException e) { throw new BuildException(e); } setAntfile(filename); log("Executing target [" + thetarget + "] in " + filename, Project.MSG_VERBOSE); try { super.execute(); } catch (BuildException bex) { throw new BuildException("Problem attempting to build target "+thetarget+" in "+filename, bex); } } } public void addFileSet(FileSet fs){ filesets.add(fs); } public void setTarget(String thetarget) { super.setTarget(thetarget); this.thetarget = thetarget; } } -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
