diff options
author | Kenny Ballou <kballou@devnulllabs.io> | 2018-11-19 22:59:50 -0700 |
---|---|---|
committer | Kenny Ballou <kballou@devnulllabs.io> | 2018-11-19 22:59:50 -0700 |
commit | ea3e1b949dcbdc09518f17eee0bcf21d41d76896 (patch) | |
tree | 7ec7a7fb4df67815a9b7bb0e4d95d67c4050e2a2 /src/main/java/jp/ac/tsukuba | |
download | openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.gz openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.xz |
OJ (aka OpenJava) modernization/mirroring
Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
Diffstat (limited to 'src/main/java/jp/ac/tsukuba')
4 files changed, 198 insertions, 0 deletions
diff --git a/src/main/java/jp/ac/tsukuba/openjava/NullCompiler.java b/src/main/java/jp/ac/tsukuba/openjava/NullCompiler.java new file mode 100644 index 0000000..8a1f179 --- /dev/null +++ b/src/main/java/jp/ac/tsukuba/openjava/NullCompiler.java @@ -0,0 +1,24 @@ +/* + * NullCompiler.java + * + * Oct 10, 2000 Michiaki Tatsubori + */ +package jp.ac.tsukuba.openjava; + +import io.devnulllabs.openjava.ojc.JavaCompiler; + +/** + * The class <code>NullCompiler</code> does nothing. + * <p> + */ +public class NullCompiler implements JavaCompiler { + public NullCompiler() { + } + + public static void main(String[] args) { + } + + public void compile(String[] args) { + } + +} diff --git a/src/main/java/jp/ac/tsukuba/openjava/OldJavaCompiler.java b/src/main/java/jp/ac/tsukuba/openjava/OldJavaCompiler.java new file mode 100644 index 0000000..df890c3 --- /dev/null +++ b/src/main/java/jp/ac/tsukuba/openjava/OldJavaCompiler.java @@ -0,0 +1,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(); + } + +} diff --git a/src/main/java/jp/ac/tsukuba/openjava/SunJavaCompiler.java b/src/main/java/jp/ac/tsukuba/openjava/SunJavaCompiler.java new file mode 100644 index 0000000..ef9ba90 --- /dev/null +++ b/src/main/java/jp/ac/tsukuba/openjava/SunJavaCompiler.java @@ -0,0 +1,71 @@ +/* + * SunJavaCompiler.java + * Workaround for Runtime.exec() environment handling incompatibility.. + * + * A work based on jp.ac.tsukuba.openjava.SunJavaCompiler + * + * Apr 16, 1999 Michiaki Tatsubori (mt@is.tsukuba.ac.jp) + * Oct 1, 1999 Shiro Kawai (shiro@squareusa.com) + * Nov 22, 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>SunJavaCompiler</code> is an adapter for Sun's javac. + * + * Message-Id: 19990930154627G.shiro@squareusa.com + * <p> + * I tried OpenJava1.0a1 on my IRIX box w/ SGI's JDK1.2 + * and had a problem to run ojc. Somehow, Runtime.exec() + * didn't pass all the environment variables to the invoked + * process (more specifically, it only passed TZ). + * Consequently the CLASSPATH env was not passed to javac kicked + * by JP.ac.tsukuba.openjava.SunJavaCompiler.complie(), which + * prevented ojc from finishing compilation. + * <p> + * So far I couldn't find exact specification about how the + * environment variables should be treated in Java specification + * and API documents. I guess it may depend on platforms. + * <p> + * We avoided the problem by explicitly passing CLASSPATH to + * the subprocess my modifying SunJavaCompiler class, but wondering + * if there'd be a better way to handle it... + */ +public class SunJavaCompiler implements JavaCompiler { + public static void main(String[] args) { + new SunJavaCompiler().compile(args); + } + + public void compile(String[] args) { + Runtime runtime = Runtime.getRuntime(); + try { + String classpath = + "CLASSPATH=" + System.getProperty("java.class.path"); + String[] envp = new String[1]; + envp[0] = classpath; + Process p = runtime.exec("javac " + strs2str(args), envp); + 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(); + } + +} diff --git a/src/main/java/jp/ac/tsukuba/openjava/SunLibCompiler.java b/src/main/java/jp/ac/tsukuba/openjava/SunLibCompiler.java new file mode 100644 index 0000000..f36454e --- /dev/null +++ b/src/main/java/jp/ac/tsukuba/openjava/SunLibCompiler.java @@ -0,0 +1,57 @@ +/* + * SunLibCompiler.java + * + * Apr 16, 1999 Michiaki Tatsubori + */ +package jp.ac.tsukuba.openjava; + +import java.io.OutputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import io.devnulllabs.openjava.ojc.JavaCompiler; + +/** + * The class <code>SunLibCompiler</code> is an adapter for the compiler + * which invokes Sun's library javac. + * <p> + * The class path must includes lib/tools.jar in the jdk package. + * + * @since jdk1.2 + */ +public class SunLibCompiler implements JavaCompiler { + Object sunJavac; + //sun.tools.javac.Main m; + Method compileMethod; + + public SunLibCompiler() { + //m = new sun.tools.javac.Main(System.err, "javac"); + try { + Class clazz = Class.forName("sun.tools.javac.Main"); + Constructor cons = + clazz.getConstructor( + new Class[] { OutputStream.class, String.class }); + sunJavac = cons.newInstance(new Object[] { System.err, "javac" }); + compileMethod = + clazz.getMethod("compile", new Class[] { String[].class }); + } catch (Exception ex) { + throw new RuntimeException(ex.toString()); + } + + } + + public static void main(String[] args) { + new SunLibCompiler().compile(args); + } + + public void compile(String[] args) { + //sun.tools.javac.Main.main( args ); + //m.compile(args); + try { + compileMethod.invoke(sunJavac, new Object[] { args }); + } catch (Exception ex) { + throw new RuntimeException(ex.toString()); + } + } + +} |