Search in sources :

Example 81 with GeneralCommandLine

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());
    }
}
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)

Example 82 with GeneralCommandLine

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()));
    }
}
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)

Example 83 with GeneralCommandLine

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;
    }
}
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) Key(com.intellij.openapi.util.Key) Nullable(org.jetbrains.annotations.Nullable)

Example 84 with GeneralCommandLine

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;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with GeneralCommandLine

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;
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)179 ExecutionException (com.intellij.execution.ExecutionException)70 NotNull (org.jetbrains.annotations.NotNull)47 File (java.io.File)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)25 ProcessOutput (com.intellij.execution.process.ProcessOutput)25 Key (com.intellij.openapi.util.Key)18 ProcessEvent (com.intellij.execution.process.ProcessEvent)15 Project (com.intellij.openapi.project.Project)15 IOException (java.io.IOException)15 Nullable (org.jetbrains.annotations.Nullable)15 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)14 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)13 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)12 Sdk (com.intellij.openapi.projectRoots.Sdk)9 PsiFile (com.intellij.psi.PsiFile)9 ArrayList (java.util.ArrayList)9 Module (com.intellij.openapi.module.Module)8 ProcessHandler (com.intellij.execution.process.ProcessHandler)7