use of org.jetbrains.ide.script.IdeScriptEngine in project intellij-community by JetBrains.
the class IdeStartupScripts method scheduleStartupScriptsExecution.
private static void scheduleStartupScriptsExecution() {
List<VirtualFile> scripts = getScripts();
LOG.info(scripts.size() + " startup script(s) found");
if (scripts.isEmpty())
return;
final Future<List<Pair<VirtualFile, IdeScriptEngine>>> scriptsAndEnginesFuture = prepareScriptEnginesAsync(scripts);
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerAdapter() {
final AtomicBoolean myScriptsExecutionStarted = new AtomicBoolean();
@Override
public void projectOpened(final Project project) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
if (project.isDisposed())
return;
if (!myScriptsExecutionStarted.compareAndSet(false, true))
return;
ProjectManager.getInstance().removeProjectManagerListener(this);
runAllScriptsImpl(project);
});
}
private void runAllScriptsImpl(@NotNull Project project) {
try {
for (Pair<VirtualFile, IdeScriptEngine> pair : scriptsAndEnginesFuture.get()) {
try {
if (pair.second == null) {
LOG.warn(pair.first.getPath() + " not supported (no script engine)");
} else {
runImpl(project, pair.first, pair.second);
}
} catch (Exception e) {
LOG.warn(e);
}
}
} catch (ProcessCanceledException e) {
LOG.warn("... cancelled");
} catch (InterruptedException e) {
LOG.warn("... interrupted");
} catch (Exception e) {
LOG.error(e);
}
}
});
}
use of org.jetbrains.ide.script.IdeScriptEngine in project intellij-community by JetBrains.
the class IdeStartupScripts method prepareScriptEngines.
@NotNull
private static List<Pair<VirtualFile, IdeScriptEngine>> prepareScriptEngines(@NotNull List<VirtualFile> scripts) {
IdeScriptEngineManager scriptEngineManager = IdeScriptEngineManager.getInstance();
List<Pair<VirtualFile, IdeScriptEngine>> result = ContainerUtil.newArrayList();
for (VirtualFile script : scripts) {
String extension = script.getExtension();
IdeScriptEngine engine = extension != null ? scriptEngineManager.getEngineForFileExtension(extension, null) : null;
result.add(Pair.create(script, engine));
}
return result;
}
Aggregations