use of com.intellij.execution.configurations.GeneralCommandLine 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.configurations.GeneralCommandLine 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.configurations.GeneralCommandLine 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.configurations.GeneralCommandLine in project flutter-intellij by flutter.
the class FlutterCommand method createGeneralCommandLine.
/**
* Creates the command line to run.
* <p>
* If a project is supplied, it will be used to determine the ANDROID_HOME variable for the subprocess.
*/
@NotNull
public GeneralCommandLine createGeneralCommandLine(@Nullable Project project) {
final GeneralCommandLine line = new GeneralCommandLine();
line.setCharset(CharsetToolkit.UTF8_CHARSET);
line.withEnvironment(FlutterSdkUtil.FLUTTER_HOST_ENV, FlutterSdkUtil.getFlutterHostEnvValue());
final String androidHome = IntelliJAndroidSdk.chooseAndroidHome(project, false);
if (androidHome != null) {
line.withEnvironment("ANDROID_HOME", androidHome);
}
line.setExePath(FileUtil.toSystemDependentName(sdk.getHomePath() + "/bin/" + FlutterSdkUtil.flutterScriptName()));
line.setWorkDirectory(workDir.getPath());
line.addParameter("--no-color");
line.addParameters(type.subCommand);
line.addParameters(args);
return line;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project flutter-intellij by flutter.
the class FlutterCommand method startProcess.
/**
* Starts a process that runs a flutter command, unless one is already running.
* <p>
* Returns the handler if successfully started.
*/
@Nullable
public OSProcessHandler startProcess(boolean sendAnalytics) {
try {
final GeneralCommandLine commandLine = createGeneralCommandLine(null);
LOG.info(commandLine.toString());
final OSProcessHandler handler = new OSProcessHandler(commandLine);
if (sendAnalytics) {
type.sendAnalyticsEvent();
}
return handler;
} catch (ExecutionException e) {
FlutterMessages.showError(type.title, FlutterBundle.message("flutter.command.exception.message", e.getMessage()));
return null;
}
}
Aggregations