KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > Connector > EEG > EEM > Actions > JavaCompiler


1 /*
2  * JavaCompiler.java
3  *
4  * Created on 2. duben 2002, 23:37
5  */

6
7 package SOFA.Connector.EEG.EEM.Actions;
8
9 import SOFA.Connector.EEG.EEM.ActionException;
10 import SOFA.Connector.EEG.EEM.ActionInterface;
11
12 /**
13  *
14  * @author ghort
15  * @version
16  */

17 public class JavaCompiler implements ActionInterface {
18
19     /** Creates new JavaCompiler */
20    public JavaCompiler(java.util.HashMap JavaDoc props) {
21    }
22
23     public String JavaDoc getName() {
24         return "javac";
25     }
26      
27     public void perform(SOFA.Connector.Property[] params, String JavaDoc sourceDir, String JavaDoc sourcePackage, String JavaDoc destDir, String JavaDoc destPackage) throws ActionException {
28         String JavaDoc source;
29                 String JavaDoc iface;
30         if ((source=SOFA.Connector.Property.findFirst(params,"source"))==null) {
31             throw new ActionException("source param not specified");
32         }
33         if ((iface=SOFA.Connector.Property.findFirst(params,"iface"))==null) {
34             throw new ActionException("iface param not specified");
35         }
36          
37         int ret;
38     String JavaDoc classpath="";
39         try {
40       classpath = SOFA.Util.ConnGenPathInfo.getConnGenClassPath(iface);
41             Runtime JavaDoc runtime=Runtime.getRuntime();
42             Process JavaDoc process=runtime.exec("javac -classpath "+classpath+" "+destDir+"/"+source);
43             ret=process.waitFor();
44         } catch (Exception JavaDoc e) {
45             throw new ActionException("Can't compile java source "+destDir+"/"+source+".",e);
46         }
47         if (ret!=0) {
48             throw new ActionException("Compilation 'javac -classpath "+classpath+" "+destDir+"/"+source+"' returned error ("+ret+").");
49         }
50     }
51      
52 }
53
Popular Tags