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 35 public class Ejbc extends MatchingTask { 36 41 private File descriptorDirectory; 42 43 46 private File generatedFilesDirectory; 47 48 51 private File generatedManifestFile; 52 53 57 private String classpath; 58 59 63 private File sourceDirectory; 64 65 67 public boolean keepgenerated; 68 70 81 public void execute() throws BuildException { 82 if (descriptorDirectory == null 83 || !descriptorDirectory.isDirectory()) { 84 throw new BuildException("descriptors directory " 85 + descriptorDirectory.getPath() + " is not valid"); 86 } 87 if (generatedFilesDirectory == null 88 || !generatedFilesDirectory.isDirectory()) { 89 throw new BuildException("dest directory " 90 + generatedFilesDirectory.getPath() + " is not valid"); 91 } 92 93 if (sourceDirectory == null 94 || !sourceDirectory.isDirectory()) { 95 throw new BuildException("src directory " 96 + sourceDirectory.getPath() + " is not valid"); 97 } 98 99 String systemClassPath = System.getProperty("java.class.path"); 100 String execClassPath 101 = FileUtils.translatePath(systemClassPath + ":" + classpath 102 + ":" + generatedFilesDirectory); 103 DirectoryScanner ds = super.getDirectoryScanner(descriptorDirectory); 105 106 String [] files = ds.getIncludedFiles(); 107 108 Java helperTask = new Java(this); 109 helperTask.setFork(true); 110 helperTask.setClassname("org.apache.tools.ant.taskdefs.optional.ejb.EjbcHelper"); 111 String args = ""; 112 args += " " + descriptorDirectory; 113 args += " " + generatedFilesDirectory; 114 args += " " + sourceDirectory; 115 args += " " + generatedManifestFile; 116 args += " " + keepgenerated; 117 118 for (int i = 0; i < files.length; ++i) { 119 args += " " + files[i]; 120 } 121 122 Commandline.Argument arguments = helperTask.createArg(); 123 arguments.setLine(args); 124 helperTask.setClasspath(new Path(getProject(), execClassPath)); 125 if (helperTask.executeJava() != 0) { 126 throw new BuildException("Execution of ejbc helper failed"); 127 } 128 } 129 130 134 public boolean getKeepgenerated() { 135 return keepgenerated; 136 } 137 138 144 public void setDescriptors(String dirName) { 145 descriptorDirectory = new File (dirName); 146 } 147 148 153 public void setDest(String dirName) { 154 generatedFilesDirectory = new File (dirName); 155 } 156 157 163 public void setKeepgenerated(String newKeepgenerated) { 164 keepgenerated = Boolean.valueOf(newKeepgenerated.trim()).booleanValue(); 165 166 } 167 168 176 public void setManifest(String manifestFilename) { 177 generatedManifestFile = new File (manifestFilename); 178 } 179 180 184 public void setClasspath(String s) { 185 this.classpath = FileUtils.translatePath(s); 186 } 187 188 194 public void setSrc(String dirName) { 195 sourceDirectory = new File (dirName); 196 } 197 } 198 | Popular Tags |