Search in sources :

Example 96 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij by bazelbuild.

the class BlazeGDBDriverConfigurationBase method createDriverCommandLine.

@Override
public GeneralCommandLine createDriverCommandLine(DebuggerDriver driver, Installer installer) throws ExecutionException {
    GeneralCommandLine commandLine = super.createDriverCommandLine(driver, installer);
    modifyCommandLine(commandLine);
    return commandLine;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine)

Example 97 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij by bazelbuild.

the class BlazeGDBDriverConfigurationBase method createDriverCommandLine.

@Override
public GeneralCommandLine createDriverCommandLine(DebuggerDriver driver) throws ExecutionException {
    GeneralCommandLine commandLine = super.createDriverCommandLine(driver);
    modifyCommandLine(commandLine);
    return commandLine;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine)

Example 98 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project intellij by bazelbuild.

the class AaptUtil method getAaptBadging.

/**
 * Uses aapt to dump badging information for the given apk, and extracts information from the
 * output matching the given pattern.
 */
@Nullable
private static MatchResult getAaptBadging(Project project, File apk, Pattern pattern) throws AaptUtilException {
    if (!apk.exists()) {
        throw new AaptUtilException("apk file does not exist: " + apk);
    }
    AndroidPlatform androidPlatform = SdkUtil.getAndroidPlatform(project);
    if (androidPlatform == null) {
        throw new AaptUtilException("Could not find Android platform sdk for project " + project.getName());
    }
    BuildToolInfo toolInfo = androidPlatform.getSdkData().getLatestBuildTool();
    if (toolInfo == null) {
        throw new AaptUtilException("Could not find Android sdk build-tools for project " + project.getName());
    }
    String aapt = toolInfo.getPath(PathId.AAPT);
    GeneralCommandLine commandLine = new GeneralCommandLine(aapt, "dump", "badging", apk.getAbsolutePath());
    OSProcessHandler handler;
    try {
        handler = new OSProcessHandler(commandLine);
    } catch (ExecutionException e) {
        throw new AaptUtilException("Could not execute aapt to extract apk information.", e);
    }
    // The wrapped stream is closed by the process handler.
    BufferedReader reader = new BufferedReader(new InputStreamReader(handler.getProcess().getInputStream()));
    try {
        String line;
        while ((line = reader.readLine()) != null) {
            Matcher matcher = pattern.matcher(line);
            if (matcher.find()) {
                return matcher.toMatchResult();
            }
        }
    } catch (IOException e) {
        throw new AaptUtilException("Could not read aapt output.", e);
    }
    return null;
}
Also used : InputStreamReader(java.io.InputStreamReader) BuildToolInfo(com.android.sdklib.BuildToolInfo) Matcher(java.util.regex.Matcher) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) BufferedReader(java.io.BufferedReader) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException) Nullable(javax.annotation.Nullable)

Example 99 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project ballerina by ballerina-lang.

the class BallerinaRunningState method startProcess.

@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
    BallerinaExecutor executor = patchExecutor(createCommonExecutor());
    // We only need to set parameters.
    GeneralCommandLine commandLine = executor.withParameterString(myConfiguration.getParams()).createCommandLine();
    KillableColoredProcessHandler handler = new KillableColoredProcessHandler(commandLine, true);
    ProcessTerminatedListener.attach(handler);
    return handler;
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) BallerinaExecutor(org.ballerinalang.plugins.idea.util.BallerinaExecutor) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 100 with GeneralCommandLine

use of com.intellij.execution.configurations.GeneralCommandLine in project ballerina by ballerina-lang.

the class BallerinaExecutor method execute.

public boolean execute() {
    Logger.getInstance(getClass()).assertTrue(!ApplicationManager.getApplication().isDispatchThread(), "It's bad idea to run external tool on EDT");
    Logger.getInstance(getClass()).assertTrue(myProcessHandler == null, "Process has already run with this executor instance");
    Ref<Boolean> result = Ref.create(false);
    GeneralCommandLine commandLine = null;
    try {
        commandLine = createCommandLine();
        GeneralCommandLine finalCommandLine = commandLine;
        myProcessHandler = new KillableColoredProcessHandler(finalCommandLine, true) {

            @Override
            public void startNotify() {
                if (myShowBallerinaEnvVariables) {
                    BallerinaRunUtil.printBallerinaEnvVariables(finalCommandLine, this);
                }
                super.startNotify();
            }
        };
        BallerinaHistoryProcessListener historyProcessListener = new BallerinaHistoryProcessListener();
        myProcessHandler.addProcessListener(historyProcessListener);
        for (ProcessListener listener : myProcessListeners) {
            myProcessHandler.addProcessListener(listener);
        }
        CapturingProcessAdapter processAdapter = new CapturingProcessAdapter(myProcessOutput) {

            @Override
            public void processTerminated(@NotNull ProcessEvent event) {
                super.processTerminated(event);
                boolean success = event.getExitCode() == 0 && myProcessOutput.getStderr().isEmpty();
                boolean nothingToShow = myProcessOutput.getStdout().isEmpty() && myProcessOutput.getStderr().isEmpty();
                boolean cancelledByUser = (event.getExitCode() == -1 || event.getExitCode() == 2) && nothingToShow;
                result.set(success);
                if (success) {
                    if (myShowNotificationsOnSuccess) {
                        showNotification("Finished successfully", NotificationType.INFORMATION);
                    }
                } else if (cancelledByUser) {
                    if (myShowNotificationsOnError) {
                        showNotification("Interrupted", NotificationType.WARNING);
                    }
                } else if (myShowOutputOnError) {
                    ApplicationManager.getApplication().invokeLater(() -> showOutput(myProcessHandler, historyProcessListener));
                }
            }
        };
        myProcessHandler.addProcessListener(processAdapter);
        myProcessHandler.startNotify();
        ExecutionModes.SameThreadMode sameThreadMode = new ExecutionModes.SameThreadMode(getPresentableName());
        ExecutionHelper.executeExternalProcess(myProject, myProcessHandler, sameThreadMode, commandLine);
        LOGGER.debug("Finished `" + getPresentableName() + "` with result: " + result.get());
        return result.get();
    } catch (ExecutionException e) {
        if (myShowOutputOnError) {
            ExecutionHelper.showErrors(myProject, Collections.singletonList(e), getPresentableName(), null);
        }
        if (myShowNotificationsOnError) {
            showNotification(StringUtil.notNullize(e.getMessage(), "Unknown error, see logs for details"), NotificationType.ERROR);
        }
        String commandLineInfo = commandLine != null ? commandLine.getCommandLineString() : "not constructed";
        LOGGER.debug("Finished `" + getPresentableName() + "` with an exception. Commandline: " + commandLineInfo, e);
        return false;
    }
}
Also used : CapturingProcessAdapter(com.intellij.execution.process.CapturingProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) ProcessListener(com.intellij.execution.process.ProcessListener) NotNull(org.jetbrains.annotations.NotNull) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionModes(com.intellij.execution.ExecutionModes) ExecutionException(com.intellij.execution.ExecutionException) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler)

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