01: /**
02: * Copyright (C) 2001-2004 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package org.objectweb.speedo.generation.recompiler;
18:
19: import org.apache.tools.ant.Project;
20: import org.apache.tools.ant.taskdefs.Javac;
21: import org.apache.tools.ant.types.Path;
22: import org.apache.tools.ant.types.PatternSet.NameEntry;
23: import org.objectweb.speedo.api.SpeedoException;
24: import org.objectweb.speedo.generation.api.SpeedoCompilerParameter;
25: import org.objectweb.speedo.generation.mivisitor.MetaInfoVisitorImpl;
26: import org.objectweb.speedo.lib.Personality;
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: /**
34: *
35: * @author S.Chassande-Barrioz
36: */
37: public class Recompiler extends MetaInfoVisitorImpl {
38: /**
39: * Ant Task intended to java compilation
40: */
41: protected Javac compiler;
42:
43: public Recompiler(Personality p) {
44: super (p);
45: }
46:
47: protected String getLoggerName() {
48: return super .getLoggerName() + ".recompiler";
49: }
50:
51: public String getTitle() {
52: return "Recompiling classes ...";
53: }
54:
55: public void visitCompilerParameter(SpeedoCompilerParameter scp)
56: throws SpeedoException {
57: compiler = scp.javac;
58: if (compiler == null) {
59: compiler = new Javac();
60: Project project = new Project();
61: project.init();
62: compiler.setProject(project);
63: }
64: compiler.setDestdir(new File(scp.output));
65: compiler.setVerbose(debug);
66: compiler.setDebug(true);
67: compiler.setTaskName("speedo");
68: //compiler.setDebugLevel("-g:lines,vars,source");
69: compiler.setClasspath(scp.classpath);
70: compiler.setClasspath(scp.speedoclasspath);
71: Path srcCompiler = new Path(compiler.getProject());
72: srcCompiler.createPathElement()
73: .setLocation(new File(scp.input));
74: compiler.setSrcdir(srcCompiler);
75: //Let the visitClass method fill with include
76: super .visitCompilerParameter(scp);
77: logger.log(BasicLevel.INFO, "Recompilation");
78: compiler.execute();
79: }
80:
81: public void visitClass(SpeedoClass sc) throws SpeedoException {
82: super .visitClass(sc);
83: if (sc.moPackage.xmlDescriptor.requireEnhancement) {
84: String name = sc.getFQName();
85: name = StringReplace.replaceChar('.', '/', name);
86: name += ".java";
87: if (debug) {
88: logger.log(BasicLevel.DEBUG, "Class '" + sc.getFQName()
89: + "' is going to be recompile (file name= "
90: + name + ")");
91: }
92: NameEntry ne = compiler.createInclude();
93: ne.setName(name);
94: }
95: }
96: }
|