thread context classloader for the compiler to find its dependencies

This commit is contained in:
Maxim Shafirov
2012-02-09 19:05:29 +04:00
parent bb0cf4f92f
commit 0bbe267a75
@@ -170,12 +170,23 @@ public class JetCompiler implements TranslatingCompiler {
try { try {
Class<?> kompiler = Class.forName("org.jetbrains.jet.cli.KotlinCompiler", true, loader); Class<?> kompiler = Class.forName("org.jetbrains.jet.cli.KotlinCompiler", true, loader);
Method exec = kompiler.getDeclaredMethod("exec", PrintStream.class, String[].class); Method exec = kompiler.getDeclaredMethod("exec", PrintStream.class, String[].class);
Object rc = exec.invoke(null, out, new String[]{"-module", scriptFile.getAbsolutePath(), "-output", path(outputDir)});
if (rc instanceof Integer) { Thread curThread = Thread.currentThread();
return ((Integer) rc).intValue();
ClassLoader previousLoader = curThread.getContextClassLoader();
curThread.setContextClassLoader(loader);
try {
Object rc = exec.invoke(null, out, new String[]{"-module", scriptFile.getAbsolutePath(), "-output", path(outputDir)});
if (rc instanceof Integer) {
return ((Integer) rc).intValue();
}
else {
throw new RuntimeException("Unexpected return: " + rc);
}
} }
else { finally {
throw new RuntimeException("Unexpected return: " + rc); curThread.setContextClassLoader(previousLoader);
} }
} catch (Throwable e) { } catch (Throwable e) {
LOG.error(e); LOG.error(e);