use of com.intellij.execution.process.ProcessEvent in project flutter-intellij by flutter.
the class OpenInXcodeAction method openWithXcode.
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(final ProcessEvent event) {
if (event.getExitCode() != 0) {
FlutterMessages.showError("Error Opening", path);
}
}
});
handler.startNotify();
} catch (ExecutionException ex) {
FlutterMessages.showError("Error Opening", "Exception: " + ex.getMessage());
}
}
use of com.intellij.execution.process.ProcessEvent in project flutter-intellij by flutter.
the class OpenSimulatorAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
try {
final GeneralCommandLine cmd = new GeneralCommandLine().withExePath("open").withParameters("-a", "Simulator.app");
final OSProcessHandler handler = new OSProcessHandler(cmd);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(final ProcessEvent event) {
if (event.getExitCode() != 0) {
final String msg = event.getText() != null ? event.getText() : "Process error - exit code: (" + event.getExitCode() + ")";
FlutterMessages.showError("Error Opening Simulator", msg);
}
}
});
handler.startNotify();
} catch (ExecutionException e) {
FlutterMessages.showError("Error Opening Simulator", FlutterBundle.message("flutter.command.exception.message", e.getMessage()));
}
}
use of com.intellij.execution.process.ProcessEvent in project flutter-intellij by flutter.
the class System method which.
/**
* Locate a given command-line tool given its name.
*/
@Nullable
public static String which(String toolName) {
final String whichCommandName = SystemInfo.isWindows ? "where" : "which";
final GeneralCommandLine cmd = new GeneralCommandLine().withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE).withExePath(whichCommandName).withParameters(toolName);
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 null;
}
final Integer exitCode = process.getExitCode();
if (exitCode == null || process.getExitCode() != 0) {
return null;
}
final String[] results = stringBuilder.toString().split("\n");
return results.length == 0 ? null : results[0].trim();
} catch (ExecutionException | RuntimeException e) {
return null;
}
}
use of com.intellij.execution.process.ProcessEvent in project moe-ide-integration by multi-os-engine.
the class MOERunProfileState method createProcessHandler.
@NotNull
private OSProcessHandler createProcessHandler() throws ExecutionException {
if (runConfiguration.configuration() == null) {
throw new ExecutionException("Invalid build configuration for " + runConfiguration.getClass().getName());
} else if (runConfiguration.architecture() == null) {
throw new ExecutionException("Invalid architecture for " + runConfiguration.getClass().getName());
}
final MOEGradleRunner gradleRunner = new MOEGradleRunner(runConfiguration);
final boolean isDebug = runConfiguration.getActionType().equals("Debug");
final GeneralCommandLine commandLine = gradleRunner.construct(isDebug, true);
final OSProcessHandler handler = new MOEOSProcessHandler(commandLine);
handler.setShouldDestroyProcessRecursively(true);
final MOETestResultParser parser = new MOETestResultParser(new MOETestListener(this));
final boolean isTest = runConfiguration.runJUnitTests();
handler.addProcessListener(new ProcessListener() {
@Override
public void startNotified(ProcessEvent event) {
}
@Override
public void processTerminated(ProcessEvent event) {
}
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
}
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String text = event.getText();
if (isTest) {
parser.addOutput(text);
}
if (text.contains("ApplicationVerificationFailed")) {
MOEToolWindow.getInstance(project).balloon(MessageType.ERROR, "Application installation failed. Please check log for details...");
MOEToolWindow.getInstance(project).log("Application installation failed. Please make sure you have correct bundle id in your Info.plist file.");
}
}
});
return handler;
}
use of com.intellij.execution.process.ProcessEvent in project moe-ide-integration by multi-os-engine.
the class MOEGradleRunner method buildProject.
private void buildProject(MOEGradleInvocationResult result) {
final Stopwatch stopwatch = Stopwatch.createUnstarted();
stopwatch.start();
String errorMessage = null;
try {
LOG.debug("Start build process");
final org.moe.idea.compiler.MOEGradleRunner gradleRunner = new org.moe.idea.compiler.MOEGradleRunner(runConfig);
final boolean isDebug = runConfig.getActionType().equals("Debug");
boolean isMaven = ModuleUtils.isMOEMavenModule(runConfig.module());
final MOEToolWindow toolWindow = MOEToolWindow.getInstance(runConfig.getProject());
if (!isMaven) {
final GeneralCommandLine commandLine = gradleRunner.construct(isDebug, false);
final OSProcessHandler handler = new OSProcessHandler(commandLine);
handler.setShouldDestroyProcessRecursively(true);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
if (ProcessOutputTypes.STDERR.equals(outputType)) {
toolWindow.error(event.getText());
} else if (ProcessOutputTypes.STDOUT.equals(outputType)) {
toolWindow.log(event.getText());
}
}
});
handler.startNotify();
// Start and wait
handler.waitFor();
int returnCode = handler.getProcess().exitValue();
// Show on failure
if (returnCode != 0) {
toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
errorMessage = "Multi-OS Engine module build failed";
}
} else {
MOEMavenBuildTask mavenTask = new MOEMavenBuildTask(runConfig, "Building " + runConfig.moduleName(), true);
boolean res = mavenTask.runTask();
if (!res) {
toolWindow.balloon(MessageType.ERROR, "BUILD FAILED");
errorMessage = "Multi-OS Engine module build failed";
}
}
if (errorMessage == null) {
result.setBuildSuccessful(true);
} else {
result.setBuildSuccessful(false);
result.setErrorMessage(errorMessage);
}
} catch (Exception e) {
result.setBuildSuccessful(false);
result.setErrorMessage(String.format("Error while building %s .%n", e.getMessage()));
} finally {
stopwatch.stop();
}
}
Aggregations