Search in sources :

Example 16 with OSProcessHandler

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;
        }
    };
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler)

Example 17 with OSProcessHandler

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);
                    }
                }
            });
        }
    }
}
Also used : OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File)

Example 18 with OSProcessHandler

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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 19 with OSProcessHandler

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();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ArrayList(java.util.ArrayList) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with OSProcessHandler

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());
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

OSProcessHandler (com.intellij.execution.process.OSProcessHandler)55 ExecutionException (com.intellij.execution.ExecutionException)25 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)24 ProcessEvent (com.intellij.execution.process.ProcessEvent)24 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)23 NotNull (org.jetbrains.annotations.NotNull)18 Key (com.intellij.openapi.util.Key)14 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 Module (com.intellij.openapi.module.Module)5 Sdk (com.intellij.openapi.projectRoots.Sdk)5 IOException (java.io.IOException)5 ProgramRunner (com.intellij.execution.runners.ProgramRunner)4 Nullable (org.jetbrains.annotations.Nullable)4 Executor (com.intellij.execution.Executor)3 RunContentExecutor (com.intellij.execution.RunContentExecutor)3 KillableColoredProcessHandler (com.intellij.execution.process.KillableColoredProcessHandler)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3