use of com.intellij.execution.process.OSProcessHandler in project intellij-community by JetBrains.
the class AppletConfiguration method getState.
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) throws ExecutionException {
return new JavaCommandLineState(env) {
private AppletHtmlFile myHtmlURL = null;
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
final JavaParameters params = new JavaParameters();
myHtmlURL = getHtmlURL();
if (myHtmlURL != null) {
final int classPathType = myHtmlURL.isHttp() ? JavaParameters.JDK_ONLY : JavaParameters.JDK_AND_CLASSES;
final RunConfigurationModule runConfigurationModule = getConfigurationModule();
JavaParametersUtil.configureModule(runConfigurationModule, params, classPathType, ALTERNATIVE_JRE_PATH_ENABLED ? ALTERNATIVE_JRE_PATH : null);
final String policyFileParameter = getPolicyFileParameter();
if (policyFileParameter != null) {
params.getVMParametersList().add(policyFileParameter);
}
params.getVMParametersList().addParametersString(VM_PARAMETERS);
params.setMainClass("sun.applet.AppletViewer");
params.getProgramParametersList().add(myHtmlURL.getUrl());
}
return params;
}
@Override
@NotNull
protected OSProcessHandler startProcess() throws ExecutionException {
final OSProcessHandler handler = super.startProcess();
final AppletHtmlFile htmlUrl = myHtmlURL;
if (htmlUrl != null) {
handler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
htmlUrl.deleteFile();
}
});
}
return handler;
}
};
}
use of com.intellij.execution.process.OSProcessHandler in project android by JetBrains.
the class AndroidRunDdmsAction method doLaunchDdms.
private static void doLaunchDdms(GeneralCommandLine commandLine, final Project project, final boolean adbServiceWasEnabled) {
try {
ourProcessHandler = new OSProcessHandler(commandLine);
ourProcessHandler.startNotify();
ourProcessHandler.waitFor();
} catch (ExecutionException e) {
LOG.info(e);
} finally {
ourProcessHandler = null;
if (adbServiceWasEnabled) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (project.isDisposed()) {
return;
}
AndroidEnableAdbServiceAction.setAdbServiceEnabled(project, true);
// trigger creation of new bridge
File adb = AndroidSdkUtils.getAdb(project);
if (adb != null) {
AdbService.getInstance().getDebugBridge(adb);
}
}
});
}
}
}
use of com.intellij.execution.process.OSProcessHandler 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.OSProcessHandler 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.OSProcessHandler 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());
}
}
Aggregations