1 18 package org.objectweb.speedo.generation.recompiler; 19 20 import org.apache.tools.ant.Project; 21 import org.apache.tools.ant.taskdefs.Javac; 22 import org.apache.tools.ant.types.Path; 23 import org.apache.tools.ant.types.PatternSet.NameEntry; 24 import org.objectweb.speedo.api.SpeedoException; 25 import org.objectweb.speedo.generation.api.SpeedoCompilerParameter; 26 import org.objectweb.speedo.generation.mivisitor.MetaInfoVisitorImpl; 27 import org.objectweb.speedo.metadata.SpeedoClass; 28 import org.objectweb.speedo.tools.StringReplace; 29 import org.objectweb.util.monolog.api.BasicLevel; 30 31 import java.io.File ; 32 33 37 public class Recompiler extends MetaInfoVisitorImpl { 38 39 42 protected Javac compiler; 43 44 protected String getLoggerName() { 45 return super.getLoggerName() + ".recompiler"; 46 } 47 48 public void visitCompilerParameter(SpeedoCompilerParameter scp) throws SpeedoException { 49 compiler = scp.javac; 50 if (compiler == null) { 51 compiler = new Javac(); 52 Project project = new Project(); 53 project.init(); 54 compiler.setProject(project); 55 } 56 compiler.setDestdir(new File (scp.output)); 57 compiler.setVerbose(debug); 58 compiler.setDebug(true); 59 compiler.setTaskName("speedo"); 60 compiler.setClasspath(scp.classpath); 62 compiler.setClasspath(scp.speedoclasspath); 63 Path srcCompiler = new Path(compiler.getProject()); 64 srcCompiler.createPathElement().setLocation(new File (scp.input)); 65 compiler.setSrcdir(srcCompiler); 66 super.visitCompilerParameter(scp); 68 logger.log(BasicLevel.INFO, "Recompilation"); 69 compiler.execute(); 70 } 71 72 public void visitClass(SpeedoClass sc) throws SpeedoException { 73 super.visitClass(sc); 74 if (sc.jdoPackage.jdoXMLDescriptor.requireEnhancement) { 75 String name = sc.getFQName(); 76 name = StringReplace.replaceChar('.', '/', name); 77 name += ".java"; 78 if (debug) { 79 logger.log(BasicLevel.DEBUG, "Class '" + sc.getFQName() 80 + "' is going to be recompile (file name= " + name +")"); 81 } 82 NameEntry ne = compiler.createInclude(); 83 ne.setName(name); 84 } 85 } 86 } 87 | Popular Tags |