Search in sources :

Example 86 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project clion-embedded-arm by elmot.

the class OpenOcdLauncher method createDebugProcess.

@NotNull
@Override
protected CidrDebugProcess createDebugProcess(@NotNull CommandLineState commandLineState, @NotNull XDebugSession xDebugSession) throws ExecutionException {
    Project project = commandLineState.getEnvironment().getProject();
    OpenOcdSettingsState ocdSettings = project.getComponent(OpenOcdSettingsState.class);
    CidrRemoteDebugParameters remoteDebugParameters = new CidrRemoteDebugParameters();
    remoteDebugParameters.setSymbolFile(findRunFile(commandLineState).getAbsolutePath());
    remoteDebugParameters.setRemoteCommand("tcp:localhost:" + ocdSettings.gdbPort);
    CPPToolchains.Toolchain toolchain = CPPToolchains.getInstance().getDefaultToolchain();
    if (toolchain == null) {
        throw new ExecutionException("Project toolchain is not defined. Please define it in the project settings.");
    }
    String gdbPath;
    toolchain = toolchain.copy();
    if (ocdSettings.shippedGdb) {
        gdbPath = PathManager.findBinFile("gdb/bin/gdb" + (OS.isWindows() ? ".exe" : "")).getAbsolutePath();
    } else {
        gdbPath = ocdSettings.gdbLocation;
    }
    CPPDebugger cppDebugger = CPPDebugger.create(CPPDebugger.Kind.CUSTOM_GDB, gdbPath);
    toolchain.setDebugger(cppDebugger);
    GDBDriverConfiguration gdbDriverConfiguration = new GDBDriverConfiguration(getProject(), toolchain);
    xDebugSession.stop();
    CidrRemoteGDBDebugProcess debugProcess = new CidrRemoteGDBDebugProcess(gdbDriverConfiguration, remoteDebugParameters, xDebugSession, commandLineState.getConsoleBuilder(), project1 -> new Filter[0]);
    debugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {

        @Override
        public void processWillTerminate(@NotNull ProcessEvent event, boolean willBeDestroyed) {
            super.processWillTerminate(event, willBeDestroyed);
            findOpenOcdAction(project).stopOpenOcd();
        }
    });
    debugProcess.getProcessHandler().putUserData(RESTART_KEY, new AnAction("Reset", "MCU Reset", IconLoader.findIcon("reset.png", OpenOcdLauncher.class)) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            XDebugSession session = debugProcess.getSession();
            session.pause();
            debugProcess.postCommand(drv -> {
                try {
                    ProgressManager.getInstance().runProcess(() -> {
                        while (drv.getState() != DebuggerDriver.TargetState.SUSPENDED) {
                            Thread.yield();
                        }
                    }, null);
                    drv.executeConsoleCommand("monitor reset init");
                    session.resume();
                } catch (DebuggerCommandException exception) {
                    Informational.showFailedDownloadNotification(e.getProject());
                }
            });
        }
    });
    return debugProcess;
}
Also used : ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) CPPDebugger(com.jetbrains.cidr.cpp.toolchains.CPPDebugger) ExecutionException(com.intellij.execution.ExecutionException) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) PathManager(com.intellij.openapi.application.PathManager) TimeoutException(java.util.concurrent.TimeoutException) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) CidrDebugProcess(com.jetbrains.cidr.execution.debugger.CidrDebugProcess) CidrRemoteGDBDebugProcess(com.jetbrains.cidr.execution.debugger.remote.CidrRemoteGDBDebugProcess) DebuggerCommandException(com.jetbrains.cidr.execution.debugger.backend.DebuggerCommandException) Future(java.util.concurrent.Future) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) CidrRemoteDebugParameters(com.jetbrains.cidr.execution.debugger.remote.CidrRemoteDebugParameters) XDebugSession(com.intellij.xdebugger.XDebugSession) OS(org.jdesktop.swingx.util.OS) CMakeAppRunConfiguration(com.jetbrains.cidr.cpp.execution.CMakeAppRunConfiguration) ProgressManager(com.intellij.openapi.progress.ProgressManager) CidrLauncher(com.jetbrains.cidr.execution.testing.CidrLauncher) GDBDriverConfiguration(com.jetbrains.cidr.cpp.execution.debugger.backend.GDBDriverConfiguration) CommandLineState(com.intellij.execution.configurations.CommandLineState) CPPToolchains(com.jetbrains.cidr.cpp.toolchains.CPPToolchains) Filter(com.intellij.execution.filters.Filter) Key(com.intellij.openapi.util.Key) DebuggerDriver(com.jetbrains.cidr.execution.debugger.backend.DebuggerDriver) AnAction(com.intellij.openapi.actionSystem.AnAction) File(java.io.File) ProcessHandler(com.intellij.execution.process.ProcessHandler) TimeUnit(java.util.concurrent.TimeUnit) ThrowableComputable(com.intellij.openapi.util.ThrowableComputable) List(java.util.List) IconLoader(com.intellij.openapi.util.IconLoader) STATUS(xyz.elmot.clion.openocd.OpenOcdComponent.STATUS) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ProcessEvent(com.intellij.execution.process.ProcessEvent) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) XDebugSession(com.intellij.xdebugger.XDebugSession) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) DebuggerCommandException(com.jetbrains.cidr.execution.debugger.backend.DebuggerCommandException) CPPToolchains(com.jetbrains.cidr.cpp.toolchains.CPPToolchains) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) CidrRemoteDebugParameters(com.jetbrains.cidr.execution.debugger.remote.CidrRemoteDebugParameters) AnAction(com.intellij.openapi.actionSystem.AnAction) GDBDriverConfiguration(com.jetbrains.cidr.cpp.execution.debugger.backend.GDBDriverConfiguration) CidrRemoteGDBDebugProcess(com.jetbrains.cidr.execution.debugger.remote.CidrRemoteGDBDebugProcess) Project(com.intellij.openapi.project.Project) CPPDebugger(com.jetbrains.cidr.cpp.toolchains.CPPDebugger) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project clion-embedded-arm by elmot.

the class OpenOcdLauncher method createProcess.

@Override
protected ProcessHandler createProcess(@NotNull CommandLineState commandLineState) throws ExecutionException {
    File runFile = findRunFile(commandLineState);
    findOpenOcdAction(commandLineState.getEnvironment().getProject()).stopOpenOcd();
    try {
        GeneralCommandLine commandLine = OpenOcdComponent.createOcdCommandLine(commandLineState.getEnvironment().getProject(), runFile, "reset", true);
        OSProcessHandler osProcessHandler = new OSProcessHandler(commandLine);
        osProcessHandler.addProcessListener(new ProcessAdapter() {

            @Override
            public void processTerminated(@NotNull ProcessEvent event) {
                super.processTerminated(event);
                Project project = commandLineState.getEnvironment().getProject();
                if (event.getExitCode() == 0) {
                    Informational.showSuccessfulDownloadNotification(project);
                } else {
                    Informational.showFailedDownloadNotification(project);
                }
            }
        });
        return osProcessHandler;
    } catch (ConfigurationException e) {
        Messages.showErrorDialog(getProject(), e.getLocalizedMessage(), e.getTitle());
        throw new ExecutionException(e);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ConfigurationException(com.intellij.openapi.options.ConfigurationException) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 88 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project intellij by bazelbuild.

the class BlazeAndroidTestLaunchTask method waitAndSetUpForKillingBlazeOnStop.

/**
 * Hooks up the Blaze process to be killed if the user hits the 'Stop' button, then waits for the
 * Blaze process to stop. In non-debug mode, we wait for test execution to finish before returning
 * from launch() (this matches the behavior of the stock ddmlib runner).
 */
private void waitAndSetUpForKillingBlazeOnStop(@NotNull final ProcessHandler processHandler, @NotNull LaunchStatus launchStatus) {
    processHandler.addProcessListener(new ProcessAdapter() {

        @Override
        public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
            blazeResult.cancel(true);
            launchStatus.terminateLaunch("Test run stopped.\n");
        }
    });
    try {
        blazeResult.get();
        launchStatus.terminateLaunch("Tests ran to completion.\n");
    } catch (CancellationException e) {
        // The user has canceled the test.
        launchStatus.terminateLaunch("Test run stopped.\n");
    } catch (InterruptedException e) {
        // We've been interrupted - cancel the underlying Blaze process.
        blazeResult.cancel(true);
        launchStatus.terminateLaunch("Test run stopped.\n");
    } catch (ExecutionException e) {
        LOG.error(e);
        launchStatus.terminateLaunch("Test run stopped due to internal exception. Please file a bug report.\n");
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException)

Example 89 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoBeforeRunTaskProvider method executeTask.

@Override
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, GoCommandBeforeRunTask task) {
    Semaphore done = new Semaphore();
    Ref<Boolean> result = Ref.create(false);
    GoRunConfigurationBase goRunConfiguration = (GoRunConfigurationBase) configuration;
    Module module = goRunConfiguration.getConfigurationModule().getModule();
    Project project = configuration.getProject();
    String workingDirectory = goRunConfiguration.getWorkingDirectory();
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            if (StringUtil.isEmpty(task.getCommand()))
                return;
            if (project == null || project.isDisposed())
                return;
            GoSdkService sdkService = GoSdkService.getInstance(project);
            if (!sdkService.isGoModule(module))
                return;
            done.down();
            GoExecutor.in(module).withParameterString(task.getCommand()).withWorkDirectory(workingDirectory).showOutputOnError().showNotifications(false, true).withPresentableName("Executing `" + task + "`").withProcessListener(new ProcessAdapter() {

                @Override
                public void processTerminated(ProcessEvent event) {
                    done.up();
                    result.set(event.getExitCode() == 0);
                }
            }).executeWithProgress(false, result1 -> VirtualFileManager.getInstance().asyncRefresh(null));
        }
    });
    done.waitFor();
    return result.get();
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) GoRunConfigurationBase(com.goide.runconfig.GoRunConfigurationBase) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) DataContext(com.intellij.openapi.actionSystem.DataContext) GoIcons(com.goide.GoIcons) StringUtil(com.intellij.openapi.util.text.StringUtil) GoExecutor(com.goide.util.GoExecutor) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) Key(com.intellij.openapi.util.Key) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) GoSdkService(com.goide.sdk.GoSdkService) Nullable(org.jetbrains.annotations.Nullable) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Semaphore(com.intellij.util.concurrency.Semaphore) BeforeRunTaskProvider(com.intellij.execution.BeforeRunTaskProvider) Project(com.intellij.openapi.project.Project) ProcessEvent(com.intellij.execution.process.ProcessEvent) Messages(com.intellij.openapi.ui.Messages) Module(com.intellij.openapi.module.Module) Ref(com.intellij.openapi.util.Ref) javax.swing(javax.swing) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Semaphore(com.intellij.util.concurrency.Semaphore) GoSdkService(com.goide.sdk.GoSdkService) GoRunConfigurationBase(com.goide.runconfig.GoRunConfigurationBase) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module)

Example 90 with ProcessEvent

use of com.intellij.execution.process.ProcessEvent 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

ProcessEvent (com.intellij.execution.process.ProcessEvent)90 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)82 Key (com.intellij.openapi.util.Key)34 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)25 NotNull (org.jetbrains.annotations.NotNull)24 ExecutionException (com.intellij.execution.ExecutionException)22 ProcessHandler (com.intellij.execution.process.ProcessHandler)18 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)16 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)12 IOException (java.io.IOException)12 Nullable (org.jetbrains.annotations.Nullable)12 Project (com.intellij.openapi.project.Project)9 File (java.io.File)9 ProcessListener (com.intellij.execution.process.ProcessListener)8 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)7 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)5 ProgramRunner (com.intellij.execution.runners.ProgramRunner)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)4 Disposable (com.intellij.openapi.Disposable)4