Search in sources :

Example 1 with IdeScriptEngine

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);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IdeScriptException(org.jetbrains.ide.script.IdeScriptException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Project(com.intellij.openapi.project.Project) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) List(java.util.List) IdeScriptEngine(org.jetbrains.ide.script.IdeScriptEngine) Pair(com.intellij.openapi.util.Pair) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 2 with IdeScriptEngine

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeScriptEngineManager(org.jetbrains.ide.script.IdeScriptEngineManager) Pair(com.intellij.openapi.util.Pair) IdeScriptEngine(org.jetbrains.ide.script.IdeScriptEngine) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Pair (com.intellij.openapi.util.Pair)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IdeScriptEngine (org.jetbrains.ide.script.IdeScriptEngine)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1 ProjectManagerAdapter (com.intellij.openapi.project.ProjectManagerAdapter)1 IOException (java.io.IOException)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 NotNull (org.jetbrains.annotations.NotNull)1 IdeScriptEngineManager (org.jetbrains.ide.script.IdeScriptEngineManager)1 IdeScriptException (org.jetbrains.ide.script.IdeScriptException)1