1 29 30 package com.caucho.loader; 31 32 import com.caucho.java.CompileClassNotFound; 33 import com.caucho.log.Log; 34 import com.caucho.server.util.CauchoSystem; 35 import com.caucho.util.L10N; 36 import com.caucho.util.ThreadPool; 37 import com.caucho.vfs.Path; 38 39 import java.io.IOException ; 40 import java.security.CodeSource ; 41 import java.util.logging.Logger ; 42 43 class CompilingClassEntry extends ClassEntry { 44 private static final L10N L = new L10N(CompilingClassEntry.class); 45 private static final Logger log = Log.open(CompilingClassEntry.class); 46 47 private CompilingLoader _loader; 48 private boolean _compileIsModified; 49 50 public CompilingClassEntry(CompilingLoader compilingLoader, 51 DynamicClassLoader loader, 52 String name, Path sourcePath, 53 Path classPath, 54 CodeSource codeSource) 55 { 56 super(loader, name, sourcePath, classPath, codeSource); 57 58 _loader = compilingLoader; 59 } 60 61 public void preLoad() 62 throws ClassNotFoundException 63 { 64 String javaName = getName().replace('.', '/') + ".java"; 65 66 Path javaFile = getSourcePath(); 67 Path classFile = getClassPath(); 68 69 if (javaFile.getLastModified() <= classFile.getLastModified()) { 70 log.fine(L.l("loading pre-compiled class {0} from {1}", 71 getName(), classFile)); 72 return; 73 } 74 75 if (! javaFile.canRead()) 76 return; 77 78 try { 79 classFile.remove(); 80 } catch (IOException e) { 81 } 82 83 String sourcePath = _loader.prefixClassPath(_loader.getLoader().getSourcePath()); 84 85 if (CauchoSystem.isWindows() && 87 ! _loader.checkSource(_loader.getSource(), javaName)) 88 return; 89 90 _loader.compileClass(javaFile, classFile, sourcePath, false); 91 92 if (classFile.canRead()) { 93 log.fine(L.l("loading compiled class {0} from {1}", 94 getName(), classFile)); 95 } 96 else if (javaFile.exists()) 97 throw new CompileClassNotFound(L.l("compiling {0} didn't produce a {1}. class", 98 javaFile, getName())); 99 100 setDependPath(classFile); 101 } 102 103 106 public boolean compileIsModified() 107 { 108 if (_compileIsModified) 109 return true; 110 111 CompileThread compileThread = new CompileThread(); 112 ThreadPool.getThreadPool().start(compileThread); 113 114 try { 115 synchronized (compileThread) { 116 if (! compileThread.isDone()) 117 compileThread.wait(5000); 118 } 119 120 if (_compileIsModified) 121 return true; 122 else if (compileThread.isDone()) { 123 setDependPath(getClassPath()); 124 125 return reloadIsModified(); 126 } 127 else 128 return true; 129 } catch (Throwable e) { 130 } 131 132 return false; 133 } 134 135 class CompileThread implements Runnable { 136 private volatile boolean _isDone; 137 138 public boolean isDone() 139 { 140 return _isDone; 141 } 142 public void run() { 143 Path sourcePath = getSourcePath(); 144 145 long length = sourcePath.getLength(); 146 long lastModified = sourcePath.getLastModified(); 147 148 try { 149 _loader.compileClass(getSourcePath(), getClassPath(), 150 getSourcePath().getPath(), false); 151 152 setSourceLength(length); 153 setSourceLastModified(lastModified); 154 } catch (Throwable e) { 155 _compileIsModified = true; 156 } 157 158 _isDone = true; 159 160 synchronized (this) { 161 notifyAll(); 162 } 163 } 164 } 165 166 public String toString() 167 { 168 return "CompilingClassEntry[" + getClassPath() + ", SRC=" + getSourcePath() + "]"; 169 } 170 171 } 172 | Popular Tags |