mirror of
https://github.com/enso-org/enso.git
synced 2024-09-11 13:15:52 +03:00
Fix Java log initialization in std-table
(#8364)
This commit is contained in:
parent
af5be19be8
commit
a9099ddce5
@ -0,0 +1,24 @@
|
||||
package org.enso;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ClassLoaderConstants {
|
||||
|
||||
/**
|
||||
* Prefix of names of classes that are know to be on the system module-path, i.e., on the boot
|
||||
* module layer. Engine is started from {@link EngineRunnerBootLoader} with a custom class loader
|
||||
* that is isolated form the system's module-path. Delegating to either system class loader, or
|
||||
* any other class loader that has access to the boot module layer, ensures that the Truffle
|
||||
* polyglot environment is properly initialized and also that the global logging configuration is
|
||||
* consistent.
|
||||
*/
|
||||
public static final List<String> CLASS_DELEGATION_PATTERNS =
|
||||
List.of("org.graalvm", "java", "org.slf4j", "ch.qos");
|
||||
|
||||
public static final List<String> RESOURCE_DELEGATION_PATTERNS = List.of("org.slf4j", "ch.qos");
|
||||
/**
|
||||
* Path to the {@code runner.jar} fat jar. This must not be on the system's module-path, because
|
||||
* the JVM would not be able to boot.
|
||||
*/
|
||||
static final String DEFAULT_RUNNER_JAR = "runner/runner.jar";
|
||||
}
|
@ -7,7 +7,6 @@ import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@code runner.jar} is a fat jar containing all the dependencies for engine-runner, however, it
|
||||
@ -23,8 +22,6 @@ public final class EngineRunnerBootLoader {
|
||||
|
||||
private EngineRunnerBootLoader() {}
|
||||
|
||||
private static final String defaultRunnerJar = "runner/runner.jar";
|
||||
|
||||
private static final ClassLoader loader;
|
||||
|
||||
static {
|
||||
@ -53,7 +50,7 @@ public final class EngineRunnerBootLoader {
|
||||
var runtimeJar =
|
||||
EngineRunnerBootLoader.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
try {
|
||||
var runnerJarUri = runtimeJar.toURI().resolve(defaultRunnerJar);
|
||||
var runnerJarUri = runtimeJar.toURI().resolve(ClassLoaderConstants.DEFAULT_RUNNER_JAR);
|
||||
return Path.of(runnerJarUri);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalStateException(e);
|
||||
@ -62,9 +59,6 @@ public final class EngineRunnerBootLoader {
|
||||
|
||||
private static final class IsolatedClassLoader extends URLClassLoader {
|
||||
private final ClassLoader systemClassLoader;
|
||||
private static final List<String> resourceDelegationPatterns = List.of("org.slf4j", "ch.qos");
|
||||
private static final List<String> classDelegationPatterns =
|
||||
List.of("org.graalvm", "java", "org.slf4j", "ch.qos");
|
||||
|
||||
public IsolatedClassLoader(URL runnerJarUrl) {
|
||||
super("org.enso.IsolatedClassLoader", new URL[] {runnerJarUrl}, null);
|
||||
@ -73,7 +67,7 @@ public final class EngineRunnerBootLoader {
|
||||
|
||||
@Override
|
||||
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
||||
if (classDelegationPatterns.stream().anyMatch(name::startsWith)) {
|
||||
if (ClassLoaderConstants.CLASS_DELEGATION_PATTERNS.stream().anyMatch(name::startsWith)) {
|
||||
return systemClassLoader.loadClass(name);
|
||||
} else {
|
||||
return super.loadClass(name);
|
||||
@ -82,7 +76,7 @@ public final class EngineRunnerBootLoader {
|
||||
|
||||
@Override
|
||||
public URL findResource(String name) {
|
||||
if (resourceDelegationPatterns.stream().anyMatch(name::startsWith)) {
|
||||
if (ClassLoaderConstants.RESOURCE_DELEGATION_PATTERNS.stream().anyMatch(name::startsWith)) {
|
||||
return systemClassLoader.getResource(name);
|
||||
} else {
|
||||
return super.findResource(name);
|
||||
@ -91,7 +85,7 @@ public final class EngineRunnerBootLoader {
|
||||
|
||||
@Override
|
||||
public Enumeration<URL> findResources(String name) throws IOException {
|
||||
if (resourceDelegationPatterns.stream().anyMatch(name::startsWith)) {
|
||||
if (ClassLoaderConstants.RESOURCE_DELEGATION_PATTERNS.stream().anyMatch(name::startsWith)) {
|
||||
return systemClassLoader.getResources(name);
|
||||
} else {
|
||||
return super.findResources(name);
|
||||
|
@ -1,9 +1,12 @@
|
||||
package org.enso.interpreter.runtime;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.enso.ClassLoaderConstants;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -47,6 +50,9 @@ public class HostClassLoader extends URLClassLoader {
|
||||
logger.trace("Class {} found in cache", name);
|
||||
return l;
|
||||
}
|
||||
if (ClassLoaderConstants.CLASS_DELEGATION_PATTERNS.stream().anyMatch(name::startsWith)) {
|
||||
return polyglotClassLoader.loadClass(name);
|
||||
}
|
||||
try {
|
||||
l = findClass(name);
|
||||
if (resolve) {
|
||||
@ -60,4 +66,22 @@ public class HostClassLoader extends URLClassLoader {
|
||||
return super.loadClass(name, resolve);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL findResource(String name) {
|
||||
if (ClassLoaderConstants.RESOURCE_DELEGATION_PATTERNS.stream().anyMatch(name::startsWith)) {
|
||||
return polyglotClassLoader.getResource(name);
|
||||
} else {
|
||||
return super.findResource(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<URL> findResources(String name) throws IOException {
|
||||
if (ClassLoaderConstants.RESOURCE_DELEGATION_PATTERNS.stream().anyMatch(name::startsWith)) {
|
||||
return polyglotClassLoader.getResources(name);
|
||||
} else {
|
||||
return super.findResources(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user