summaryrefslogtreecommitdiff
path: root/src/main/java/jp/ac/tsukuba/openjava/OldJavaCompiler.java
blob: df890c3e1655c7bef1dcb2216c4fa939da693fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * OldJavaCompiler.java
 *
 * Apr 16, 1999  Michiaki Tatsubori
 */
package jp.ac.tsukuba.openjava;

import java.io.BufferedInputStream;
import java.io.InputStream;

import io.devnulllabs.openjava.ojc.JavaCompiler;

/**
 * The class <code>OldJavaCompiler</code> is an adapter for Sun's javac.
 *
 */
public class OldJavaCompiler implements JavaCompiler {
    public static void main(String[] args) {
        new OldJavaCompiler().compile(args);
    }

    public void compile(String[] args) {
        /*sun.tools.javac.Main.main( args );*/
        Runtime runtime = Runtime.getRuntime();
        try {
            Process p = runtime.exec("javac " + strs2str(args));
            InputStream in = new BufferedInputStream(p.getErrorStream());
            byte[] buf = new byte[1024];
            for (int len = in.read(buf); len != -1; len = in.read(buf)) {
                System.err.write(buf, 0, len);
            }
            p.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static String strs2str(String[] strs) {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < strs.length; ++i) {
            buf.append(strs[i]).append(" ");
        }
        return buf.toString();
    }

}