1 33 34 package edu.rice.cs.drjava.model.compiler; 35 36 import java.io.File ; 37 import java.util.List ; 38 39 import edu.rice.cs.drjava.DrJava; 40 import edu.rice.cs.util.classloader.StickyClassLoader; 41 import edu.rice.cs.util.Log; 42 import edu.rice.cs.util.swing.Utilities; 43 import edu.rice.cs.drjava.config.OptionConstants; 44 import edu.rice.cs.drjava.config.FileOption; 45 46 49 public class CompilerProxy implements CompilerInterface { 50 51 public static final String VERSION = System.getProperty("java.specification.version"); 52 53 private static final Log _log = new Log("CompilerTest.txt", false); 54 55 56 private CompilerInterface _realCompiler = null; 57 58 private final String _className; 59 private final ClassLoader _newLoader; 60 61 64 private static final String [] _useOldLoader = { 65 "edu.rice.cs.drjava.model.Configuration", 66 "edu.rice.cs.drjava.model.compiler.CompilerInterface", 67 "edu.rice.cs.drjava.model.compiler.CompilerError" 68 }; 69 70 75 76 public CompilerProxy(String className, ClassLoader newLoader) { 77 _className = className; 78 _newLoader = newLoader; 79 _recreateCompiler(); 80 } 81 82 private void _recreateCompiler() { 83 84 _log.log(this + "._recreateCompiler() called"); 85 86 StickyClassLoader loader = new StickyClassLoader(_newLoader, getClass().getClassLoader(), _useOldLoader); 87 88 try { 89 Class <?> c = loader.loadClass(_className); 90 _log.log("Class " + c + " loaded"); 91 _realCompiler = CompilerRegistry.createCompiler(c); 92 93 _log.log("_realCompiler set to " + _realCompiler); 94 95 String compilerClass = _realCompiler.getClass().getName(); 96 _log.log("Compiler created with name " + compilerClass); 97 } 98 catch (Throwable t) { 99 _log.log(this + "._recreateCompiler() threw exception " + t); 100 101 } 102 103 } 104 105 106 118 public List <? extends CompilerError> compile(List <? extends File > files, List <? extends File > classPath, 119 List <? extends File > sourcePath, File destination, 120 List <? extends File > bootClassPath, String sourceVersion, boolean showWarnings) { 121 _recreateCompiler(); 122 _log.log("realCompiler is " + _realCompiler.getClass()); 123 return _realCompiler.compile(files, classPath, sourcePath, destination, bootClassPath, sourceVersion, showWarnings); 124 } 125 126 130 public boolean isAvailable() { 131 _log.log("CompilerProxy.isAvailable() called for " + getClass() + " _realCompiler = " + _realCompiler); 132 if (_realCompiler == null) return false; 133 else return _realCompiler.isAvailable(); 134 } 135 136 137 public String getName() { 138 if (! isAvailable()) return "(unavailable)"; 139 return _realCompiler.getName(); 140 } 141 142 143 public String toString() { return getName(); } 144 145 } 146 147 148 149 | Popular Tags |