Java Code Examples for com.intellij.execution.process.OSProcessHandler#waitFor()
The following examples show how to use
com.intellij.execution.process.OSProcessHandler#waitFor() .
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: 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 2
Source File: AndroidSdk.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
@NotNull public List<AndroidEmulator> getEmulators() { // Execute $ANDROID_HOME/emulator/emulator -list-avds and parse the results. final VirtualFile emulator = getEmulatorToolExecutable(); if (emulator == null) { return Collections.emptyList(); } final String emulatorPath = emulator.getCanonicalPath(); assert (emulatorPath != null); final GeneralCommandLine cmd = new GeneralCommandLine() .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE) .withWorkDirectory(home.getCanonicalPath()) .withExePath(emulatorPath) .withParameters("-list-avds"); try { final StringBuilder stringBuilder = new StringBuilder(); final OSProcessHandler process = new OSProcessHandler(cmd); process.addProcessListener(new ProcessAdapter() { @Override public void onTextAvailable(ProcessEvent event, Key outputType) { if (outputType == ProcessOutputTypes.STDOUT) { stringBuilder.append(event.getText()); } } }); process.startNotify(); // We wait a maximum of 10s. if (!process.waitFor(10000)) { return Collections.emptyList(); } final Integer exitCode = process.getExitCode(); if (exitCode == null || process.getExitCode() != 0) { return Collections.emptyList(); } // 'emulator -list-avds' results are in the form "foo\nbar\nbaz\n". final List<AndroidEmulator> emulators = new ArrayList<>(); for (String str : stringBuilder.toString().split("\n")) { str = str.trim(); if (str.isEmpty()) { continue; } emulators.add(new AndroidEmulator(this, str)); } return emulators; } catch (ExecutionException | RuntimeException e) { FlutterUtils.warn(LOG, "Error listing android emulators", e); return Collections.emptyList(); } }
Example 3
Source File: AndroidSdk.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 4 votes |
@NotNull public List<AndroidEmulator> getEmulators() { // Execute $ANDROID_HOME/emulator/emulator -list-avds and parse the results. final VirtualFile emulator = getEmulatorToolExecutable(); if (emulator == null) { return Collections.emptyList(); } final String emulatorPath = emulator.getCanonicalPath(); assert (emulatorPath != null); final GeneralCommandLine cmd = new GeneralCommandLine() .withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE) .withWorkDirectory(home.getCanonicalPath()) .withExePath(emulatorPath) .withParameters("-list-avds"); try { final StringBuilder stringBuilder = new StringBuilder(); final OSProcessHandler process = new OSProcessHandler(cmd); process.addProcessListener(new ProcessAdapter() { @Override public void onTextAvailable(ProcessEvent event, Key outputType) { if (outputType == ProcessOutputTypes.STDOUT) { stringBuilder.append(event.getText()); } } }); process.startNotify(); // We wait a maximum of 10s. if (!process.waitFor(10000)) { return Collections.emptyList(); } final Integer exitCode = process.getExitCode(); if (exitCode == null || process.getExitCode() != 0) { return Collections.emptyList(); } // 'emulator -list-avds' results are in the form "foo\nbar\nbaz\n". final List<AndroidEmulator> emulators = new ArrayList<>(); for (String str : stringBuilder.toString().split("\n")) { str = str.trim(); if (str.isEmpty()) { continue; } emulators.add(new AndroidEmulator(this, str)); } return emulators; } catch (ExecutionException | RuntimeException e) { FlutterUtils.warn(LOG, "Error listing android emulators", e); return Collections.emptyList(); } }
Example 4
Source File: PluginGeneratorUtil.java From idea-php-shopware-plugin with MIT License | 4 votes |
public static void installPlugin(@NotNull Project project, @NotNull PluginGeneratorSettings settings) { // download cli tools, if not existing locally VirtualFile cliFile = getCliToolsPharFile(project); if (cliFile == null) { showErrorNotification(project, "No CLI-Tools phar found"); return; } List<String> commands = generateCommand(settings); String[] myCommand = ArrayUtil.toStringArray(commands); final StringBuilder outputBuilder = new StringBuilder(); try { OSProcessHandler processHandler = ScriptRunnerUtil.execute(myCommand[0], project.getBaseDir().getPath(), null, Arrays.copyOfRange(myCommand, 1, myCommand.length)); processHandler.addProcessListener(new ProcessAdapter() { @Override public void onTextAvailable(@NotNull ProcessEvent event, @NotNull com.intellij.openapi.util.Key outputType) { String text = event.getText(); outputBuilder.append(text); } }); processHandler.startNotify(); for (;;){ boolean finished = processHandler.waitFor(CHECKING_TIMEOUT_IN_MILLISECONDS); if (finished) { break; } } } catch (ExecutionException e) { showErrorNotification(project, e.getMessage()); return; } String output = outputBuilder.toString(); if (output.toLowerCase().contains("exception")) { String message = SymfonyInstallerUtil.formatExceptionMessage(output); if(message == null) { message = "The unexpected happens..."; } showErrorNotification(project, message); return; } // delete cli tools FileUtil.delete(VfsUtil.virtualToIoFile(cliFile)); // move into correct plugin folder String newDir = project.getBasePath() + "/engine/Shopware/Plugins/Local/" + settings.getNamespace() + "/" + settings.getPluginName(); if (FileUtil.canWrite(newDir)) { return; } FileUtil.createDirectory(new File(newDir)); FileUtil.moveDirWithContent(new File(project.getBasePath() + "/" + settings.getPluginName()), new File(newDir)); // open bootstrap file VirtualFile fileByIoFile = VfsUtil.findFileByIoFile(new File(newDir + "/Bootstrap.php"), true); if(fileByIoFile == null) { return; } final PsiFile file = PsiManager.getInstance(project).findFile(fileByIoFile); if (file == null) { return; } IdeHelper.navigateToPsiElement(file); }