1 24 25 package com.rift.coad.lib.thirdparty.ant; 26 27 import java.io.File ; 29 import java.io.ByteArrayOutputStream ; 30 import java.net.URL ; 31 32 33 import org.apache.tools.ant.Project; 35 import org.apache.tools.ant.Target; 36 import org.apache.tools.ant.taskdefs.Javac; 37 import org.apache.tools.ant.types.Path; 38 39 import com.rift.coad.BaseClassLoader; 41 42 48 public class JavaC extends Javac { 49 50 51 public JavaC(File [] classPath, File source, File dest) { 52 project = new Project(); 53 54 project.init(); 55 taskType = "JavaC"; 56 taskName = "JavaC"; 57 Path path = new Path(project); 58 for (int index = 0; index < classPath.length; index++) { 59 path.add(new Path(project,classPath[index].getAbsolutePath())); 60 } 61 if (this.getClass().getClassLoader() instanceof BaseClassLoader) { 62 BaseClassLoader baseClassLoader = 63 (BaseClassLoader)this.getClass().getClassLoader(); 64 URL urls[] = baseClassLoader.getURLs(); 65 for (int index = 0; index < urls.length; index++) { 66 path.add(new Path(project,urls[index].getFile())); 67 } 68 } 69 70 this.setProject(project); 71 this.setClasspath(path); 72 this.setSrcdir(new Path(project,source.getAbsolutePath())); 73 this.setDestdir(dest); 74 } 75 76 81 public void compileClasses() throws AntException { 82 AntListener listener = new AntListener(); 83 project.addBuildListener(listener); 84 try { 85 super.execute(); 86 } catch (Exception ex) { 87 throw new AntException("Failed to compile :" + ex.getMessage() 88 + " [" + listener.getMessage() + "]",ex); 89 } 90 } 91 } 92 | Popular Tags |