1 16 19 20 package com.sun.org.apache.xml.internal.utils.synthetic; 21 22 import java.io.IOException ; 23 24 38 public class JavaUtils 39 { 40 private static boolean cantLoadCompiler=false; 42 43 private static boolean debug = false; 45 46 60 public static void setDebug(boolean newDebug) 61 { 62 debug=newDebug; 63 } 64 65 101 public static boolean JDKcompile(String fileName, String classPath) 102 { 103 String moreClassPath= 104 System.getProperty("com.sun.org.apache.xml.internal.utils.synthetic.moreclasspath","") 105 .trim(); 106 if(moreClassPath.length()>0) 107 classPath=moreClassPath+';'+classPath; 108 109 if (debug) 110 { 111 System.err.println ("JavaEngine: Compiling " + fileName); 112 System.err.println ("JavaEngine: Classpath is " + classPath); 113 } 114 115 String code_option = debug ? "-g" : "-O"; 116 117 if(!cantLoadCompiler) 119 { 120 String args[] = { 121 code_option, 122 "-classpath", classPath, 123 fileName 124 }; 125 126 } 137 138 String javac_command= 142 System.getProperty("com.sun.org.apache.xml.internal.utils.synthetic.javac","javac"); 143 String args[] = { 144 javac_command, 145 code_option, 146 "-classpath", classPath, 147 fileName 148 }; 149 try 150 { 151 Process p=java.lang.Runtime.getRuntime().exec(args); 152 int compileOK=waitHardFor(p); return compileOK==0; } 155 catch(IOException e) 156 { 157 System.err.println("ERROR: IO exception during exec(javac)."); 158 } 159 catch(SecurityException e) 160 { 161 System.err.println("ERROR: Unable to create subprocess to exec(javac)."); 162 } 163 164 return false; 166 } 167 168 174 static int waitHardFor(java.lang.Process p) 175 { 176 boolean done=false; 177 while(!done) 178 try 179 { 180 p.waitFor(); 181 done=true; 182 } 183 catch(InterruptedException e) 184 { 185 System.err.println("(Compiler process wait interrupted and resumed)"); 186 } 187 int ev=p.exitValue(); return ev; 189 } 190 191 } 192 | Popular Tags |