Search in sources :

Example 1 with RunCanceledByUserException

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

the class ExecutionErrorDialog method show.

public static void show(final ExecutionException e, final String title, final Project project) {
    if (e instanceof RunCanceledByUserException) {
        return;
    }
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        throw new RuntimeException(e.getLocalizedMessage());
    }
    final String message = e.getMessage();
    if (message == null || message.length() < 100) {
        Messages.showErrorDialog(project, message == null ? "exception was thrown" : message, title);
        return;
    }
    final DialogBuilder builder = new DialogBuilder(project);
    builder.setTitle(title);
    final JTextArea textArea = new JTextArea();
    textArea.setEditable(false);
    textArea.setForeground(UIUtil.getLabelForeground());
    textArea.setBackground(UIUtil.getLabelBackground());
    textArea.setFont(UIUtil.getLabelFont());
    textArea.setText(message);
    textArea.setWrapStyleWord(false);
    textArea.setLineWrap(true);
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(textArea);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    final JPanel panel = new JPanel(new BorderLayout(10, 0));
    panel.setPreferredSize(JBUI.size(500, 200));
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.add(new JLabel(Messages.getErrorIcon()), BorderLayout.WEST);
    builder.setCenterPanel(panel);
    builder.setButtonsAlignment(SwingConstants.CENTER);
    builder.addOkAction();
    builder.show();
}
Also used : RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) DialogBuilder(com.intellij.openapi.ui.DialogBuilder)

Example 2 with RunCanceledByUserException

use of com.intellij.execution.RunCanceledByUserException in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebuggerRunner method createContentDescriptor.

private static RunContentDescriptor createContentDescriptor(@Nullable final CloudDebugProcessState processState, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    final XDebugSession debugSession = XDebuggerManager.getInstance(environment.getProject()).startSession(environment, new XDebugProcessStarter() {

        @NotNull
        @Override
        public XDebugProcess start(@NotNull final XDebugSession session) throws ExecutionException {
            // Clear out the stash state which is queried on debug exit.
            if (processState != null) {
                ProjectRepositoryState.fromProcessState(processState).clearForNextSession();
            }
            CloudDebugProcessState state = processState;
            CloudAttachDialog attachDialog = new CloudAttachDialog(session.getProject(), null);
            attachDialog.setInputState(state);
            DialogManager.show(attachDialog);
            state = attachDialog.getResultState();
            ProjectRepositoryValidator validator = null;
            if (state != null) {
                validator = new ProjectRepositoryValidator(state);
            }
            if (!attachDialog.isOK() || state == null || !validator.isValidDebuggee()) {
                throw new RunCanceledByUserException();
            }
            if (environment.getRunnerAndConfigurationSettings() != null && environment.getRunnerAndConfigurationSettings().getConfiguration() instanceof CloudDebugRunConfiguration) {
                CloudDebugRunConfiguration config = (CloudDebugRunConfiguration) environment.getRunnerAndConfigurationSettings().getConfiguration();
                // State is only stored in the run config between active sessions.
                // Otherwise, the background watcher may hit a check during debug session
                // startup.
                config.setProcessState(null);
            }
            CloudDebugProcess process = new CloudDebugProcess(session);
            process.initialize(state);
            return process;
        }
    });
    RunnerLayoutUi ui = debugSession.getUI();
    if (ui instanceof DataProvider) {
        final RunnerContentUi contentUi = (RunnerContentUi) ((DataProvider) ui).getData(RunnerContentUi.KEY.getName());
        final Project project = debugSession.getProject();
        if (contentUi != null) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (project.isOpen() && !project.isDisposed()) {
                        contentUi.restoreLayout();
                    }
                }
            });
        }
    }
    return debugSession.getRunContentDescriptor();
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) NotNull(org.jetbrains.annotations.NotNull) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) DataProvider(com.intellij.openapi.actionSystem.DataProvider) Project(com.intellij.openapi.project.Project) RunnerLayoutUi(com.intellij.execution.ui.RunnerLayoutUi) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) CloudAttachDialog(com.google.cloud.tools.intellij.debugger.ui.CloudAttachDialog) RunnerContentUi(com.intellij.execution.ui.layout.impl.RunnerContentUi) ExecutionException(com.intellij.execution.ExecutionException)

Example 3 with RunCanceledByUserException

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

the class MavenResumeAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = myEnvironment.getProject();
    try {
        MavenRunConfiguration runConfiguration = ((MavenRunConfiguration) myEnvironment.getRunProfile()).clone();
        List<String> goals = runConfiguration.getRunnerParameters().getGoals();
        if (goals.size() > 2 && "-rf".equals(goals.get(goals.size() - 2))) {
            // This runConfiguration was created by other MavenResumeAction.
            goals.set(goals.size() - 1, myResumeModuleId);
        } else {
            goals.add("-rf");
            goals.add(myResumeModuleId);
        }
        runConfiguration.getRunnerParameters().setGoals(goals);
        myRunner.execute(new ExecutionEnvironmentBuilder(myEnvironment).contentToReuse(null).runProfile(runConfiguration).build());
    } catch (RunCanceledByUserException ignore) {
    } catch (ExecutionException e1) {
        Messages.showErrorDialog(project, e1.getMessage(), ExecutionBundle.message("restart.error.message.title"));
    }
}
Also used : RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) Project(com.intellij.openapi.project.Project) MavenProject(org.jetbrains.idea.maven.project.MavenProject) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException)

Example 4 with RunCanceledByUserException

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

the class PyCondaPackageManagerImpl method createVirtualEnv.

@NotNull
public static String createVirtualEnv(@NotNull String destinationDir, String version) throws ExecutionException {
    final String condaExecutable = PyCondaPackageService.getSystemCondaExecutable();
    if (condaExecutable == null)
        throw new PyExecutionException("Cannot find conda", "Conda", Collections.<String>emptyList(), new ProcessOutput());
    final ArrayList<String> parameters = Lists.newArrayList(condaExecutable, "create", "-p", destinationDir, "-y", "python=" + version);
    final GeneralCommandLine commandLine = new GeneralCommandLine(parameters);
    final CapturingProcessHandler handler = new CapturingProcessHandler(commandLine);
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    final ProcessOutput result = handler.runProcessWithProgressIndicator(indicator);
    if (result.isCancelled()) {
        throw new RunCanceledByUserException();
    }
    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";
        throw new PyExecutionException(message, "Conda", parameters, result);
    }
    final String binary = PythonSdkType.getPythonExecutable(destinationDir);
    final String binaryFallback = destinationDir + File.separator + "bin" + File.separator + "python";
    return (binary != null) ? binary : binaryFallback;
}
Also used : RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessOutput(com.intellij.execution.process.ProcessOutput) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CapturingProcessHandler(com.intellij.execution.process.CapturingProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with RunCanceledByUserException

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

the class PyPackageManagerImpl method getPythonProcessOutput.

@NotNull
protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath, @NotNull List<String> args, boolean askForSudo, boolean showProgress, @Nullable String workingDir) throws ExecutionException {
    final String homePath = getSdk().getHomePath();
    if (homePath == null) {
        throw new ExecutionException("Cannot find Python interpreter for SDK " + mySdk.getName());
    }
    if (workingDir == null) {
        workingDir = new File(homePath).getParent();
    }
    final List<String> cmdline = new ArrayList<>();
    cmdline.add(homePath);
    cmdline.add(helperPath);
    cmdline.addAll(args);
    LOG.info("Running packaging tool: " + StringUtil.join(cmdline, " "));
    final boolean canCreate = FileUtil.ensureCanCreateFile(new File(homePath));
    final boolean useSudo = !canCreate && !SystemInfo.isWindows && askForSudo;
    try {
        final GeneralCommandLine commandLine = new GeneralCommandLine(cmdline).withWorkDirectory(workingDir);
        final Map<String, String> environment = commandLine.getEnvironment();
        PythonEnvUtil.setPythonUnbuffered(environment);
        PythonEnvUtil.setPythonDontWriteBytecode(environment);
        PythonEnvUtil.resetHomePathChanges(homePath, environment);
        final Process process;
        if (useSudo) {
            process = ExecUtil.sudo(commandLine, "Please enter your password to make changes in system packages: ");
        } else {
            process = commandLine.createProcess();
        }
        final CapturingProcessHandler handler = new CapturingProcessHandler(process, commandLine.getCharset(), commandLine.getCommandLineString());
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        final ProcessOutput result;
        if (showProgress && indicator != null) {
            handler.addProcessListener(new ProcessAdapter() {

                @Override
                public void onTextAvailable(ProcessEvent event, Key outputType) {
                    if (outputType == ProcessOutputTypes.STDOUT || outputType == ProcessOutputTypes.STDERR) {
                        for (String line : StringUtil.splitByLines(event.getText())) {
                            final String trimmed = line.trim();
                            if (isMeaningfulOutput(trimmed)) {
                                indicator.setText2(trimmed);
                            }
                        }
                    }
                }

                private boolean isMeaningfulOutput(@NotNull String trimmed) {
                    return trimmed.length() > 3;
                }
            });
            result = handler.runProcessWithProgressIndicator(indicator);
        } else {
            result = handler.runProcess(TIMEOUT);
        }
        if (result.isCancelled()) {
            throw new RunCanceledByUserException();
        }
        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 (" + exitCode + ")";
            throw new PyExecutionException(message, helperPath, args, result);
        }
        return result;
    } catch (IOException e) {
        throw new PyExecutionException(e.getMessage(), helperPath, args);
    }
}
Also used : IOException(java.io.IOException) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) Key(com.intellij.openapi.util.Key) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RunCanceledByUserException (com.intellij.execution.RunCanceledByUserException)8 ExecutionException (com.intellij.execution.ExecutionException)6 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)3 BuildResult (com.google.idea.blaze.base.sync.aspects.BuildResult)3 CancellationException (java.util.concurrent.CancellationException)3 NotNull (org.jetbrains.annotations.NotNull)3 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 Label (com.google.idea.blaze.base.model.primitives.Label)2 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Key (com.intellij.openapi.util.Key)2 CloudAttachDialog (com.google.cloud.tools.intellij.debugger.ui.CloudAttachDialog)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 BlazeBeforeRunCommandHelper (com.google.idea.blaze.base.run.BlazeBeforeRunCommandHelper)1 WithBrowserHyperlinkExecutionException (com.google.idea.blaze.base.run.WithBrowserHyperlinkExecutionException)1