@Override public void runPlugin(String pathToPluginFolder, final String pluginId,
Map<String, ?> binding, Function<Runnable, Void> runOnEDTCallback) {
final File scriptFile = MyFileUtil.findSingleFileIn(pathToPluginFolder, ScalaPluginRunner.MAIN_SCRIPT);
assert scriptFile != null;
final IMain interpreter;
synchronized (interpreterLock) {
try {
environment.put("PLUGIN_PATH", pathToPluginFolder);
List<String> additionalPaths = findClasspathAdditions(readLines(asUrl(scriptFile)), SCALA_ADD_TO_CLASSPATH_KEYWORD, environment, new Function<String, Void>() {
@Override public Void fun(String path) {
errorReporter.addLoadingError(pluginId, "Couldn't find dependency '" + path + "'");
return null;
}
});
String classpath = createInterpreterClasspath(additionalPaths);
interpreter = initInterpreter(classpath);
} catch (Exception e) {
errorReporter.addLoadingError("Failed to init scala interpreter", e);
return;
} catch (LinkageError e) {
errorReporter.addLoadingError("Failed to init scala interpreter", e);
return;
}
interpreterOutput.getBuffer().delete(0, interpreterOutput.getBuffer().length());
for (Map.Entry<String, ?> entry : binding.entrySet()) {
interpreter.bindValue(entry.getKey(), entry.getValue());
}
}
runOnEDTCallback.fun(new Runnable() {
@Override public void run() {
synchronized (interpreterLock) {
Results.Result result;
try {
result = interpreter.interpret(FileUtil.loadFile(scriptFile));
} catch (LinkageError e) {
errorReporter.addLoadingError(pluginId, "Error linking script file: " + scriptFile);
return;
} catch (Exception e) {
errorReporter.addLoadingError(pluginId, "Error reading script file: " + scriptFile);