com.intellij.execution.process.OSProcessHandler Java Examples
The following examples show how to use
com.intellij.execution.process.OSProcessHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestExecutionState.java From buck with Apache License 2.0 | 6 votes |
private void schedulePostExecutionActions(final OSProcessHandler result, final String title) { final ProgressManager manager = ProgressManager.getInstance(); ApplicationManager.getApplication() .invokeLater( () -> { manager.run( new Task.Backgroundable(mProject, title, true) { @Override public void run(@NotNull final ProgressIndicator indicator) { try { result.waitFor(); } finally { indicator.cancel(); } BuckToolWindow buckToolWindow = BuckUIManager.getInstance(mProject).getBuckToolWindow(); if (!buckToolWindow.isRunToolWindowVisible()) { buckToolWindow.showRunToolWindow(); } } }); }); }
Example #2
Source File: FlutterConsoleFilter.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void navigate(Project project) { try { final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(myPath); final OSProcessHandler handler = new OSProcessHandler(cmd); handler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(@NotNull final ProcessEvent event) { if (event.getExitCode() != 0) { FlutterMessages.showError("Error Opening ", myPath); } } }); handler.startNotify(); } catch (ExecutionException e) { FlutterMessages.showError( "Error Opening External File", "Exception: " + e.getMessage()); } }
Example #3
Source File: FlutterConsole.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Starts displaying the output of a different process. */ void watchProcess(@NotNull OSProcessHandler process) { if (cancelProcessSubscription != null) { cancelProcessSubscription.run(); cancelProcessSubscription = null; } view.clear(); view.attachToProcess(process); // Print exit code. final ProcessAdapter listener = new ProcessAdapter() { @Override public void processTerminated(final ProcessEvent event) { view.print( "Process finished with exit code " + event.getExitCode(), ConsoleViewContentType.SYSTEM_OUTPUT); } }; process.addProcessListener(listener); cancelProcessSubscription = () -> process.removeProcessListener(listener); }
Example #4
Source File: FlutterConsoles.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Shows a process's output on the appropriate console. (Asynchronous.) * * @param module if not null, show in this module's console. */ public static void displayProcessLater(@NotNull OSProcessHandler process, @NotNull Project project, @Nullable Module module, @NotNull Runnable onReady) { // Getting a MessageView has to happen on the UI thread. ApplicationManager.getApplication().invokeLater(() -> { final MessageView messageView = MessageView.SERVICE.getInstance(project); messageView.runWhenInitialized(() -> { final FlutterConsole console = findOrCreate(project, module); console.watchProcess(process); console.bringToFront(); onReady.run(); }); }); }
Example #5
Source File: NativeFileWatcherImpl.java From consulo with Apache License 2.0 | 6 votes |
private void shutdownProcess() { OSProcessHandler processHandler = myProcessHandler; if (processHandler != null) { if (!processHandler.isProcessTerminated()) { try { writeLine(EXIT_COMMAND); } catch (IOException ignore) { } if (!processHandler.waitFor(10)) { ApplicationManager.getApplication().executeOnPooledThread(() -> { if (!processHandler.waitFor(500)) { LOG.warn("File watcher is still alive. Doing a force quit."); processHandler.destroyProcess(); } }); } } myProcessHandler = null; } }
Example #6
Source File: FlutterBuildActionGroup.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static OSProcessHandler build(Project project, @NotNull PubRoot pubRoot, FlutterSdk sdk, BuildType buildType, String desc) { ProgressHelper progressHelper = new ProgressHelper(project); progressHelper.start(desc); OSProcessHandler processHandler = sdk.flutterBuild(pubRoot, buildType.type).startInConsole(project); if (processHandler == null) { progressHelper.done(); } else { processHandler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(@NotNull ProcessEvent event) { progressHelper.done(); int exitCode = event.getExitCode(); if (exitCode != 0) { FlutterMessages.showError("Error while building " + buildType, "`flutter build` returned: " + exitCode); } } }); } return processHandler; }
Example #7
Source File: OpenInXcodeAction.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void openWithXcode(String path) { try { final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(path); final OSProcessHandler handler = new OSProcessHandler(cmd); handler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(@NotNull final ProcessEvent event) { if (event.getExitCode() != 0) { FlutterMessages.showError("Error Opening", path); } } }); handler.startNotify(); } catch (ExecutionException ex) { FlutterMessages.showError( "Error Opening", "Exception: " + ex.getMessage()); } }
Example #8
Source File: DevToolsManager.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Gets the process handler that will start DevTools from pub. */ @Nullable private OSProcessHandler getProcessHandlerForPub() { final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); if (sdk == null) { return null; } final FlutterCommand command = sdk.flutterPub(null, "global", "run", "devtools", "--machine", "--port=0"); final OSProcessHandler processHandler = command.startProcessOrShowError(project); if (processHandler != null) { ApplicationManager.getApplication().invokeLater(() -> { //noinspection Convert2MethodRef processHandler.startNotify(); }); } return processHandler; }
Example #9
Source File: ReactiveTfvcClientHost.java From azure-devops-intellij with MIT License | 6 votes |
public static ReactiveTfvcClientHost create(Project project, Path clientPath) throws ExecutionException { SingleThreadScheduler scheduler = new SingleThreadScheduler(defineNestedLifetime(project), "ReactiveTfClient Scheduler"); ReactiveClientConnection connection = new ReactiveClientConnection(scheduler); try { Path logDirectory = Paths.get(PathManager.getLogPath(), "ReactiveTfsClient"); Path clientHomeDir = clientPath.getParent().getParent(); GeneralCommandLine commandLine = ProcessHelper.patchPathEnvironmentVariable( getClientCommandLine(clientPath, connection.getPort(), logDirectory, clientHomeDir)); ProcessHandler processHandler = new OSProcessHandler(commandLine); connection.getLifetime().onTerminationIfAlive(processHandler::destroyProcess); processHandler.addProcessListener(createProcessListener(connection)); processHandler.startNotify(); return new ReactiveTfvcClientHost(connection); } catch (Throwable t) { connection.terminate(); throw t; } }
Example #10
Source File: FlutterConsoleFilter.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void navigate(Project project) { try { final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(myPath); final OSProcessHandler handler = new OSProcessHandler(cmd); handler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(@NotNull final ProcessEvent event) { if (event.getExitCode() != 0) { FlutterMessages.showError("Error Opening ", myPath); } } }); handler.startNotify(); } catch (ExecutionException e) { FlutterMessages.showError( "Error Opening External File", "Exception: " + e.getMessage()); } }
Example #11
Source File: DevToolsManager.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Gets the process handler that will start DevTools from pub. */ @Nullable private OSProcessHandler getProcessHandlerForPub() { final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project); if (sdk == null) { return null; } final FlutterCommand command = sdk.flutterPub(null, "global", "run", "devtools", "--machine", "--port=0"); final OSProcessHandler processHandler = command.startProcessOrShowError(project); if (processHandler != null) { ApplicationManager.getApplication().invokeLater(() -> { //noinspection Convert2MethodRef processHandler.startNotify(); }); } return processHandler; }
Example #12
Source File: FlutterConsole.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Starts displaying the output of a different process. */ void watchProcess(@NotNull OSProcessHandler process) { if (cancelProcessSubscription != null) { cancelProcessSubscription.run(); cancelProcessSubscription = null; } view.clear(); view.attachToProcess(process); // Print exit code. final ProcessAdapter listener = new ProcessAdapter() { @Override public void processTerminated(final ProcessEvent event) { view.print( "Process finished with exit code " + event.getExitCode(), ConsoleViewContentType.SYSTEM_OUTPUT); } }; process.addProcessListener(listener); cancelProcessSubscription = () -> process.removeProcessListener(listener); }
Example #13
Source File: FlutterConsoles.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Shows a process's output on the appropriate console. (Asynchronous.) * * @param module if not null, show in this module's console. */ public static void displayProcessLater(@NotNull OSProcessHandler process, @NotNull Project project, @Nullable Module module, @NotNull Runnable onReady) { // Getting a MessageView has to happen on the UI thread. ApplicationManager.getApplication().invokeLater(() -> { final MessageView messageView = MessageView.SERVICE.getInstance(project); messageView.runWhenInitialized(() -> { final FlutterConsole console = findOrCreate(project, module); console.watchProcess(process); console.bringToFront(); onReady.run(); }); }); }
Example #14
Source File: OpenInXcodeAction.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void openWithXcode(String path) { try { final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters(path); final OSProcessHandler handler = new OSProcessHandler(cmd); handler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(@NotNull final ProcessEvent event) { if (event.getExitCode() != 0) { FlutterMessages.showError("Error Opening", path); } } }); handler.startNotify(); } catch (ExecutionException ex) { FlutterMessages.showError( "Error Opening", "Exception: " + ex.getMessage()); } }
Example #15
Source File: RunnerUtil.java From react-native-console with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static final ConsoleView showHelperProcessRunContent(String header, OSProcessHandler runHandler, Project project, Executor defaultExecutor) { ProcessTerminatedListener.attach(runHandler); ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true); DefaultActionGroup toolbarActions = new DefaultActionGroup(); JPanel panel = new JPanel((LayoutManager) new BorderLayout()); panel.add((Component) consoleView.getComponent(), "Center"); ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("unknown", (ActionGroup) toolbarActions, false); toolbar.setTargetComponent(consoleView.getComponent()); panel.add((Component) toolbar.getComponent(), "West"); RunContentDescriptor runDescriptor = new RunContentDescriptor((ExecutionConsole) consoleView, (ProcessHandler) runHandler, (JComponent) panel, header, AllIcons.RunConfigurations.Application); AnAction[] consoleActions = consoleView.createConsoleActions(); toolbarActions.addAll((AnAction[]) Arrays.copyOf(consoleActions, consoleActions.length)); toolbarActions.add((AnAction) new StopProcessAction("Stop process", "Stop process", (ProcessHandler) runHandler)); toolbarActions.add((AnAction) new CloseAction(defaultExecutor, runDescriptor, project)); consoleView.attachToProcess((ProcessHandler) runHandler); // ExecutionManager.getInstance(environment.getProject()).getContentManager().showRunContent(environment.getExecutor(), runDescriptor); showConsole(project, defaultExecutor, runDescriptor); return (ConsoleView) consoleView; }
Example #16
Source File: FlutterBuildActionGroup.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static OSProcessHandler build(Project project, @NotNull PubRoot pubRoot, FlutterSdk sdk, BuildType buildType, String desc) { ProgressHelper progressHelper = new ProgressHelper(project); progressHelper.start(desc); OSProcessHandler processHandler = sdk.flutterBuild(pubRoot, buildType.type).startInConsole(project); if (processHandler == null) { progressHelper.done(); } else { processHandler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(@NotNull ProcessEvent event) { progressHelper.done(); int exitCode = event.getExitCode(); if (exitCode != 0) { FlutterMessages.showError("Error while building " + buildType, "`flutter build` returned: " + exitCode); } } }); } return processHandler; }
Example #17
Source File: FlutterCommandStartResult.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
public FlutterCommandStartResult(@NotNull FlutterCommandStartResultStatus status, @Nullable OSProcessHandler processHandler, @Nullable ExecutionException exception) { this.status = status; this.processHandler = processHandler; this.exception = exception; }
Example #18
Source File: InstallSdkAction.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void runCommand(@NotNull InstallCommand cmd) { try { handler = new OSProcessHandler(cmd.getCommandLine()); } catch (ExecutionException e) { cmd.onError(e); return; } cmd.registerTo(handler); handler.startNotify(); }
Example #19
Source File: InstallSdkAction.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void runCommand(@NotNull InstallCommand cmd) { try { handler = new OSProcessHandler(cmd.getCommandLine()); } catch (ExecutionException e) { cmd.onError(e); return; } cmd.registerTo(handler); handler.startNotify(); }
Example #20
Source File: FreelineUtil.java From freeline with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void processCommandline(final Project project, GeneralCommandLine commandLine) throws ExecutionException { final OSProcessHandler processHandler = new OSProcessHandler(commandLine); ProcessTerminatedListener.attach(processHandler); processHandler.startNotify(); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { processConsole(project, processHandler); } }); }
Example #21
Source File: FreeRunConfiguration.java From freeline with BSD 3-Clause "New" or "Revised" License | 5 votes |
@NotNull @Override protected ProcessHandler startProcess() throws ExecutionException { if (!FreelineUtil.hadInitFreeline(getProject())) { throw new CantRunException("Not yet initialized freeline code"); } // here just run one command: python freeline.py GeneralCommandLine commandLine = new GeneralCommandLine(); ExecutionEnvironment environment = getEnvironment(); commandLine.setWorkDirectory(environment.getProject().getBasePath()); commandLine.setExePath("python"); commandLine.addParameters("freeline.py"); return new OSProcessHandler(commandLine); }
Example #22
Source File: XQueryRunProfileState.java From intellij-xquery with Apache License 2.0 | 5 votes |
@NotNull @Override protected ProcessHandler startProcess() throws ExecutionException { ProcessHandlerFactory factory = ProcessHandlerFactory.getInstance(); OSProcessHandler processHandler = factory.createProcessHandler(createCommandLine()); ProcessTerminatedListener.attach(processHandler); return processHandler; }
Example #23
Source File: HaxeTestsRunner.java From intellij-haxe with Apache License 2.0 | 5 votes |
@Override protected RunContentDescriptor doExecute(@NotNull final Project project, @NotNull RunProfileState state, final RunContentDescriptor descriptor, @NotNull final ExecutionEnvironment environment) throws ExecutionException { final HaxeTestsConfiguration profile = (HaxeTestsConfiguration)environment.getRunProfile(); final Module module = profile.getConfigurationModule().getModule(); ModuleRootManager rootManager = ModuleRootManager.getInstance(module); VirtualFile[] roots = rootManager.getContentRoots(); return super.doExecute(project, new CommandLineState(environment) { @NotNull @Override protected ProcessHandler startProcess() throws ExecutionException { //actually only neko target is supported for tests HaxeTarget currentTarget = HaxeTarget.NEKO; final GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setWorkDirectory(PathUtil.getParentPath(module.getModuleFilePath())); commandLine.setExePath(currentTarget.getFlag()); final HaxeModuleSettings settings = HaxeModuleSettings.getInstance(module); String folder = settings.getOutputFolder() != null ? (settings.getOutputFolder() + "/release/") : ""; commandLine.addParameter(getFileNameWithCurrentExtension(currentTarget, folder + settings.getOutputFileName())); final TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(module.getProject()); consoleBuilder.addFilter(new ErrorFilter(module)); setConsoleBuilder(consoleBuilder); return new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()); } private String getFileNameWithCurrentExtension(HaxeTarget haxeTarget, String fileName) { if (haxeTarget != null) { return haxeTarget.getTargetFileNameWithExtension(FileUtil.getNameWithoutExtension(fileName)); } return fileName; } }, descriptor, environment); }
Example #24
Source File: BuckCommandHandler.java From Buck-IntelliJ-Plugin with Apache License 2.0 | 5 votes |
/** * Start the buck process. */ @Nullable protected Process startProcess() throws ExecutionException { synchronized (mProcessStateLock) { final ProcessHandler processHandler = createProcess(mCommandLine); mHandler = (OSProcessHandler) processHandler; return mHandler.getProcess(); } }
Example #25
Source File: BashCommandLineState.java From BashSupport with Apache License 2.0 | 5 votes |
@NotNull @Override protected ProcessHandler startProcess() throws ExecutionException { String workingDir = BashRunConfigUtil.findWorkingDir(runConfig); GeneralCommandLine cmd = BashRunConfigUtil.createCommandLine(workingDir, runConfig); if (!cmd.getEnvironment().containsKey("TERM")) { cmd.getEnvironment().put("TERM", "xterm-256color"); } OSProcessHandler processHandler = new KillableColoredProcessHandler(cmd); ProcessTerminatedListener.attach(processHandler, getEnvironment().getProject()); //fixme handle path macros return processHandler; }
Example #26
Source File: MongoCommandLineState.java From nosql4idea with Apache License 2.0 | 5 votes |
@NotNull @Override protected ProcessHandler startProcess() throws ExecutionException { GeneralCommandLine commandLine = generateCommandLine(); final OSProcessHandler processHandler = new ColoredProcessHandler(commandLine); ProcessTerminatedListener.attach(processHandler); return processHandler; }
Example #27
Source File: PantsIntegrationTestCase.java From intellij-pants-plugin with Apache License 2.0 | 5 votes |
@NotNull protected RunResult runWithConfiguration(RunConfiguration configuration) { PantsMakeBeforeRun.replaceDefaultMakeWithPantsMake(configuration); PantsMakeBeforeRun.setRunConfigurationWorkingDirectory(configuration); PantsJUnitRunnerAndConfigurationSettings runnerAndConfigurationSettings = new PantsJUnitRunnerAndConfigurationSettings(configuration); ExecutionEnvironmentBuilder environmentBuilder = ExecutionUtil.createEnvironment(DefaultRunExecutor.getRunExecutorInstance(), runnerAndConfigurationSettings); ExecutionEnvironment environment = environmentBuilder.build(); List<String> output = new ArrayList<>(); List<String> errors = new ArrayList<>(); ProcessAdapter processAdapter = new ProcessAdapter() { @Override public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) { if (outputType == ProcessOutputTypes.STDOUT) { output.add(event.getText()); } else if (outputType == ProcessOutputTypes.STDERR) { errors.add(event.getText()); } } }; ProgramRunnerUtil.executeConfiguration(environment, false, false); OSProcessHandler handler = (OSProcessHandler) environment.getContentToReuse().getProcessHandler(); handler.addProcessListener(processAdapter); assertTrue(handler.waitFor()); return new RunResult(handler.getExitCode(), output, errors); }
Example #28
Source File: DemoRunConfiguration.java From intellij-sdk-docs with Apache License 2.0 | 5 votes |
@Nullable @Override public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) { return new CommandLineState(executionEnvironment) { @NotNull @Override protected ProcessHandler startProcess() throws ExecutionException { GeneralCommandLine commandLine = new GeneralCommandLine(getOptions().getScriptName()); OSProcessHandler processHandler = ProcessHandlerFactory.getInstance().createColoredProcessHandler(commandLine); ProcessTerminatedListener.attach(processHandler); return processHandler; } }; }
Example #29
Source File: HaskellTestCommandLineState.java From intellij-haskforce with Apache License 2.0 | 5 votes |
@NotNull @Override protected OSProcessHandler startProcess() throws ExecutionException { ExecutionEnvironment env = getEnvironment(); GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setWorkDirectory(env.getProject().getBasePath()); // TODO: This should probably be a bit more generic than relying on `cabal test`. final String cabalPath = HaskellBuildSettings.getInstance(myConfig.getProject()).getCabalPath(); commandLine.setExePath(cabalPath); ParametersList parametersList = commandLine.getParametersList(); parametersList.add("test"); parametersList.addParametersString(myConfig.programArguments); return new OSProcessHandler(commandLine); }
Example #30
Source File: HaskellApplicationCommandLineState.java From intellij-haskforce with Apache License 2.0 | 5 votes |
@NotNull @Override protected OSProcessHandler startProcess() throws ExecutionException { ExecutionEnvironment env = getEnvironment(); GeneralCommandLine commandLine = new GeneralCommandLine(); commandLine.setWorkDirectory(env.getProject().getBasePath()); // TODO: This should probably be a bit more generic than relying on `cabal run`. final HaskellBuildSettings buildSettings = HaskellBuildSettings.getInstance(myConfig.getProject()); commandLine.setExePath(buildSettings.getCabalPath()); ParametersList parametersList = commandLine.getParametersList(); parametersList.add("run"); parametersList.add("--with-ghc=" + buildSettings.getGhcPath()); parametersList.addParametersString(myConfig.programArguments); return new OSProcessHandler(commandLine); }