1 18 package org.apache.tools.ant.taskdefs.optional.ejb; 19 20 import java.io.File ; 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.DirectoryScanner; 23 import org.apache.tools.ant.taskdefs.Java; 24 import org.apache.tools.ant.taskdefs.MatchingTask; 25 import org.apache.tools.ant.types.Commandline; 26 import org.apache.tools.ant.types.Path; 27 import org.apache.tools.ant.util.FileUtils; 28 29 36 public class DDCreator extends MatchingTask { 37 42 private File descriptorDirectory; 43 44 47 private File generatedFilesDirectory; 48 49 54 private String classpath; 55 56 67 public void execute() throws BuildException { 68 if (descriptorDirectory == null 69 || !descriptorDirectory.isDirectory()) { 70 throw new BuildException("descriptors directory " 71 + descriptorDirectory.getPath() + " is not valid"); 72 } 73 if (generatedFilesDirectory == null 74 || !generatedFilesDirectory.isDirectory()) { 75 throw new BuildException("dest directory " 76 + generatedFilesDirectory.getPath() + " is not valid"); 77 } 78 79 String args = descriptorDirectory + " " + generatedFilesDirectory; 80 81 DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory); 83 84 String [] files = ds.getIncludedFiles(); 85 86 for (int i = 0; i < files.length; ++i) { 87 args += " " + files[i]; 88 } 89 90 String systemClassPath = System.getProperty("java.class.path"); 91 String execClassPath = FileUtils.translatePath(systemClassPath + ":" + classpath); 92 Java ddCreatorTask = new Java(this); 93 ddCreatorTask.setFork(true); 94 ddCreatorTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.DDCreatorHelper"); 95 Commandline.Argument arguments = ddCreatorTask.createArg(); 96 arguments.setLine(args); 97 ddCreatorTask.setClasspath(new Path(getProject(), execClassPath)); 98 if (ddCreatorTask.executeJava() != 0) { 99 throw new BuildException("Execution of ddcreator helper failed"); 100 } 101 } 102 103 109 public void setDescriptors(String dirName) { 110 descriptorDirectory = new File (dirName); 111 } 112 113 120 public void setDest(String dirName) { 121 generatedFilesDirectory = new File (dirName); 122 } 123 124 129 public void setClasspath(String s) { 130 this.classpath = FileUtils.translatePath(s); 131 } 132 } 133 | Popular Tags |