From a764e59e1d3a8e330f0d484fdb26b35ca3f0b2e4 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 22 Mar 2008 02:15:12 +0000 Subject: bringing pdj-0.8.3 into the main branch svn path=/trunk/externals/loaders/pdj/; revision=9621 --- src/java/com/e1/pdj/GenericCompiler.java | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/java/com/e1/pdj/GenericCompiler.java (limited to 'src/java/com/e1/pdj/GenericCompiler.java') diff --git a/src/java/com/e1/pdj/GenericCompiler.java b/src/java/com/e1/pdj/GenericCompiler.java new file mode 100644 index 0000000..31278b7 --- /dev/null +++ b/src/java/com/e1/pdj/GenericCompiler.java @@ -0,0 +1,71 @@ +package com.e1.pdj; + +import java.io.*; + +import com.cycling74.max.MaxSystem; + +abstract class GenericCompiler { + File javaFile; + String cp[]; + String compilerName; + + static String rtJar; + + GenericCompiler(String name) { + compilerName = name + ": "; + } + + String getConfigurationClassPath() { + return PDJClassLoader.getConfigurationClassPath(); + } + + File resolvJavaFile() { + int base = PDJClassLoader.fclasses.toString().length() + 1; + String className = javaFile.toString().substring(base); + return new File(className); + } + + private int doexec(String arg) throws Exception { + Process p = Runtime.getRuntime().exec(arg, null, PDJClassLoader.fclasses); + + BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); + BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); + String buff; + boolean cont = true; + while(cont) { + cont = false; + + buff = stdout.readLine(); + if ( buff != null ) { + MaxSystem.post(compilerName + buff); + cont = true; + } else { + cont = false; + } + + buff = stderr.readLine(); + if ( buff != null ) { + MaxSystem.post(compilerName + buff); + cont = true; + } else { + cont = cont & false; + } + } + + p.waitFor(); + + return p.exitValue(); + } + + int exec(String arg) throws PDJClassLoaderException { + MaxSystem.post("pdj: trying to compile class: " + resolvJavaFile().toString()); + + try { + return doexec(arg); + } catch (Exception e) { + throw new PDJClassLoaderException(e); + } + } + + abstract void compileClass() throws PDJClassLoaderException; +} -- cgit v1.2.1