Search in sources :

Example 11 with GeneralCommandLine

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

the class MixProjectRootStep method getMixPath.

/**
   * private methods
   * */
@NotNull
private static String getMixPath(@Nullable String directory) {
    if (directory != null) {
        File mix = new File(directory, "mix");
        if (mix.exists() && mix.canExecute()) {
            return mix.getPath();
        }
    }
    String output = "";
    GeneralCommandLine generalCommandLine = null;
    if (SystemInfo.isWindows) {
        generalCommandLine = new GeneralCommandLine("where");
        generalCommandLine.addParameter("mix.bat");
    } else if (SystemInfo.isMac || SystemInfo.isLinux || SystemInfo.isUnix) {
        generalCommandLine = new GeneralCommandLine("which");
        generalCommandLine.addParameter("mix");
    }
    if (generalCommandLine != null) {
        try {
            output = ScriptRunnerUtil.getProcessOutput(generalCommandLine);
        } catch (Exception ignored) {
            LOG.warn(ignored);
        }
    }
    return output.trim();
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) ExecutionException(com.intellij.execution.ExecutionException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with GeneralCommandLine

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

the class MixProjectRootStep method fetchDependencies.

private static void fetchDependencies(@NotNull final VirtualFile projectRoot, @NotNull final String mixPath) {
    final Project project = ProjectImportBuilder.getCurrentProject();
    String sdkPath = project != null ? ElixirSdkType.getSdkPath(project) : null;
    final String elixirPath = sdkPath != null ? JpsElixirSdkType.getScriptInterpreterExecutable(sdkPath).getAbsolutePath() : JpsElixirSdkType.getExecutableFileName(JpsElixirSdkType.SCRIPT_INTERPRETER);
    ProgressManager.getInstance().run(new Task.Modal(project, "Fetching dependencies", true) {

        @Override
        public void run(@NotNull final ProgressIndicator indicator) {
            indicator.setIndeterminate(true);
            GeneralCommandLine commandLine = new GeneralCommandLine();
            commandLine.withWorkDirectory(projectRoot.getCanonicalPath());
            commandLine.setExePath(elixirPath);
            commandLine.addParameter(mixPath);
            commandLine.addParameter("deps.get");
            try {
                OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getPreparedCommandLine(Platform.current()));
                handler.addProcessListener(new ProcessAdapter() {

                    @Override
                    public void onTextAvailable(ProcessEvent event, Key outputType) {
                        String text = event.getText();
                        indicator.setText2(text);
                    }
                });
                ProcessTerminatedListener.attach(handler);
                handler.startNotify();
                handler.waitFor();
                indicator.setText2("Refreshing");
            } catch (ExecutionException e) {
                LOG.warn(e);
            }
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Example 13 with GeneralCommandLine

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

the class ElixirSystemUtil method getProcessOutput.

@NotNull
public static ProcessOutput getProcessOutput(int timeout, @Nullable String workDir, @NotNull String exePath, @NotNull String... arguments) throws ExecutionException {
    if (workDir == null || !new File(workDir).isDirectory() || !new File(exePath).canExecute()) {
        return new ProcessOutput();
    }
    GeneralCommandLine cmd = new GeneralCommandLine();
    cmd.withWorkDirectory(workDir);
    cmd.setExePath(exePath);
    cmd.addParameters(arguments);
    return execute(cmd, timeout);
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with GeneralCommandLine

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

the class GroovyConsole method createProcessHandler.

private static ProcessHandler createProcessHandler(Module module) {
    try {
        final JavaParameters javaParameters = createJavaParameters(module);
        final GeneralCommandLine commandLine = javaParameters.toCommandLine();
        return new OSProcessHandler(commandLine) {

            @Override
            public boolean isSilentlyDestroyOnClose() {
                return true;
            }
        };
    } catch (ExecutionException e) {
        LOG.warn(e);
        return null;
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) ExecutionException(com.intellij.execution.ExecutionException)

Example 15 with GeneralCommandLine

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

the class SshTunnelRuntimeModule method buildTunnelCommandLine.

@NotNull
private GeneralCommandLine buildTunnelCommandLine(@NotNull String sshPath) {
    GeneralCommandLine result = new GeneralCommandLine(sshPath);
    boolean isPuttyLinkClient = StringUtil.endsWithIgnoreCase(FileUtil.getNameWithoutExtension(sshPath), "plink");
    SvnConfigurationState state = getState();
    // quiet mode
    if (!isPuttyLinkClient) {
        result.addParameter("-q");
    }
    result.addParameters(isPuttyLinkClient ? "-P" : "-p", String.valueOf(state.sshPort));
    if (!StringUtil.isEmpty(state.sshUserName)) {
        result.addParameters("-l", state.sshUserName);
    }
    if (SvnConfiguration.SshConnectionType.PRIVATE_KEY.equals(state.sshConnectionType) && !StringUtil.isEmpty(state.sshPrivateKeyPath)) {
        result.addParameters("-i", FileUtil.toSystemIndependentName(state.sshPrivateKeyPath));
    }
    return result;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) SvnConfigurationState(org.jetbrains.idea.svn.SvnConfigurationState) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)136 ExecutionException (com.intellij.execution.ExecutionException)42 File (java.io.File)35 NotNull (org.jetbrains.annotations.NotNull)35 ProcessOutput (com.intellij.execution.process.ProcessOutput)20 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 CapturingProcessHandler (com.intellij.execution.process.CapturingProcessHandler)10 Project (com.intellij.openapi.project.Project)10 Key (com.intellij.openapi.util.Key)10 IOException (java.io.IOException)10 Nullable (org.jetbrains.annotations.Nullable)10 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)7 Sdk (com.intellij.openapi.projectRoots.Sdk)7 PsiFile (com.intellij.psi.PsiFile)7 Test (org.junit.Test)6 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)5 ArrayList (java.util.ArrayList)5 RunResult (org.jetbrains.kotlin.android.tests.run.RunResult)5