Search in sources :

Example 31 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.

the class AdlUtil method runDebugger.

// http://kb2.adobe.com/cps/407/kb407625.html
public static void runDebugger(final Module module, final Runnable postTask) throws ExecutionException {
    final Project project = module.getProject();
    final RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createConfiguration("FlashUIDesigner", RemoteFlashRunConfigurationType.getFactory());
    final RemoteFlashRunConfiguration configuration = (RemoteFlashRunConfiguration) settings.getConfiguration();
    RunManagerEx.disableTasks(project, settings.getConfiguration(), CompileStepBeforeRun.ID, CompileStepBeforeRunNoErrorCheck.ID);
    final Executor executor = DefaultDebugExecutor.getDebugExecutorInstance();
    ProgramRunner.Callback callback = new ProgramRunner.Callback() {

        @Override
        public void processStarted(final RunContentDescriptor descriptor) {
            final ProcessHandler processHandler = descriptor.getProcessHandler();
            assert processHandler != null;
            DesignerApplication application = DesignerApplicationManager.getApplication();
            if (application != null) {
                Disposer.register(application, new Disposable() {

                    @Override
                    public void dispose() {
                        if (!project.isDisposed()) {
                            ApplicationManager.getApplication().invokeLater(() -> ExecutionManager.getInstance(project).getContentManager().removeRunContent(executor, descriptor));
                        }
                        processHandler.destroyProcess();
                    }
                });
                postTask.run();
            }
        }
    };
    FlexBuildConfiguration buildConfiguration = FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration();
    configuration.getRunnerParameters().setModuleName(module.getName());
    configuration.getRunnerParameters().setBCName(buildConfiguration.getName());
    final FlexRunner runner = new FlexRunner(callback, buildConfiguration);
    runner.execute(new ExecutionEnvironment(executor, runner, settings, project));
}
Also used : Disposable(com.intellij.openapi.Disposable) FlexRunner(com.intellij.flex.uiDesigner.debug.FlexRunner) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) Project(com.intellij.openapi.project.Project) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) RemoteFlashRunConfiguration(com.intellij.lang.javascript.flex.run.RemoteFlashRunConfiguration) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 32 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project android by JetBrains.

the class AndroidJavaDebugger method hasExistingDebugSession.

private static boolean hasExistingDebugSession(@NotNull Project project, @NotNull final String debugPort, @NotNull final String runConfigName) {
    Collection<RunContentDescriptor> descriptors = null;
    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    Project targetProject = null;
    // Scan through open project to find if this port has been opened in any session.
    for (Project openProject : openProjects) {
        targetProject = openProject;
        // First check the titles of the run configurations.
        descriptors = ExecutionHelper.findRunningConsoleByTitle(targetProject, new NotNullFunction<String, Boolean>() {

            @NotNull
            @Override
            public Boolean fun(String title) {
                return runConfigName.equals(title);
            }
        });
        // If it can't find a matching title, check the debugger sessions.
        if (descriptors.isEmpty()) {
            DebuggerSession debuggerSession = findJdwpDebuggerSession(targetProject, debugPort);
            if (debuggerSession != null) {
                XDebugSession session = debuggerSession.getXDebugSession();
                if (session != null) {
                    descriptors = Collections.singletonList(session.getRunContentDescriptor());
                } else {
                    // Detach existing session.
                    debuggerSession.getProcess().stop(false);
                }
            }
        }
        if (!descriptors.isEmpty()) {
            break;
        }
    }
    if (descriptors != null && !descriptors.isEmpty()) {
        return activateDebugSessionWindow(project, descriptors.iterator().next());
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) NotNullFunction(com.intellij.util.NotNullFunction)

Example 33 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.

the class KarmaDebugProgramRunner method execute.

@NotNull
@Override
protected Promise<RunContentDescriptor> execute(@NotNull ExecutionEnvironment environment, @NotNull RunProfileState state) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    ExecutionResult executionResult = state.execute(environment.getExecutor(), this);
    if (executionResult == null) {
        return Promise.resolve(null);
    }
    KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
    if (consoleView == null) {
        return Promise.resolve(KarmaUtil.createDefaultDescriptor(executionResult, environment));
    }
    KarmaServer karmaServer = consoleView.getKarmaExecutionSession().getKarmaServer();
    if (karmaServer.areBrowsersReady()) {
        KarmaDebugBrowserSelector browserSelector = new KarmaDebugBrowserSelector(karmaServer.getCapturedBrowsers(), environment, consoleView);
        DebuggableWebBrowser debuggableWebBrowser = browserSelector.selectDebugEngine();
        if (debuggableWebBrowser == null) {
            return Promises.resolvedPromise(KarmaUtil.createDefaultDescriptor(executionResult, environment));
        }
        return KarmaKt.prepareKarmaDebugger(environment.getProject(), debuggableWebBrowser, () -> createDescriptor(environment, executionResult, consoleView, karmaServer, debuggableWebBrowser));
    } else {
        RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, environment);
        karmaServer.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
        return Promises.resolvedPromise(descriptor);
    }
}
Also used : KarmaServer(com.intellij.javascript.karma.server.KarmaServer) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) KarmaConsoleView(com.intellij.javascript.karma.execution.KarmaConsoleView) ExecutionResult(com.intellij.execution.ExecutionResult) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-plugins by JetBrains.

the class KarmaCoverageProgramRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment env) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    ExecutionResult executionResult = state.execute(env.getExecutor(), this);
    if (executionResult == null) {
        return null;
    }
    RunContentDescriptor descriptor = KarmaUtil.createDefaultDescriptor(executionResult, env);
    KarmaConsoleView consoleView = KarmaConsoleView.get(executionResult, state);
    if (consoleView == null) {
        return descriptor;
    }
    KarmaServer server = consoleView.getKarmaExecutionSession().getKarmaServer();
    if (server.areBrowsersReady()) {
        listenForCoverageFile(env, server);
    } else {
        server.onBrowsersReady(() -> ExecutionUtil.restartIfActive(descriptor));
    }
    return descriptor;
}
Also used : KarmaServer(com.intellij.javascript.karma.server.KarmaServer) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) KarmaConsoleView(com.intellij.javascript.karma.execution.KarmaConsoleView) ExecutionResult(com.intellij.execution.ExecutionResult)

Example 35 with RunContentDescriptor

use of com.intellij.execution.ui.RunContentDescriptor in project intellij-leiningen-plugin by derkork.

the class LeiningenRunConfigurationType method runConfiguration.

public static void runConfiguration(Project project, LeiningenRunnerParameters params, DataContext context) {
    RunnerAndConfigurationSettings configSettings = createRunnerAndConfigurationSettings(params, project);
    ProgramRunner runner = RunnerRegistry.getInstance().findRunnerById(DefaultRunExecutor.EXECUTOR_ID);
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    ExecutionEnvironment env = new ExecutionEnvironment(executor, runner, configSettings, project);
    try {
        runner.execute(env, new ProgramRunner.Callback() {

            public void processStarted(RunContentDescriptor runContentDescriptor) {
                final ProcessHandler runContentDescriptorProcessHandler = runContentDescriptor.getProcessHandler();
                if (runContentDescriptorProcessHandler != null) {
                    runContentDescriptorProcessHandler.addProcessListener(new ProcessAdapter() {

                        @Override
                        public void processTerminated(ProcessEvent event) {
                            LocalFileSystem.getInstance().refreshWithoutFileWatcher(true);
                        }
                    });
                }
            }
        });
    } catch (ExecutionException e) {
    }
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessHandler(com.intellij.execution.process.ProcessHandler) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Aggregations

RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)70 ProcessHandler (com.intellij.execution.process.ProcessHandler)26 Project (com.intellij.openapi.project.Project)18 NotNull (org.jetbrains.annotations.NotNull)14 Nullable (org.jetbrains.annotations.Nullable)13 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)11 Executor (com.intellij.execution.Executor)10 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)9 ProcessEvent (com.intellij.execution.process.ProcessEvent)8 ExecutionException (com.intellij.execution.ExecutionException)7 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)7 ArrayList (java.util.ArrayList)7 ProgramRunner (com.intellij.execution.runners.ProgramRunner)6 ExecutionResult (com.intellij.execution.ExecutionResult)5 RunProfile (com.intellij.execution.configurations.RunProfile)5 CloseAction (com.intellij.execution.ui.actions.CloseAction)5 Pair (com.intellij.openapi.util.Pair)5 IOException (java.io.IOException)5 RunContentManager (com.intellij.execution.ui.RunContentManager)4 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4