KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > generation > recompiler > Recompiler


1 /**
2  * Copyright (C) 2001-2004 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * 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  */

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 JavaDoc;
32
33 /**
34  *
35  * @author S.Chassande-Barrioz
36  */

37 public class Recompiler extends MetaInfoVisitorImpl {
38
39     /**
40      * Ant Task intended to java compilation
41      */

42     protected Javac compiler;
43
44     protected String JavaDoc 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 JavaDoc(scp.output));
57         compiler.setVerbose(debug);
58         compiler.setDebug(true);
59         compiler.setTaskName("speedo");
60         //compiler.setDebugLevel("-g:lines,vars,source");
61
compiler.setClasspath(scp.classpath);
62         compiler.setClasspath(scp.speedoclasspath);
63         Path srcCompiler = new Path(compiler.getProject());
64         srcCompiler.createPathElement().setLocation(new File JavaDoc(scp.input));
65         compiler.setSrcdir(srcCompiler);
66         //Let the visitClass method fill with include
67
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 JavaDoc 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