import org.apache.tools.ant.*; import org.apache.tools.ant.taskdefs.*; import atg.beanmaker.*; import java.io.*; import org.apache.tools.ant.types.*; public class BeanMaker extends MatchingTask { private File dir; public void setDir(File dir) { this.dir = dir; } public File getDir(){ return dir; } public void execute() throws BuildException { if (dir != null) { String sep = System.getProperty("file.separator"); DirectoryScanner ds = super.getDirectoryScanner(dir); String [] files = ds.getIncludedFiles(); String destDir; Commandline command; int index; System.out.println(" [make beans] Creating " + files.length + " beans in directory " + dir); System.out.print(" "); for( int i=0;i<files.length;i++){ index = files[i].lastIndexOf( sep ); if (index >= 0){ destDir = files[i].substring(0, index ); } else { destDir = "."; } try{ System.out.print('.'); command = new Commandline( "java atg.beanmaker.BeanMaker -d " + destDir + " " + files[i]); run( command.getCommandline() ); } catch (Exception e) { throw( new BuildException( e.getMessage() ) ); } } System.out.println(); } } /** * Executes the given classname with the given arguments in a separate VM. */ private int run(String[] command) throws BuildException { Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN), null); exe.setAntRun(project); if (dir == null) { dir = project.getBaseDir(); } else if (!dir.exists() || !dir.isDirectory()) { throw new BuildException(dir.getAbsolutePath()+" is not a valid directory", location); } exe.setWorkingDirectory(dir); exe.setCommandline(command); try { return exe.execute(); } catch (IOException e) { throw new BuildException(e, location); } } }