use of com.intellij.execution.process.ProcessEvent in project intellij-plugins by JetBrains.
the class DartPubActionBase method showPubOutputConsole.
private static void showPubOutputConsole(@NotNull final Module module, @NotNull final GeneralCommandLine command, @NotNull final OSProcessHandler processHandler, @NotNull final VirtualFile pubspecYamlFile, @NotNull final String actionTitle) {
final ConsoleView console;
PubToolWindowContentInfo info = findExistingInfoForCommand(module.getProject(), command);
if (info != null) {
// rerunning the same pub command in the same tool window tab (corresponding tool window action invoked)
console = info.console;
console.clear();
} else {
console = createConsole(module.getProject(), pubspecYamlFile);
info = new PubToolWindowContentInfo(module, pubspecYamlFile, command, actionTitle, console);
final ActionToolbar actionToolbar = createToolWindowActionsBar(info);
final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(false, true);
toolWindowPanel.setContent(console.getComponent());
toolWindowPanel.setToolbar(actionToolbar.getComponent());
final Content content = ContentFactory.SERVICE.getInstance().createContent(toolWindowPanel.getComponent(), actionTitle, true);
content.putUserData(PUB_TOOL_WINDOW_CONTENT_INFO_KEY, info);
Disposer.register(content, console);
final ContentManager contentManager = MessageView.SERVICE.getInstance(module.getProject()).getContentManager();
removeOldTabs(contentManager);
contentManager.addContent(content);
contentManager.setSelectedContent(content);
final ToolWindow toolWindow = ToolWindowManager.getInstance(module.getProject()).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
toolWindow.activate(null, true);
}
info.rerunPubCommandAction.setProcessHandler(processHandler);
info.stopProcessAction.setProcessHandler(processHandler);
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(final ProcessEvent event) {
console.print(IdeBundle.message("finished.with.exit.code.text.message", event.getExitCode()), ConsoleViewContentType.SYSTEM_OUTPUT);
}
});
console.print(DartBundle.message("working.dir.0", FileUtil.toSystemDependentName(pubspecYamlFile.getParent().getPath())) + "\n", ConsoleViewContentType.SYSTEM_OUTPUT);
console.attachToProcess(processHandler);
processHandler.startNotify();
}
use of com.intellij.execution.process.ProcessEvent in project android by JetBrains.
the class Haxm method runInstaller.
private void runInstaller(InstallContext installContext, GeneralCommandLine commandLine) {
try {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null) {
progressIndicator.setIndeterminate(true);
progressIndicator.setText(RUNNING_INTEL_HAXM_INSTALLER_MESSAGE);
}
installContext.print(RUNNING_INTEL_HAXM_INSTALLER_MESSAGE + "\n", ConsoleViewContentType.SYSTEM_OUTPUT);
CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
final StringBuffer output = new StringBuffer();
process.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
output.append(event.getText());
super.onTextAvailable(event, outputType);
}
});
myProgressStep.attachToProcess(process);
int exitCode = process.runProcess().getExitCode();
// More testing of bash scripts invocation with intellij process wrappers might be useful.
if (exitCode != INTEL_HAXM_INSTALLER_EXIT_CODE_SUCCESS) {
// According to the installer docs for Windows, installer may signify that a reboot is required
if (SystemInfo.isWindows && exitCode == INTEL_HAXM_INSTALLER_EXIT_CODE_REBOOT_REQUIRED) {
String rebootMessage = "Reboot required: HAXM installation succeeded, however the installer reported that a reboot is " + "required in order for the changes to take effect";
installContext.print(rebootMessage, ConsoleViewContentType.NORMAL_OUTPUT);
AccelerationErrorSolution.promptAndRebootAsync(rebootMessage, ModalityState.NON_MODAL);
myHaxmInstallerSuccessfullyCompleted = true;
return;
}
// HAXM is not required so we do not stop setup process if this install failed.
if (myInstallationIntention == HaxmInstallationIntention.UNINSTALL) {
installContext.print("HAXM uninstallation failed", ConsoleViewContentType.ERROR_OUTPUT);
} else {
installContext.print(String.format("HAXM installation failed. To install HAXM follow the instructions found at: %s", SystemInfo.isWindows ? FirstRunWizardDefaults.HAXM_WINDOWS_INSTALL_URL : FirstRunWizardDefaults.HAXM_MAC_INSTALL_URL), ConsoleViewContentType.ERROR_OUTPUT);
}
Matcher m = Pattern.compile("installation log:\\s*\"(.*)\"").matcher(output.toString());
if (m.find()) {
String file = m.group(1);
installContext.print(String.format("Installer log is located at %s", file), ConsoleViewContentType.ERROR_OUTPUT);
try {
installContext.print("Installer log contents:\n", ConsoleViewContentType.ERROR_OUTPUT);
installContext.print(FileUtil.loadFile(new File(file), "UTF-16"), ConsoleViewContentType.NORMAL_OUTPUT);
} catch (IOException e) {
installContext.print("Failed to read installer output log.\n", ConsoleViewContentType.ERROR_OUTPUT);
}
}
progressIndicator.setFraction(1);
myHaxmInstallerSuccessfullyCompleted = false;
return;
}
progressIndicator.setFraction(1);
myHaxmInstallerSuccessfullyCompleted = true;
} catch (ExecutionException e) {
installContext.print("Unable to run Intel HAXM installer: " + e.getMessage() + "\n", ConsoleViewContentType.ERROR_OUTPUT);
LOG.warn(e);
}
}
use of com.intellij.execution.process.ProcessEvent in project flutter-intellij by flutter.
the class AndroidEmulator method startEmulator.
public void startEmulator() {
final VirtualFile emulator = androidSdk.getEmulatorToolExecutable();
if (emulator == null) {
FlutterMessages.showError("Error Opening Emulator", "Unable to locate the emulator tool in the Android SDK.");
return;
}
final String emulatorPath = emulator.getCanonicalPath();
assert (emulatorPath != null);
final GeneralCommandLine cmd = new GeneralCommandLine().withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE).withWorkDirectory(androidSdk.getHome().getCanonicalPath()).withExePath(emulatorPath).withParameters("-avd", this.id);
try {
final StringBuilder stdout = new StringBuilder();
final OSProcessHandler process = new OSProcessHandler(cmd);
process.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (outputType == ProcessOutputTypes.STDERR || outputType == ProcessOutputTypes.STDOUT) {
stdout.append(event.getText());
}
}
public void processTerminated(ProcessEvent event) {
final int exitCode = event.getExitCode();
if (exitCode != 0) {
final String message = stdout.length() == 0 ? "Android emulator terminated with exit code " + exitCode : stdout.toString().trim();
FlutterMessages.showError("Error Opening Emulator", message);
}
}
});
process.startNotify();
} catch (ExecutionException | RuntimeException e) {
FlutterMessages.showError("Error Opening Emulator", e.toString());
}
}
use of com.intellij.execution.process.ProcessEvent in project flutter-intellij by flutter.
the class AndroidSdk method getEmulators.
@NotNull
public List<AndroidEmulator> getEmulators() {
// Execute $ANDROID_HOME/tools/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 2000ms.
if (!process.waitFor(2000)) {
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) {
LOG.warn("Error listing android emulators", e);
return Collections.emptyList();
}
}
use of com.intellij.execution.process.ProcessEvent in project flutter-intellij by flutter.
the class FlutterConsole method watchProcess.
/**
* 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);
}
Aggregations