Search in sources :

Example 21 with GeneralCommandLine

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

the class Pep8ExternalAnnotator method doAnnotate.

@Nullable
@Override
public Results doAnnotate(State collectedInfo) {
    if (collectedInfo == null)
        return null;
    ArrayList<String> options = Lists.newArrayList();
    if (!collectedInfo.ignoredErrors.isEmpty()) {
        options.add("--ignore=" + DEFAULT_IGNORED_ERRORS + "," + StringUtil.join(collectedInfo.ignoredErrors, ","));
    }
    if (collectedInfo.hangClosingBrackets) {
        options.add("--hang-closing");
    }
    options.add("--max-line-length=" + collectedInfo.margin);
    options.add("-");
    GeneralCommandLine cmd = PythonHelper.PYCODESTYLE.newCommandLine(collectedInfo.interpreterPath, options);
    ProcessOutput output = PySdkUtil.getProcessOutput(cmd, new File(collectedInfo.interpreterPath).getParent(), ImmutableMap.of("PYTHONBUFFERED", "1"), 10000, collectedInfo.fileText.getBytes(), false);
    Results results = new Results(collectedInfo.level);
    if (output.isTimeout()) {
        LOG.info("Timeout running pycodestyle.py");
    } else if (output.getStderrLines().isEmpty()) {
        for (String line : output.getStdoutLines()) {
            final Problem problem = parseProblem(line);
            if (problem != null) {
                results.problems.add(problem);
            }
        }
    } else if (((ApplicationInfoImpl) ApplicationInfo.getInstance()).isEAP()) {
        LOG.info("Error running pycodestyle.py: " + output.getStderr());
    }
    return results;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ApplicationInfoImpl(com.intellij.openapi.application.impl.ApplicationInfoImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with GeneralCommandLine

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

the class PythonTask method createProcess.

/**
   * @param env environment variables to be passed to process or null if nothing should be passed
   */
public ProcessHandler createProcess(@Nullable final Map<String, String> env) throws ExecutionException {
    final GeneralCommandLine commandLine = createCommandLine();
    if (env != null) {
        commandLine.getEnvironment().putAll(env);
    }
    // To support UTF-8 output
    PydevConsoleRunner.setCorrectStdOutEncoding(commandLine, myModule.getProject());
    ProcessHandler handler;
    if (PySdkUtil.isRemote(mySdk)) {
        assert mySdk != null;
        handler = new PyRemoteProcessStarter().startRemoteProcess(mySdk, commandLine, myModule.getProject(), null);
    } else {
        EncodingEnvironmentUtil.setLocaleEnvironmentIfMac(commandLine);
        handler = PythonProcessRunner.createProcessHandlingCtrlC(commandLine);
        ProcessTerminatedListener.attach(handler);
    }
    return handler;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 23 with GeneralCommandLine

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

the class StudyRunAction method executeFile.

private void executeFile(@NotNull final Project project, @NotNull final VirtualFile openedFile, @NotNull final String filePath) {
    GeneralCommandLine cmd = new GeneralCommandLine();
    cmd.withWorkDirectory(openedFile.getParent().getCanonicalPath());
    TaskFile selectedTaskFile = StudyUtils.getTaskFile(project, openedFile);
    assert selectedTaskFile != null;
    final Task currentTask = selectedTaskFile.getTask();
    final Sdk sdk = StudyUtils.findSdk(currentTask, project);
    if (sdk == null) {
        StudyUtils.showNoSdkNotification(currentTask, project);
        return;
    }
    String sdkHomePath = sdk.getHomePath();
    if (sdkHomePath != null) {
        cmd.setExePath(sdkHomePath);
        StudyUtils.setCommandLineParameters(cmd, project, filePath, sdkHomePath, currentTask);
        try {
            myHandler = new OSProcessHandler(cmd);
        } catch (ExecutionException e) {
            LOG.error(e);
            return;
        }
        for (ProcessListener processListener : myProcessListeners) {
            myHandler.addProcessListener(processListener);
        }
        final RunContentExecutor executor = StudyUtils.getExecutor(project, currentTask, myHandler);
        if (executor != null) {
            Disposer.register(project, executor);
            executor.run();
        }
        EduUtils.synchronize();
    }
}
Also used : TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessListener(com.intellij.execution.process.ProcessListener) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunContentExecutor(com.intellij.execution.RunContentExecutor) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException)

Example 24 with GeneralCommandLine

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

the class PyCondaManagementService method addRepository.

@Override
public void addRepository(String repositoryUrl) {
    final String conda = PyCondaPackageService.getCondaExecutable(mySdk.getHomeDirectory());
    final ArrayList<String> parameters = Lists.newArrayList(conda, "config", "--add", "channels", repositoryUrl, "--force");
    final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
    try {
        final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
        final ProcessOutput result = handler.runProcess();
        final int exitCode = result.getExitCode();
        if (exitCode != 0) {
            final String message = StringUtil.isEmptyOrSpaces(result.getStdout()) && StringUtil.isEmptyOrSpaces(result.getStderr()) ? "Permission denied" : "Non-zero exit code";
            LOG.warn("Failed to add repository " + message);
        }
        PyCondaPackageService.getInstance().addChannel(repositoryUrl);
    } catch (ExecutionException e) {
        LOG.warn("Failed to add repository");
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler)

Example 25 with GeneralCommandLine

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

the class Emulator method getWaitCommand.

private GeneralCommandLine getWaitCommand() {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    String adbCmdName = SystemInfo.isWindows ? "adb.exe" : "adb";
    commandLine.setExePath(pathManager.getPlatformToolsFolderInAndroidSdk() + "/" + adbCmdName);
    commandLine.addParameter("wait-for-device");
    return commandLine;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine)

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