1 package spoon; 2 3 import java.io.File ; 4 import java.util.ArrayList ; 5 import java.util.List ; 6 import java.util.Vector ; 7 8 import org.apache.tools.ant.BuildException; 9 import org.apache.tools.ant.DirectoryScanner; 10 import org.apache.tools.ant.taskdefs.Java; 11 import org.apache.tools.ant.types.FileSet; 12 13 17 public class SpoonTask extends Java { 18 19 22 public static class ProcessorType { 23 String type; 24 25 28 public ProcessorType() { 29 } 30 31 37 public ProcessorType(String type) { 38 setType(type); 39 } 40 41 44 public String getType() { 45 return type; 46 } 47 48 52 public void setType(String type) { 53 this.type = type; 54 } 55 } 56 57 String classname; 58 59 boolean compile = false; 60 61 File input; 62 63 int javaCompliance = 5; 64 65 boolean nooutput = false; 66 67 File output; 68 69 File build; 70 71 File spoonlet; 72 73 Vector <FileSet> spoonletfileset = new Vector <FileSet>(); 74 75 List <ProcessorType> processorTypes = new ArrayList <ProcessorType>(); 76 77 File properties; 78 79 Vector <FileSet> sourcefilesets = new Vector <FileSet>(); 80 81 boolean stats = false; 82 83 File template; 84 85 Vector <FileSet> templatefilesets = new Vector <FileSet>(); 86 87 boolean verbose = false; 88 89 92 public SpoonTask() { 93 setClassname("spoon.Launcher"); 94 } 95 96 100 public void addProcessor(ProcessorType processorType) { 101 this.processorTypes.add(processorType); 102 } 103 104 107 public void addSourceSet(FileSet set) { 108 sourcefilesets.addElement(set); 109 } 110 111 114 public void addTemplateSet(FileSet set) { 115 templatefilesets.addElement(set); 116 } 117 118 121 @Override 122 public void execute() throws BuildException { 123 124 setFork(true); 125 126 if (verbose) 128 createArg().setValue("-v"); 129 130 if (nooutput) { 131 createArg().setValue("--no"); 132 } else { 133 if (compile) { 134 createArg().setValue("--compile"); 135 136 createArg().setValue("--build"); 137 138 createArg().setFile(build); 139 140 } 141 } 142 143 createArg().setValue("--compliance"); 144 createArg().setValue("" + javaCompliance); 145 146 if (spoonlet != null || spoonletfileset.size() > 0) { 148 createArg().setValue("-s"); 149 String f = ""; 150 if (spoonlet != null) { 151 f += spoonlet.getAbsolutePath() + File.pathSeparator; 152 } 153 for (int i = 0; i < spoonletfileset.size(); i++) { 154 FileSet fs = (FileSet) spoonletfileset.elementAt(i); 155 DirectoryScanner ds = fs.getDirectoryScanner(getProject()); 156 File dir = fs.getDir(getProject()); 157 String [] srcs = ds.getIncludedFiles(); 158 for (int j = 0; j < srcs.length; j++) { 159 f += dir.getAbsolutePath() + File.separatorChar + srcs[j] 160 + File.pathSeparator; 161 } 162 } 163 createArg().setValue(f); 164 } 165 166 if (output != null) { 168 if (output.exists() && !output.isDirectory()) 169 throw new BuildException("Output must be a directory"); 170 createArg().setValue("-o"); 171 createArg().setValue(output.getAbsolutePath()); 172 } 173 if (input != null || sourcefilesets.size() > 0) { 175 createArg().setValue("-i"); 176 String f = ""; 177 if (input != null) { 178 f += input.getAbsolutePath() + File.pathSeparator; 179 } 180 for (int i = 0; i < sourcefilesets.size(); i++) { 181 FileSet fs = (FileSet) sourcefilesets.elementAt(i); 182 DirectoryScanner ds = fs.getDirectoryScanner(getProject()); 183 File dir = fs.getDir(getProject()); 184 String [] srcs = ds.getIncludedFiles(); 185 for (int j = 0; j < srcs.length; j++) { 186 f += dir.getAbsolutePath() + File.separatorChar + srcs[j] 187 + File.pathSeparator; 188 } 189 } 190 createArg().setValue(f); 191 } 192 193 if (template != null || templatefilesets.size() > 0) { 195 createArg().setValue("-t"); 196 String f = ""; 197 if (template != null) { 198 f += template.getAbsolutePath() + File.pathSeparator; 199 } 200 for (int i = 0; i < templatefilesets.size(); i++) { 201 FileSet fs = (FileSet) templatefilesets.elementAt(i); 202 DirectoryScanner ds = fs.getDirectoryScanner(getProject()); 203 File dir = fs.getDir(getProject()); 204 String [] srcs = ds.getIncludedFiles(); 205 for (int j = 0; j < srcs.length; j++) { 206 f += dir.getAbsolutePath() + File.separatorChar + srcs[j] 207 + File.pathSeparator; 208 } 209 } 210 createArg().setValue(f); 211 } 212 213 if (properties != null) { 215 createArg().setValue("--properties"); 216 createArg().setValue(properties.getAbsolutePath()); 217 } 218 219 if (processorTypes != null && processorTypes.size() > 0) { 221 createArg().setValue("-p"); 222 String process = ""; 223 for (ProcessorType t : processorTypes) 224 process += t.type + File.pathSeparator; 225 createArg().setValue(process); 226 } 227 228 if (classname != null) 229 createArg().setValue(classname); 230 231 super.execute(); 232 233 } 234 235 238 public void setClassName(String classname) { 239 this.classname = classname; 240 } 241 242 245 public void setCompile(boolean compile) { 246 this.compile = compile; 247 } 248 249 253 public void setInput(File input) { 254 this.input = input; 255 } 256 257 261 public void setSpoonlet(File spoonlet) { 262 this.spoonlet = spoonlet; 263 } 264 265 268 public void setJavaCompliance(int javaCompliance) { 269 this.javaCompliance = javaCompliance; 270 } 271 272 275 public void setNoOutput(boolean nooutput) { 276 this.nooutput = nooutput; 277 } 278 279 282 public void setOutput(File output) { 283 this.output = output; 284 } 285 286 289 public void setBuild(File build) { 290 this.build = build; 291 } 292 293 297 public void setProperties(File properties) { 298 this.properties = properties; 299 } 300 301 304 public void setStats(boolean stats) { 305 this.stats = stats; 306 } 307 308 312 public void setTemplate(File template) { 313 this.template = template; 314 } 315 316 319 public void setVerbose(boolean verbose) { 320 this.verbose = verbose; 321 } 322 323 } 324 | Popular Tags |