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();
}
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();
}
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"));
}
}
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;
}
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);
}
}
Aggregations