Search in sources :

Example 76 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij-elixir by KronicDeth.

the class MixBuilder method runMix.

private static void runMix(@NotNull String elixirPath, @NotNull String mixPath, @Nullable String contentRootPath, boolean addDebugInfo, @NotNull CompileContext context) throws ProjectBuildException {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.withWorkDirectory(contentRootPath);
    commandLine.setExePath(elixirPath);
    commandLine.addParameter(mixPath);
    commandLine.addParameter("compile");
    if (!addDebugInfo) {
        commandLine.addParameter("--no-debug-info");
    }
    Process process;
    try {
        process = commandLine.createProcess();
    } catch (ExecutionException e) {
        throw new ProjectBuildException("Failed to run mix.", e);
    }
    BaseOSProcessHandler handler = new BaseOSProcessHandler(process, commandLine.getCommandLineString(), Charset.defaultCharset());
    ProcessAdapter adapter = new ElixirCompilerProcessAdapter(context, NAME, commandLine.getWorkDirectory().getPath());
    handler.addProcessListener(adapter);
    handler.startNotify();
    handler.waitFor();
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) BaseOSProcessHandler(com.intellij.execution.process.BaseOSProcessHandler)

Example 77 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project Intellij-Plugin by getgauge.

the class GaugeCommandLine method getInstance.

public static GeneralCommandLine getInstance(Module module, Project project) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    try {
        GaugeSettingsModel settings = GaugeUtil.getGaugeSettings();
        commandLine.setExePath(settings.getGaugePath());
        Map<String, String> environment = commandLine.getEnvironment();
        environment.put(Constants.GAUGE_HOME, settings.getHomePath());
    } catch (GaugeNotFoundException e) {
        commandLine.setExePath(Constants.GAUGE);
    } finally {
        commandLine.setWorkDirectory(project.getBasePath());
        if (module != null)
            commandLine.setWorkDirectory(GaugeUtil.moduleDir(module));
        return commandLine;
    }
}
Also used : GaugeNotFoundException(com.thoughtworks.gauge.exception.GaugeNotFoundException) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) GaugeSettingsModel(com.thoughtworks.gauge.settings.GaugeSettingsModel)

Example 78 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project teamcity-powershell by JetBrains.

the class PowerShellServiceUnix method enableExecution.

private static void enableExecution(@NotNull final File filePath) {
    final GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath("chmod");
    commandLine.addParameter("+x");
    commandLine.addParameter(filePath.getName());
    commandLine.setWorkDirectory(filePath.getParent());
    final ExecResult execResult = SimpleCommandLineProcessRunner.runCommand(commandLine, null);
    if (execResult.getExitCode() != 0) {
        LOG.warn("Failed to set executable attribute for " + filePath + ": chmod +x exit code is " + execResult.getExitCode());
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecResult(jetbrains.buildServer.ExecResult)

Example 79 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine 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 80 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine 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)

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