use of com.intellij.execution.process.ProcessAdapter in project android by JetBrains.
the class AndroidUtils method executeCommand.
@NotNull
public static ExecutionStatus executeCommand(@NotNull GeneralCommandLine commandLine, @Nullable final OutputProcessor processor, @Nullable WaitingStrategies.Strategy strategy) throws ExecutionException {
LOG.info(commandLine.getCommandLineString());
OSProcessHandler handler = new OSProcessHandler(commandLine);
final ProcessAdapter listener = new ProcessAdapter() {
@Override
public void onTextAvailable(final ProcessEvent event, final Key outputType) {
if (processor != null) {
final String message = event.getText();
processor.onTextAvailable(message);
}
}
};
if (!(strategy instanceof WaitingStrategies.DoNotWait)) {
handler.addProcessListener(listener);
}
handler.startNotify();
try {
if (!(strategy instanceof WaitingStrategies.WaitForever)) {
if (strategy instanceof WaitingStrategies.WaitForTime) {
handler.waitFor(((WaitingStrategies.WaitForTime) strategy).getTimeMs());
}
} else {
handler.waitFor();
}
} catch (ProcessCanceledException e) {
return ExecutionStatus.ERROR;
}
if (!handler.isProcessTerminated()) {
return ExecutionStatus.TIMEOUT;
}
if (!(strategy instanceof WaitingStrategies.DoNotWait)) {
handler.removeProcessListener(listener);
}
int exitCode = handler.getProcess().exitValue();
return exitCode == 0 ? ExecutionStatus.SUCCESS : ExecutionStatus.ERROR;
}
use of com.intellij.execution.process.ProcessAdapter 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.ProcessAdapter in project intellij-plugins by JetBrains.
the class FlexCommonUtils method getVersionOfAirSdkIncludedInFlexSdk.
@Nullable
public static String getVersionOfAirSdkIncludedInFlexSdk(final String flexSdkHomePath) {
final File adtFile = new File(flexSdkHomePath + "/lib/adt.jar");
if (!adtFile.isFile()) {
return null;
}
String version = ourAdtJarPathAndTimestampToVersion.get(Pair.create(adtFile.getPath(), adtFile.lastModified()));
if (version != null) {
return version;
}
try {
final Ref<String> versionRef = Ref.create();
final String javaExecutable = FileUtil.toSystemDependentName((SystemProperties.getJavaHome() + "/bin/java" + (SystemInfo.isWindows ? ".exe" : "")));
String[] cmdarray = { javaExecutable, "-jar", adtFile.getPath(), "-version" };
final Process process = Runtime.getRuntime().exec(cmdarray);
final BaseOSProcessHandler handler = new BaseOSProcessHandler(process, StringUtil.join(cmdarray, " "), Charset.defaultCharset());
handler.addProcessListener(new ProcessAdapter() {
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (outputType != ProcessOutputTypes.SYSTEM) {
parseAirVersionFromAdtOutput(event.getText().trim(), versionRef);
}
}
});
handler.startNotify();
handler.waitFor(3000);
if (!handler.isProcessTerminated()) {
handler.destroyProcess();
}
version = versionRef.get();
ourAdtJarPathAndTimestampToVersion.put(Pair.create(adtFile.getPath(), adtFile.lastModified()), version);
return version;
} catch (IOException e) {
/*ignore*/
}
return null;
}
use of com.intellij.execution.process.ProcessAdapter in project android by JetBrains.
the class AndroidCommonUtils method executeZipAlign.
@Nullable
public static String executeZipAlign(@NotNull String zipAlignPath, @NotNull File source, @NotNull File destination) {
List<String> commandLine = Arrays.asList(zipAlignPath, "-f", "4", source.getAbsolutePath(), destination.getAbsolutePath());
final ProcessBuilder processBuilder = new ProcessBuilder(commandLine);
BaseOSProcessHandler handler;
try {
handler = new BaseOSProcessHandler(processBuilder.start(), StringUtil.join(commandLine, " "), null);
} catch (IOException e) {
return e.getMessage();
}
final StringBuilder builder = new StringBuilder();
handler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
builder.append(event.getText());
}
});
handler.startNotify();
handler.waitFor();
int exitCode = handler.getProcess().exitValue();
return exitCode != 0 ? builder.toString() : null;
}
use of com.intellij.execution.process.ProcessAdapter 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();
}
Aggregations