mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-03 19:57:36 +08:00
class loader priority - dynamic loader has higher priority than static one
#PL-1977
This commit is contained in:
parent
b517ac64bb
commit
54ce1be3da
@ -27,6 +27,7 @@ import javax.tools.DiagnosticCollector;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.*;
|
||||
@ -90,14 +91,10 @@ public class JavaClassLoader extends URLClassLoader {
|
||||
Log4JStopWatch loadingWatch = new Log4JStopWatch("LoadClass");
|
||||
try {
|
||||
lock(className);
|
||||
Class clazz = null;
|
||||
try {
|
||||
clazz = super.loadClass(className, resolve);
|
||||
} catch (ClassNotFoundException e) {
|
||||
//
|
||||
}
|
||||
Class clazz;
|
||||
|
||||
if (clazz != null) {
|
||||
if (!sourceProvider.getSourceFile(className).exists()) {
|
||||
clazz = super.loadClass(className);
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@ -144,6 +141,30 @@ public class JavaClassLoader extends URLClassLoader {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL findResource(String name) {
|
||||
if (name.startsWith("/"))
|
||||
name = name.substring(1);
|
||||
File file = new File(rootDir, name);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
return file.toURI().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getResource(String name) {
|
||||
URL resource = findResource(name);
|
||||
if (resource != null)
|
||||
return resource;
|
||||
else
|
||||
return super.getResource(name);
|
||||
}
|
||||
|
||||
protected Date getCurrentTimestamp() {
|
||||
return timeSource.currentTimestamp();
|
||||
}
|
||||
|
@ -25,16 +25,12 @@ class ProxyClassLoader extends ClassLoader {
|
||||
|
||||
@Override
|
||||
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
||||
try {
|
||||
return super.loadClass(name, resolve);
|
||||
} catch (ClassNotFoundException e) {
|
||||
//do nothing
|
||||
}
|
||||
TimestampClass tsClass = compiled.get(name);
|
||||
if (tsClass != null) {
|
||||
return tsClass.clazz;
|
||||
} else {
|
||||
return super.loadClass(name, resolve);
|
||||
}
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
|
||||
public TimestampClass removeFromCache(String className) {
|
||||
@ -62,7 +58,7 @@ class ProxyClassLoader extends ClassLoader {
|
||||
removedFromCompilation.remove();
|
||||
}
|
||||
|
||||
public void cleanupRemoved(){
|
||||
public void cleanupRemoved() {
|
||||
removedFromCompilation.remove();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user