use of com.intellij.execution.process.OSProcessHandler in project flutter-intellij by flutter.
the class OpenInAndroidStudioAction method openFileInStudio.
private static void openFileInStudio(@NotNull VirtualFile file, @NotNull String androidStudioPath) {
try {
final GeneralCommandLine cmd;
if (SystemInfo.isMac) {
cmd = new GeneralCommandLine().withExePath("open").withParameters("-a", androidStudioPath, file.getPath());
} else {
cmd = new GeneralCommandLine().withExePath(androidStudioPath).withParameters(file.getPath());
}
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", file.getPath());
}
}
});
handler.startNotify();
} catch (ExecutionException ex) {
FlutterMessages.showError("Error Opening", "Exception: " + ex.getMessage());
}
}
use of com.intellij.execution.process.OSProcessHandler in project flutter-intellij by flutter.
the class FlutterApp method start.
/**
* Creates a process that will launch the flutter app.
* <p>
* (Assumes we are launching it in --machine mode.)
*/
@NotNull
public static FlutterApp start(@NotNull ExecutionEnvironment env, @NotNull Project project, @Nullable Module module, @NotNull RunMode mode, @NotNull FlutterDevice device, @NotNull GeneralCommandLine command, @NotNull String analyticsStart, @NotNull String analyticsStop) throws ExecutionException {
LOG.info(analyticsStart + " " + project.getName() + " (" + mode.mode() + ")");
LOG.info(command.toString());
final ProcessHandler process = new OSProcessHandler(command);
Disposer.register(project, process::destroyProcess);
// Send analytics for the start and stop events.
FlutterInitializer.sendAnalyticsAction(analyticsStart);
final DaemonApi api = new DaemonApi(process);
final FlutterApp app = new FlutterApp(project, module, mode, device, process, env, api);
process.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(@NotNull ProcessEvent event) {
LOG.info(analyticsStop + " " + project.getName() + " (" + mode.mode() + ")");
FlutterInitializer.sendAnalyticsAction(analyticsStop);
// Send analytics about whether this session used the reload workflow, the restart workflow, or neither.
final String workflowType = app.reloadCount > 0 ? "reload" : (app.restartCount > 0 ? "restart" : "none");
FlutterInitializer.getAnalytics().sendEvent("workflow", workflowType);
}
});
api.listen(process, new io.flutter.run.daemon.FlutterAppListener(app, project));
return app;
}
use of com.intellij.execution.process.OSProcessHandler in project moe-ide-integration by multi-os-engine.
the class MOERefreshXcodeProject method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Module module = (Module) dataContext.getData(LangDataKeys.MODULE.getName());
if (module == null) {
Messages.showErrorDialog("Failed to locate module", "Injecting/Refreshing Xcode Settings Error");
return;
}
boolean isMaven = ModuleUtils.isMOEMavenModule(module);
if (!isMaven) {
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
if (progress == null) {
progress = new EmptyProgressIndicator();
}
progress.pushState();
try {
progress.setText(ACTION_PROGRESS_LABEL);
runInternal();
} catch (final Throwable t) {
t.printStackTrace(System.err);
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
String message = t.getMessage();
if (message == null || message.length() == 0) {
message = "Unknown error";
}
Messages.showErrorDialog(message, "Injecting/Refreshing Xcode Settings Error");
final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
toolWindow.show();
}
});
} finally {
progress.popState();
}
}
private void runInternal() throws IOException, ExecutionException {
final GeneralCommandLine commandLine = MOEGradleRunner.construct(module, "moeUpdateXcodeSettings");
final OSProcessHandler handler = new OSProcessHandler(commandLine);
handler.setShouldDestroyProcessRecursively(true);
// Configure output
final MOEToolWindow toolWindow = MOEToolWindow.getInstance(module.getProject());
toolWindow.clear();
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();
final int exitValue = handler.getProcess().exitValue();
if (exitValue != 0) {
throw new IOException(ACTION_TITLE + " finished with non-zero exit value (" + exitValue + ")");
}
}
}, ACTION_TITLE, true, module.getProject());
} else {
CompilerTask compilerTask = new CompilerTask(module.getProject(), "", false, true, true, true);
compilerTask.start(new Runnable() {
@Override
public void run() {
MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
task.setGoal("moe:updateXcodeSettings");
if (!task.runTask()) {
ModuleUtils.runInDispatchedThread(new Runnable() {
@Override
public void run() {
Messages.showErrorDialog("Unable to refresh Xcode project", "Injecting/Refreshing Xcode Settings Error");
}
});
}
}
}, null);
ModuleUtils.runInDispatchedThread(new Runnable() {
@Override
public void run() {
MOEMavenTask task = new MOEMavenTask(module, ACTION_TITLE, false);
task.setGoal("moe:updateXcodeSettings");
if (!task.runTask()) {
Messages.showErrorDialog("Unable to refresh Xcode project", "Injecting/Refreshing Xcode Settings Error");
}
}
});
}
}
use of com.intellij.execution.process.OSProcessHandler in project moe-ide-integration by multi-os-engine.
the class MOEMavenExternalExecutor method execute.
public boolean execute(final ProgressIndicator indicator) {
displayProgress();
try {
if (myParameterCreationError != null) {
throw myParameterCreationError;
}
myProcessHandler = new OSProcessHandler(myJavaParameters.toCommandLine()) {
@Override
public void notifyTextAvailable(String text, Key outputType) {
// todo move this logic to ConsoleAdapter class
if (!myConsole.isSuppressed(text)) {
super.notifyTextAvailable(text, outputType);
}
updateProgress(indicator, text);
}
};
myProcessHandler.setShouldDestroyProcessRecursively(true);
myConsole.attachToProcess(myProcessHandler);
} catch (ExecutionException e) {
myConsole.systemMessage(MavenServerConsole.LEVEL_FATAL, RunnerBundle.message("external.startup.failed", e.getMessage()), null);
return false;
}
start();
IndicatorHandler indicatorHandler = new IndicatorHandler(indicator, this);
indicatorHandler.start();
readProcessOutput();
stop();
indicatorHandler.stop();
return printExitSummary();
}
use of com.intellij.execution.process.OSProcessHandler in project clion-embedded-arm by elmot.
the class OpenOcdLauncher method createProcess.
@Override
protected ProcessHandler createProcess(@NotNull CommandLineState commandLineState) throws ExecutionException {
File runFile = findRunFile(commandLineState);
findOpenOcdAction(commandLineState.getEnvironment().getProject()).stopOpenOcd();
try {
GeneralCommandLine commandLine = OpenOcdComponent.createOcdCommandLine(commandLineState.getEnvironment().getProject(), runFile, "reset", true);
OSProcessHandler osProcessHandler = new OSProcessHandler(commandLine);
osProcessHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(@NotNull ProcessEvent event) {
super.processTerminated(event);
Project project = commandLineState.getEnvironment().getProject();
if (event.getExitCode() == 0) {
Informational.showSuccessfulDownloadNotification(project);
} else {
Informational.showFailedDownloadNotification(project);
}
}
});
return osProcessHandler;
} catch (ConfigurationException e) {
Messages.showErrorDialog(getProject(), e.getLocalizedMessage(), e.getTitle());
throw new ExecutionException(e);
}
}
Aggregations