thread context classloader for the compiler to find its dependencies
This commit is contained in:
@@ -76,8 +76,8 @@ public class JetCompiler implements TranslatingCompiler {
|
|||||||
compileContext.addMessage(ERROR, "Cannot find kotlinc home. Make sure plugin is properly installed", "", -1, -1);
|
compileContext.addMessage(ERROR, "Cannot find kotlinc home. Make sure plugin is properly installed", "", -1, -1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StringBuilder script = new StringBuilder();
|
StringBuilder script = new StringBuilder();
|
||||||
|
|
||||||
script.append("import kotlin.modules.*\n");
|
script.append("import kotlin.modules.*\n");
|
||||||
@@ -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);
|
||||||
@@ -316,7 +327,7 @@ public class JetCompiler implements TranslatingCompiler {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String path(VirtualFile root) {
|
private static String path(VirtualFile root) {
|
||||||
String path = root.getPath();
|
String path = root.getPath();
|
||||||
if (path.endsWith("!/")) {
|
if (path.endsWith("!/")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user