Search in sources :

Example 36 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project buck by facebook.

the class TestExecutionState method runBuildCommand.

private ProcessHandler runBuildCommand(Executor executor) {
    final BuckModule buckModule = mProject.getComponent(BuckModule.class);
    final String target = mConfiguration.data.target;
    final String additionalParams = mConfiguration.data.additionalParams;
    final String testSelectors = mConfiguration.data.testSelectors;
    final String title = "Buck Test " + target;
    buckModule.attach(target);
    final BuckBuildCommandHandler handler = new BuckBuildCommandHandler(mProject, mProject.getBaseDir(), BuckCommand.TEST, /* doStartNotify */
    false) {

        @Override
        protected void notifyLines(Key outputType, Iterable<String> lines) {
            super.notifyLines(outputType, lines);
            if (outputType != ProcessOutputTypes.STDERR) {
                return;
            }
            for (String line : lines) {
                final Matcher matcher = DEBUG_SUSPEND_PATTERN.matcher(line);
                if (matcher.find()) {
                    final String port = matcher.group(1);
                    attachDebugger(title, port);
                }
            }
        }
    };
    if (!target.isEmpty()) {
        handler.command().addParameter(target);
    }
    if (!testSelectors.isEmpty()) {
        handler.command().addParameter("--test-selectors");
        handler.command().addParameter(testSelectors);
    }
    if (!additionalParams.isEmpty()) {
        for (String param : additionalParams.split("\\s")) {
            handler.command().addParameter(param);
        }
    }
    if (executor.getId().equals(DefaultDebugExecutor.EXECUTOR_ID)) {
        handler.command().addParameter("--debug");
    }
    handler.start();
    final OSProcessHandler result = handler.getHandler();
    showProgress(result, title);
    return result;
}
Also used : BuckModule(com.facebook.buck.intellij.ideabuck.config.BuckModule) Matcher(java.util.regex.Matcher) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) BuckBuildCommandHandler(com.facebook.buck.intellij.ideabuck.build.BuckBuildCommandHandler) Key(com.intellij.openapi.util.Key)

Example 37 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project intellij-plugins by JetBrains.

the class DartPubActionBase method doPerformPubAction.

private static void doPerformPubAction(@NotNull final Module module, @NotNull final VirtualFile pubspecYamlFile, @NotNull final GeneralCommandLine command, @NotNull final String actionTitle) {
    FileDocumentManager.getInstance().saveAllDocuments();
    try {
        if (ourInProgress.compareAndSet(false, true)) {
            command.withEnvironment(PUB_ENV_VAR_NAME, getPubEnvValue());
            final OSProcessHandler processHandler = new OSProcessHandler(command);
            processHandler.addProcessListener(new ProcessAdapter() {

                @Override
                public void processTerminated(final ProcessEvent event) {
                    ourInProgress.set(false);
                    ApplicationManager.getApplication().invokeLater(() -> {
                        if (!module.isDisposed()) {
                            DartProjectComponent.excludeBuildAndPackagesFolders(module, pubspecYamlFile);
                            // refresh later than exclude, otherwise IDE may start indexing excluded folders
                            VfsUtil.markDirtyAndRefresh(true, true, true, pubspecYamlFile.getParent());
                            if (DartSdkLibUtil.isDartSdkEnabled(module)) {
                                DartAnalysisServerService.getInstance(module.getProject()).serverReadyForRequest(module.getProject());
                            }
                        }
                    });
                }
            });
            showPubOutputConsole(module, command, processHandler, pubspecYamlFile, actionTitle);
        }
    } catch (ExecutionException e) {
        ourInProgress.set(false);
        // may be better show it in Messages tool window console?
        Notifications.Bus.notify(new Notification(GROUP_DISPLAY_ID, actionTitle, DartBundle.message("dart.pub.exception", e.getMessage()), NotificationType.ERROR));
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) Notification(com.intellij.notification.Notification)

Example 38 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project intellij-plugins by JetBrains.

the class PubServerService method createProcessHandler.

@Override
@Nullable
protected OSProcessHandler createProcessHandler(@NotNull final Project project, final int port) throws ExecutionException {
    final DartSdk dartSdk = DartSdk.getDartSdk(project);
    if (dartSdk == null)
        return null;
    final GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(firstServedDir.getParent().getPath());
    commandLine.setExePath(FileUtil.toSystemDependentName(DartSdkUtil.getPubPath(dartSdk)));
    commandLine.addParameter("serve");
    commandLine.addParameter(firstServedDir.getName());
    commandLine.addParameter("--port=" + String.valueOf(port));
    commandLine.withEnvironment(DartPubActionBase.PUB_ENV_VAR_NAME, DartPubActionBase.getPubEnvValue());
    final OSProcessHandler processHandler = new OSProcessHandler(commandLine);
    processHandler.addProcessListener(new PubServeOutputListener(project));
    return processHandler;
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) Nullable(org.jetbrains.annotations.Nullable)

Example 39 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.

the class BaseJavaApplicationCommandLineState method startProcess.

@NotNull
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
    OSProcessHandler handler = new KillableColoredProcessHandler(createCommandLine());
    ProcessTerminatedListener.attach(handler);
    JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, getRunnerSettings());
    return handler;
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with OSProcessHandler

use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.

the class GroovyScriptRunConfiguration method getState.

@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
    final VirtualFile scriptFile = ScriptFileUtil.findScriptFileByPath(getScriptPath());
    if (scriptFile == null)
        return null;
    final GroovyScriptRunner scriptRunner = getScriptRunner();
    if (scriptRunner == null)
        return null;
    return new JavaCommandLineState(environment) {

        @NotNull
        @Override
        protected OSProcessHandler startProcess() throws ExecutionException {
            final OSProcessHandler handler = super.startProcess();
            handler.setShouldDestroyProcessRecursively(true);
            if (scriptRunner.shouldRefreshAfterFinish()) {
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void processTerminated(ProcessEvent event) {
                        if (!ApplicationManager.getApplication().isDisposed()) {
                            VirtualFileManager.getInstance().asyncRefresh(null);
                        }
                    }
                });
            }
            return handler;
        }

        @Override
        protected JavaParameters createJavaParameters() throws ExecutionException {
            final Module module = getModule();
            final boolean tests = ProjectRootManager.getInstance(getProject()).getFileIndex().isInTestSourceContent(scriptFile);
            String jrePath = isAlternativeJrePathEnabled() ? getAlternativeJrePath() : null;
            JavaParameters params = new JavaParameters();
            params.setUseClasspathJar(true);
            params.setDefaultCharset(getProject());
            params.setJdk(module == null ? JavaParametersUtil.createProjectJdk(getProject(), jrePath) : JavaParametersUtil.createModuleJdk(module, !tests, jrePath));
            configureConfiguration(params, new CommonProgramRunConfigurationParametersDelegate(GroovyScriptRunConfiguration.this) {

                @Nullable
                @Override
                public String getProgramParameters() {
                    return null;
                }
            });
            scriptRunner.configureCommandLine(params, module, tests, scriptFile, GroovyScriptRunConfiguration.this);
            return params;
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommonProgramRunConfigurationParametersDelegate(org.jetbrains.plugins.groovy.runner.util.CommonProgramRunConfigurationParametersDelegate) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

OSProcessHandler (com.intellij.execution.process.OSProcessHandler)55 ExecutionException (com.intellij.execution.ExecutionException)25 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)24 ProcessEvent (com.intellij.execution.process.ProcessEvent)24 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)23 NotNull (org.jetbrains.annotations.NotNull)18 Key (com.intellij.openapi.util.Key)14 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 Module (com.intellij.openapi.module.Module)5 Sdk (com.intellij.openapi.projectRoots.Sdk)5 IOException (java.io.IOException)5 ProgramRunner (com.intellij.execution.runners.ProgramRunner)4 Nullable (org.jetbrains.annotations.Nullable)4 Executor (com.intellij.execution.Executor)3 RunContentExecutor (com.intellij.execution.RunContentExecutor)3 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3