Use ExecutionException in signatures instead of more specific PyExternalProcessException

This commit is contained in:
Andrey Vlasovskikh
2014-09-22 18:25:02 +04:00
parent 1addeba623
commit 90fdcf3276
16 changed files with 87 additions and 112 deletions

View File

@@ -15,6 +15,7 @@
*/ */
package com.jetbrains.python.packaging; package com.jetbrains.python.packaging;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.module.Module; import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Key;
@@ -40,20 +41,20 @@ public abstract class PyPackageManager {
return PyPackageManagers.getInstance().forSdk(sdk); return PyPackageManagers.getInstance().forSdk(sdk);
} }
public abstract void installManagement() throws PyExternalProcessException; public abstract void installManagement() throws ExecutionException;
public abstract boolean hasManagement(boolean cachedOnly); public abstract boolean hasManagement(boolean cachedOnly);
public abstract void install(@NotNull String requirementString) throws PyExternalProcessException; public abstract void install(@NotNull String requirementString) throws ExecutionException;
public abstract void install(@NotNull List<PyRequirement> requirements, @NotNull List<String> extraArgs) throws PyExternalProcessException; public abstract void install(@NotNull List<PyRequirement> requirements, @NotNull List<String> extraArgs) throws ExecutionException;
public abstract void uninstall(@NotNull List<PyPackage> packages) throws PyExternalProcessException; public abstract void uninstall(@NotNull List<PyPackage> packages) throws ExecutionException;
public abstract void refresh(); public abstract void refresh();
@NotNull @NotNull
public abstract String createVirtualEnv(@NotNull String destinationDir, boolean useGlobalSite) throws PyExternalProcessException; public abstract String createVirtualEnv(@NotNull String destinationDir, boolean useGlobalSite) throws ExecutionException;
@Nullable @Nullable
public abstract List<PyPackage> getPackages(boolean cachedOnly) throws PyExternalProcessException; public abstract List<PyPackage> getPackages(boolean cachedOnly) throws ExecutionException;
@Nullable @Nullable
public abstract PyPackage findPackage(@NotNull String name, boolean cachedOnly) throws PyExternalProcessException; public abstract PyPackage findPackage(@NotNull String name, boolean cachedOnly) throws ExecutionException;
@Nullable @Nullable
public abstract List<PyRequirement> getRequirements(@NotNull Module module); public abstract List<PyRequirement> getRequirements(@NotNull Module module);
@Nullable @Nullable
public abstract Set<PyPackage> getDependents(@NotNull PyPackage pkg) throws PyExternalProcessException; public abstract Set<PyPackage> getDependents(@NotNull PyPackage pkg) throws ExecutionException;
} }

View File

@@ -1,29 +0,0 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.packaging;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author vlan
*/
public class PyProcessCancelledException extends PyExternalProcessException {
public PyProcessCancelledException(@NotNull String name, @NotNull List<String> args) {
super(255, name, args, "Process cancelled");
}
}

View File

@@ -15,9 +15,9 @@
*/ */
package com.jetbrains.python.templateLanguages; package com.jetbrains.python.templateLanguages;
import com.intellij.execution.ExecutionException;
import com.intellij.facet.ui.ValidationResult; import com.intellij.facet.ui.ValidationResult;
import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.Sdk;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackage; import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyPackageManager; import com.jetbrains.python.packaging.PyPackageManager;
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls;
@@ -44,7 +44,7 @@ public class PyTemplatesUtil {
if (installedPackage == null) if (installedPackage == null)
return new ValidationResult(templateBinding + " will be installed on selected interpreter"); return new ValidationResult(templateBinding + " will be installed on selected interpreter");
} }
catch (PyExternalProcessException ignored) { catch (ExecutionException ignored) {
} }
} }
} }
@@ -55,7 +55,7 @@ public class PyTemplatesUtil {
return new ValidationResult(language + " will be installed on selected interpreter"); return new ValidationResult(language + " will be installed on selected interpreter");
} }
} }
catch (PyExternalProcessException ignored) { catch (ExecutionException ignored) {
} }
} }
return null; return null;

View File

@@ -15,6 +15,7 @@
*/ */
package com.jetbrains.rest; package com.jetbrains.rest;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys; import com.intellij.openapi.actionSystem.LangDataKeys;
@@ -23,7 +24,6 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.Sdk;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackage; import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyPackageManager; import com.jetbrains.python.packaging.PyPackageManager;
import com.jetbrains.python.sdk.PythonSdkType; import com.jetbrains.python.sdk.PythonSdkType;
@@ -52,7 +52,7 @@ public class RestPythonUtil {
final PyPackage sphinx = manager.findPackage("Sphinx", false); final PyPackage sphinx = manager.findPackage("Sphinx", false);
presentation.setEnabled(sphinx != null); presentation.setEnabled(sphinx != null);
} }
catch (PyExternalProcessException ignored) { catch (ExecutionException ignored) {
} }
} }
} }

View File

@@ -17,6 +17,7 @@ package com.jetbrains.python.configuration;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
import com.intellij.execution.ExecutionException;
import com.intellij.facet.impl.ui.FacetErrorPanel; import com.intellij.facet.impl.ui.FacetErrorPanel;
import com.intellij.facet.ui.FacetConfigurationQuickFix; import com.intellij.facet.ui.FacetConfigurationQuickFix;
import com.intellij.facet.ui.FacetEditorValidator; import com.intellij.facet.ui.FacetEditorValidator;
@@ -161,7 +162,7 @@ public class PyIntegratedToolsConfigurable implements SearchableConfigurable, No
public void started() {} public void started() {}
@Override @Override
public void finished(List<PyExternalProcessException> exceptions) { public void finished(List<ExecutionException> exceptions) {
if (exceptions.isEmpty()) { if (exceptions.isEmpty()) {
VFSTestFrameworkListener.getInstance().testInstalled(true, sdk.getHomePath(), name); VFSTestFrameworkListener.getInstance().testInstalled(true, sdk.getHomePath(), name);
facetErrorPanel.getValidatorsManager().validate(); facetErrorPanel.getValidatorsManager().validate();

View File

@@ -18,6 +18,7 @@ package com.jetbrains.python.inspections;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.intellij.codeInspection.*; import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ui.ListEditForm; import com.intellij.codeInspection.ui.ListEditForm;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Document;
@@ -212,7 +213,7 @@ public class PyPackageRequirementsInspection extends PyInspection {
try { try {
packages = PyPackageManager.getInstance(sdk).getPackages(PySdkUtil.isRemote(sdk)); packages = PyPackageManager.getInstance(sdk).getPackages(PySdkUtil.isRemote(sdk));
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
return null; return null;
} }
if (packages == null) return null; if (packages == null) return null;
@@ -248,7 +249,7 @@ public class PyPackageRequirementsInspection extends PyInspection {
try { try {
packages = manager.getPackages(PySdkUtil.isRemote(sdk)); packages = manager.getPackages(PySdkUtil.isRemote(sdk));
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
return null; return null;
} }
if (packages == null) return null; if (packages == null) return null;
@@ -330,7 +331,7 @@ public class PyPackageRequirementsInspection extends PyInspection {
if (installManagement) { if (installManagement) {
final PyPackageManagerUI ui = new PyPackageManagerUI(project, mySdk, new UIListener(myModule) { final PyPackageManagerUI ui = new PyPackageManagerUI(project, mySdk, new UIListener(myModule) {
@Override @Override
public void finished(List<PyExternalProcessException> exceptions) { public void finished(List<ExecutionException> exceptions) {
super.finished(exceptions); super.finished(exceptions);
if (exceptions.isEmpty()) { if (exceptions.isEmpty()) {
installRequirements(project, chosen); installRequirements(project, chosen);
@@ -363,7 +364,7 @@ public class PyPackageRequirementsInspection extends PyInspection {
} }
@Override @Override
public void finished(List<PyExternalProcessException> exceptions) { public void finished(List<ExecutionException> exceptions) {
setRunningPackagingTasks(myModule, false); setRunningPackagingTasks(myModule, false);
} }
} }

View File

@@ -18,6 +18,7 @@ package com.jetbrains.python.packaging;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.intellij.execution.ExecutionException; import com.intellij.execution.ExecutionException;
import com.intellij.execution.RunCanceledByUserException;
import com.intellij.execution.process.*; import com.intellij.execution.process.*;
import com.intellij.execution.util.ExecUtil; import com.intellij.execution.util.ExecUtil;
import com.intellij.openapi.application.Application; import com.intellij.openapi.application.Application;
@@ -91,7 +92,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
private final Object myCacheLock = new Object(); private final Object myCacheLock = new Object();
private List<PyPackage> myPackagesCache = null; private List<PyPackage> myPackagesCache = null;
private PyExternalProcessException myExceptionCache = null; private ExecutionException myExceptionCache = null;
protected Sdk mySdk; protected Sdk mySdk;
@@ -117,7 +118,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
@Override @Override
public void installManagement() throws PyExternalProcessException { public void installManagement() throws ExecutionException {
final boolean pre26 = PythonSdkType.getLanguageLevelForSdk(mySdk).isOlderThan(LanguageLevel.PYTHON26); final boolean pre26 = PythonSdkType.getLanguageLevelForSdk(mySdk).isOlderThan(LanguageLevel.PYTHON26);
if (!hasPackage(SETUPTOOLS, false) && !hasPackage(DISTRIBUTE, false)) { if (!hasPackage(SETUPTOOLS, false) && !hasPackage(DISTRIBUTE, false)) {
final String name = SETUPTOOLS + "-" + (pre26 ? SETUPTOOLS_PRE_26_VERSION : SETUPTOOLS_VERSION); final String name = SETUPTOOLS + "-" + (pre26 ? SETUPTOOLS_PRE_26_VERSION : SETUPTOOLS_VERSION);
@@ -135,7 +136,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
hasPackage(PIP, cachedOnly); hasPackage(PIP, cachedOnly);
} }
protected void installManagement(@NotNull String name) throws PyExternalProcessException { protected void installManagement(@NotNull String name) throws ExecutionException {
final String dirName = extractHelper(name + ".tar.gz"); final String dirName = extractHelper(name + ".tar.gz");
try { try {
final String fileName = dirName + name + File.separatorChar + "setup.py"; final String fileName = dirName + name + File.separatorChar + "setup.py";
@@ -148,7 +149,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
@NotNull @NotNull
private String extractHelper(@NotNull String name) throws PyExternalProcessException { private String extractHelper(@NotNull String name) throws ExecutionException {
final String helperPath = getHelperPath(name); final String helperPath = getHelperPath(name);
final ArrayList<String> args = Lists.newArrayList(UNTAR, helperPath); final ArrayList<String> args = Lists.newArrayList(UNTAR, helperPath);
final String result = getHelperResult(PACKAGING_TOOL, args, false, false, null); final String result = getHelperResult(PACKAGING_TOOL, args, false, false, null);
@@ -163,7 +164,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
try { try {
return findPackage(name, cachedOnly) != null; return findPackage(name, cachedOnly) != null;
} }
catch (PyExternalProcessException ignored) { catch (ExecutionException ignored) {
return false; return false;
} }
} }
@@ -184,13 +185,13 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
@Override @Override
public void install(@NotNull String requirementString) throws PyExternalProcessException { public void install(@NotNull String requirementString) throws ExecutionException {
installManagement(); installManagement();
install(Collections.singletonList(PyRequirement.fromString(requirementString)), Collections.<String>emptyList()); install(Collections.singletonList(PyRequirement.fromString(requirementString)), Collections.<String>emptyList());
} }
@Override @Override
public void install(@NotNull List<PyRequirement> requirements, @NotNull List<String> extraArgs) throws PyExternalProcessException { public void install(@NotNull List<PyRequirement> requirements, @NotNull List<String> extraArgs) throws ExecutionException {
final List<String> args = new ArrayList<String>(); final List<String> args = new ArrayList<String>();
args.add(INSTALL); args.add(INSTALL);
final File buildDir; final File buildDir;
@@ -198,7 +199,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
buildDir = FileUtil.createTempDirectory("pycharm-packaging", null); buildDir = FileUtil.createTempDirectory("pycharm-packaging", null);
} }
catch (IOException e) { catch (IOException e) {
throw new PyExternalProcessException(ERROR_ACCESS_DENIED, PACKAGING_TOOL, args, "Cannot create temporary build directory"); throw new ExecutionException("Cannot create temporary build directory");
} }
if (!extraArgs.contains(BUILD_DIR_OPTION)) { if (!extraArgs.contains(BUILD_DIR_OPTION)) {
args.addAll(Arrays.asList(BUILD_DIR_OPTION, buildDir.getAbsolutePath())); args.addAll(Arrays.asList(BUILD_DIR_OPTION, buildDir.getAbsolutePath()));
@@ -224,7 +225,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
} }
public void uninstall(@NotNull List<PyPackage> packages) throws PyExternalProcessException { public void uninstall(@NotNull List<PyPackage> packages) throws ExecutionException {
try { try {
final List<String> args = new ArrayList<String>(); final List<String> args = new ArrayList<String>();
args.add(UNINSTALL); args.add(UNINSTALL);
@@ -246,7 +247,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
@Nullable @Nullable
public List<PyPackage> getPackages(boolean cachedOnly) throws PyExternalProcessException { public List<PyPackage> getPackages(boolean cachedOnly) throws ExecutionException {
synchronized (myCacheLock) { synchronized (myCacheLock) {
if (myPackagesCache != null) { if (myPackagesCache != null) {
return myPackagesCache; return myPackagesCache;
@@ -266,7 +267,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
return packages; return packages;
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
synchronized (myCacheLock) { synchronized (myCacheLock) {
myExceptionCache = e; myExceptionCache = e;
} }
@@ -275,7 +276,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
@Nullable @Nullable
public Set<PyPackage> getDependents(@NotNull PyPackage pkg) throws PyExternalProcessException { public Set<PyPackage> getDependents(@NotNull PyPackage pkg) throws ExecutionException {
final List<PyPackage> packages = getPackages(false); final List<PyPackage> packages = getPackages(false);
if (packages != null) { if (packages != null) {
final Set<PyPackage> dependents = new HashSet<PyPackage>(); final Set<PyPackage> dependents = new HashSet<PyPackage>();
@@ -294,7 +295,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
@Override @Override
@Nullable @Nullable
public PyPackage findPackage(@NotNull String name, boolean cachedOnly) throws PyExternalProcessException { public PyPackage findPackage(@NotNull String name, boolean cachedOnly) throws ExecutionException {
final List<PyPackage> packages = getPackages(cachedOnly); final List<PyPackage> packages = getPackages(cachedOnly);
if (packages != null) { if (packages != null) {
for (PyPackage pkg : packages) { for (PyPackage pkg : packages) {
@@ -307,7 +308,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
@NotNull @NotNull
public String createVirtualEnv(@NotNull String destinationDir, boolean useGlobalSite) throws PyExternalProcessException { public String createVirtualEnv(@NotNull String destinationDir, boolean useGlobalSite) throws ExecutionException {
final List<String> args = new ArrayList<String>(); final List<String> args = new ArrayList<String>();
final LanguageLevel languageLevel = PythonSdkType.getLanguageLevelForSdk(mySdk); final LanguageLevel languageLevel = PythonSdkType.getLanguageLevelForSdk(mySdk);
final boolean usePyVenv = languageLevel.isAtLeast(LanguageLevel.PYTHON33); final boolean usePyVenv = languageLevel.isAtLeast(LanguageLevel.PYTHON33);
@@ -404,10 +405,10 @@ public class PyPackageManagerImpl extends PyPackageManager {
@NotNull @NotNull
private String getHelperResult(@NotNull String helper, @NotNull List<String> args, boolean askForSudo, private String getHelperResult(@NotNull String helper, @NotNull List<String> args, boolean askForSudo,
boolean showProgress, @Nullable String parentDir) throws PyExternalProcessException { boolean showProgress, @Nullable String parentDir) throws ExecutionException {
final String helperPath = getHelperPath(helper); final String helperPath = getHelperPath(helper);
if (helperPath == null) { if (helperPath == null) {
throw new PyExternalProcessException(ERROR_TOOL_NOT_FOUND, helper, args, "Cannot find external tool"); throw new ExecutionException("Cannot find external tool: " + helper);
} }
return getPythonProcessResult(helperPath, args, askForSudo, showProgress, parentDir); return getPythonProcessResult(helperPath, args, askForSudo, showProgress, parentDir);
} }
@@ -419,7 +420,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
@NotNull @NotNull
private String getPythonProcessResult(@NotNull String path, @NotNull List<String> args, boolean askForSudo, private String getPythonProcessResult(@NotNull String path, @NotNull List<String> args, boolean askForSudo,
boolean showProgress, @Nullable String workingDir) throws PyExternalProcessException { boolean showProgress, @Nullable String workingDir) throws ExecutionException {
final ProcessOutput output = getPythonProcessOutput(path, args, askForSudo, showProgress, workingDir); final ProcessOutput output = getPythonProcessOutput(path, args, askForSudo, showProgress, workingDir);
final int exitCode = output.getExitCode(); final int exitCode = output.getExitCode();
if (output.isTimeout()) { if (output.isTimeout()) {
@@ -434,10 +435,10 @@ public class PyPackageManagerImpl extends PyPackageManager {
@NotNull @NotNull
protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath, @NotNull List<String> args, boolean askForSudo, protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath, @NotNull List<String> args, boolean askForSudo,
boolean showProgress, @Nullable String workingDir) throws PyExternalProcessException { boolean showProgress, @Nullable String workingDir) throws ExecutionException {
final String homePath = mySdk.getHomePath(); final String homePath = mySdk.getHomePath();
if (homePath == null) { if (homePath == null) {
throw new PyExternalProcessException(ERROR_INVALID_SDK, helperPath, args, "Cannot find interpreter for SDK"); throw new ExecutionException("Cannot find Python interpreter for SDK " + mySdk.getName());
} }
if (workingDir == null) { if (workingDir == null) {
workingDir = new File(homePath).getParent(); workingDir = new File(homePath).getParent();
@@ -487,7 +488,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
result = handler.runProcess(TIMEOUT); result = handler.runProcess(TIMEOUT);
} }
if (result.isCancelled()) { if (result.isCancelled()) {
throw new PyProcessCancelledException(helperPath, args); throw new RunCanceledByUserException();
} }
String message = result.getStderr(); String message = result.getStderr();
if (result.getExitCode() != 0) { if (result.getExitCode() != 0) {
@@ -502,7 +503,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
return result; return result;
} }
catch (PyProcessCancelledException e) { catch (RunCanceledByUserException e) {
throw e; throw e;
} }
catch (ExecutionException e) { catch (ExecutionException e) {
@@ -514,7 +515,7 @@ public class PyPackageManagerImpl extends PyPackageManager {
} }
@NotNull @NotNull
private static List<PyPackage> parsePackagingToolOutput(@NotNull String s) throws PyExternalProcessException { private static List<PyPackage> parsePackagingToolOutput(@NotNull String s) throws ExecutionException {
final String[] lines = StringUtil.splitByLines(s); final String[] lines = StringUtil.splitByLines(s);
final List<PyPackage> packages = new ArrayList<PyPackage>(); final List<PyPackage> packages = new ArrayList<PyPackage>();
for (String line : lines) { for (String line : lines) {

View File

@@ -15,6 +15,8 @@
*/ */
package com.jetbrains.python.packaging; package com.jetbrains.python.packaging;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.RunCanceledByUserException;
import com.intellij.icons.AllIcons; import com.intellij.icons.AllIcons;
import com.intellij.notification.Notification; import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener; import com.intellij.notification.NotificationListener;
@@ -50,7 +52,7 @@ public class PyPackageManagerUI {
public interface Listener { public interface Listener {
void started(); void started();
void finished(List<PyExternalProcessException> exceptions); void finished(List<ExecutionException> exceptions);
} }
public PyPackageManagerUI(@NotNull Project project, @NotNull Sdk sdk, @Nullable Listener listener) { public PyPackageManagerUI(@NotNull Project project, @NotNull Sdk sdk, @Nullable Listener listener) {
@@ -113,14 +115,14 @@ public class PyPackageManagerUI {
} }
if (warning[0] != Messages.YES) return true; if (warning[0] != Messages.YES) return true;
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
LOG.info("Error loading packages dependents: " + e.getMessage(), e); LOG.info("Error loading packages dependents: " + e.getMessage(), e);
} }
return false; return false;
} }
private static Map<String, Set<PyPackage>> collectDependents(@NotNull final List<PyPackage> packages, Sdk sdk) private static Map<String, Set<PyPackage>> collectDependents(@NotNull final List<PyPackage> packages,
throws PyExternalProcessException { Sdk sdk) throws ExecutionException {
Map<String, Set<PyPackage>> dependentPackages = new HashMap<String, Set<PyPackage>>(); Map<String, Set<PyPackage>> dependentPackages = new HashMap<String, Set<PyPackage>>();
for (PyPackage pkg : packages) { for (PyPackage pkg : packages) {
final Set<PyPackage> dependents = PyPackageManager.getInstance(sdk).getDependents(pkg); final Set<PyPackage> dependents = PyPackageManager.getInstance(sdk).getDependents(pkg);
@@ -152,7 +154,7 @@ public class PyPackageManagerUI {
} }
@NotNull @NotNull
protected abstract List<PyExternalProcessException> runTask(@NotNull ProgressIndicator indicator); protected abstract List<ExecutionException> runTask(@NotNull ProgressIndicator indicator);
@NotNull @NotNull
protected abstract String getSuccessTitle(); protected abstract String getSuccessTitle();
@@ -175,7 +177,7 @@ public class PyPackageManagerUI {
} }
} }
protected void taskFinished(@NotNull final List<PyExternalProcessException> exceptions) { protected void taskFinished(@NotNull final List<ExecutionException> exceptions) {
final Ref<Notification> notificationRef = new Ref<Notification>(null); final Ref<Notification> notificationRef = new Ref<Notification>(null);
if (exceptions.isEmpty()) { if (exceptions.isEmpty()) {
notificationRef.set(new Notification(PACKAGING_GROUP_ID, getSuccessTitle(), getSuccessDescription(), notificationRef.set(new Notification(PACKAGING_GROUP_ID, getSuccessTitle(), getSuccessDescription(),
@@ -211,9 +213,9 @@ public class PyPackageManagerUI {
}); });
} }
private static boolean isCancelled(@NotNull List<PyExternalProcessException> exceptions) { private static boolean isCancelled(@NotNull List<ExecutionException> exceptions) {
for (PyExternalProcessException e : exceptions) { for (ExecutionException e : exceptions) {
if (e instanceof PyProcessCancelledException) { if (e instanceof RunCanceledByUserException) {
return true; return true;
} }
} }
@@ -239,8 +241,8 @@ public class PyPackageManagerUI {
@NotNull @NotNull
@Override @Override
protected List<PyExternalProcessException> runTask(@NotNull ProgressIndicator indicator) { protected List<ExecutionException> runTask(@NotNull ProgressIndicator indicator) {
final List<PyExternalProcessException> exceptions = new ArrayList<PyExternalProcessException>(); final List<ExecutionException> exceptions = new ArrayList<ExecutionException>();
final int size = myRequirements.size(); final int size = myRequirements.size();
final PyPackageManager manager = PyPackageManagers.getInstance().forSdk(mySdk); final PyPackageManager manager = PyPackageManagers.getInstance().forSdk(mySdk);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
@@ -256,11 +258,11 @@ public class PyPackageManagerUI {
try { try {
manager.install(Arrays.asList(requirement), myExtraArgs); manager.install(Arrays.asList(requirement), myExtraArgs);
} }
catch (PyProcessCancelledException e) { catch (RunCanceledByUserException e) {
exceptions.add(e); exceptions.add(e);
break; break;
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
exceptions.add(e); exceptions.add(e);
} }
} }
@@ -297,15 +299,15 @@ public class PyPackageManagerUI {
@NotNull @NotNull
@Override @Override
protected List<PyExternalProcessException> runTask(@NotNull ProgressIndicator indicator) { protected List<ExecutionException> runTask(@NotNull ProgressIndicator indicator) {
final List<PyExternalProcessException> exceptions = new ArrayList<PyExternalProcessException>(); final List<ExecutionException> exceptions = new ArrayList<ExecutionException>();
final PyPackageManager manager = PyPackageManagers.getInstance().forSdk(mySdk); final PyPackageManager manager = PyPackageManagers.getInstance().forSdk(mySdk);
indicator.setText("Installing packaging tools..."); indicator.setText("Installing packaging tools...");
indicator.setIndeterminate(true); indicator.setIndeterminate(true);
try { try {
manager.installManagement(); manager.installManagement();
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
exceptions.add(e); exceptions.add(e);
} }
manager.refresh(); manager.refresh();
@@ -334,14 +336,14 @@ public class PyPackageManagerUI {
@NotNull @NotNull
@Override @Override
protected List<PyExternalProcessException> runTask(@NotNull ProgressIndicator indicator) { protected List<ExecutionException> runTask(@NotNull ProgressIndicator indicator) {
final PyPackageManager manager = PyPackageManagers.getInstance().forSdk(mySdk); final PyPackageManager manager = PyPackageManagers.getInstance().forSdk(mySdk);
indicator.setIndeterminate(true); indicator.setIndeterminate(true);
try { try {
manager.uninstall(myPackages); manager.uninstall(myPackages);
return Arrays.asList(); return Arrays.asList();
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
return Arrays.asList(e); return Arrays.asList(e);
} }
finally { finally {
@@ -374,11 +376,11 @@ public class PyPackageManagerUI {
} }
} }
public static String createDescription(List<PyExternalProcessException> exceptions, String firstLine) { public static String createDescription(List<ExecutionException> exceptions, String firstLine) {
final StringBuilder b = new StringBuilder(); final StringBuilder b = new StringBuilder();
b.append(firstLine); b.append(firstLine);
b.append("\n\n"); b.append("\n\n");
for (PyExternalProcessException exception : exceptions) { for (ExecutionException exception : exceptions) {
b.append(exception.toString()); b.append(exception.toString());
b.append("\n"); b.append("\n");
} }

View File

@@ -78,10 +78,10 @@ public class PyRemotePackageManagerImpl extends PyPackageManagerImpl {
protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath, protected ProcessOutput getPythonProcessOutput(@NotNull String helperPath,
@NotNull List<String> args, @NotNull List<String> args,
boolean askForSudo, boolean askForSudo,
boolean showProgress, @Nullable String workingDir) throws PyExternalProcessException { boolean showProgress, @Nullable String workingDir) throws ExecutionException {
final String homePath = mySdk.getHomePath(); final String homePath = mySdk.getHomePath();
if (homePath == null) { if (homePath == null) {
throw new PyExternalProcessException(ERROR_INVALID_SDK, helperPath, args, "Cannot find interpreter for SDK"); throw new ExecutionException("Cannot find Python interpreter for SDK " + mySdk.getName());
} }
final SdkAdditionalData sdkData = mySdk.getSdkAdditionalData(); final SdkAdditionalData sdkData = mySdk.getSdkAdditionalData();
if (sdkData instanceof PyRemoteSdkAdditionalDataBase) { //remote interpreter if (sdkData instanceof PyRemoteSdkAdditionalDataBase) { //remote interpreter
@@ -167,7 +167,7 @@ public class PyRemotePackageManagerImpl extends PyPackageManagerImpl {
} }
@Override @Override
protected void installManagement(@NotNull String name) throws PyExternalProcessException { protected void installManagement(@NotNull String name) throws ExecutionException {
super.installManagement(name); super.installManagement(name);
// TODO: remove temp directory for remote interpreter // TODO: remove temp directory for remote interpreter
} }

View File

@@ -16,6 +16,7 @@
package com.jetbrains.python.packaging.ui; package com.jetbrains.python.packaging.ui;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.application.Application; import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ModalityState;
@@ -127,7 +128,7 @@ public class PyInstalledPackagesPanel extends InstalledPackagesPanel {
} }
@Override @Override
public void finished(List<PyExternalProcessException> exceptions) { public void finished(List<ExecutionException> exceptions) {
myPackagesTable.setPaintBusy(false); myPackagesTable.setPaintBusy(false);
PyPackageManager packageManager = PyPackageManager.getInstance(sdk); PyPackageManager packageManager = PyPackageManager.getInstance(sdk);
if (!exceptions.isEmpty()) { if (!exceptions.isEmpty()) {

View File

@@ -15,6 +15,7 @@
*/ */
package com.jetbrains.python.packaging.ui; package com.jetbrains.python.packaging.ui;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtil;
@@ -142,7 +143,7 @@ public class PyPackageManagementService extends PackageManagementService {
}); });
} }
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
throw new IOException(e); throw new IOException(e);
} }
return packages != null ? new ArrayList<InstalledPackage>(packages) : new ArrayList<InstalledPackage>(); return packages != null ? new ArrayList<InstalledPackage>(packages) : new ArrayList<InstalledPackage>();
@@ -183,14 +184,14 @@ public class PyPackageManagementService extends PackageManagementService {
} }
@Override @Override
public void finished(@Nullable List<PyExternalProcessException> exceptions) { public void finished(@Nullable List<ExecutionException> exceptions) {
listener.operationFinished(packageName, toErrorDescription(exceptions)); listener.operationFinished(packageName, toErrorDescription(exceptions));
} }
}); });
ui.install(Collections.singletonList(req), extraArgs); ui.install(Collections.singletonList(req), extraArgs);
} }
private String toErrorDescription(List<PyExternalProcessException> exceptions) { private String toErrorDescription(List<ExecutionException> exceptions) {
String errorDescription = null; String errorDescription = null;
if (exceptions != null && exceptions.size() > 0) { if (exceptions != null && exceptions.size() > 0) {
errorDescription = PyPackageManagerUI.createDescription(exceptions, ""); errorDescription = PyPackageManagerUI.createDescription(exceptions, "");
@@ -208,7 +209,7 @@ public class PyPackageManagementService extends PackageManagementService {
} }
@Override @Override
public void finished(final List<PyExternalProcessException> exceptions) { public void finished(final List<ExecutionException> exceptions) {
listener.operationFinished(packageName, toErrorDescription(exceptions)); listener.operationFinished(packageName, toErrorDescription(exceptions));
} }
}); });

View File

@@ -17,6 +17,7 @@ package com.jetbrains.python.sdk;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.intellij.execution.ExecutionException;
import com.intellij.facet.ui.FacetEditorValidator; import com.intellij.facet.ui.FacetEditorValidator;
import com.intellij.facet.ui.FacetValidatorsManager; import com.intellij.facet.ui.FacetValidatorsManager;
import com.intellij.openapi.application.Application; import com.intellij.openapi.application.Application;
@@ -49,7 +50,6 @@ import com.intellij.util.NullableConsumer;
import com.intellij.util.PathUtil; import com.intellij.util.PathUtil;
import com.intellij.util.PlatformUtils; import com.intellij.util.PlatformUtils;
import com.intellij.webcore.packaging.PackagesNotificationPanel; import com.intellij.webcore.packaging.PackagesNotificationPanel;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackageManager; import com.jetbrains.python.packaging.PyPackageManager;
import com.jetbrains.python.packaging.PyPackageService; import com.jetbrains.python.packaging.PyPackageService;
import com.jetbrains.python.sdk.flavors.VirtualEnvSdkFlavor; import com.jetbrains.python.sdk.flavors.VirtualEnvSdkFlavor;
@@ -421,7 +421,7 @@ public class CreateVirtualEnvDialog extends IdeaDialog {
indicator.setText("Creating virtual environment for " + basicSdk.getName()); indicator.setText("Creating virtual environment for " + basicSdk.getName());
myPath = packageManager.createVirtualEnv(getDestination(), useGlobalSitePackages()); myPath = packageManager.createVirtualEnv(getDestination(), useGlobalSitePackages());
} }
catch (final PyExternalProcessException e) { catch (final ExecutionException e) {
ApplicationManager.getApplication().invokeLater(new Runnable() { ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@@ -42,7 +42,6 @@ import com.intellij.util.io.ZipUtil;
import com.jetbrains.python.PyBundle; import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PyNames; import com.jetbrains.python.PyNames;
import com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil; import com.jetbrains.python.codeInsight.userSkeletons.PyUserSkeletonsUtil;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackageManager; import com.jetbrains.python.packaging.PyPackageManager;
import com.jetbrains.python.psi.resolve.PythonSdkPathCache; import com.jetbrains.python.psi.resolve.PythonSdkPathCache;
import com.jetbrains.python.remote.PythonRemoteInterpreterManager; import com.jetbrains.python.remote.PythonRemoteInterpreterManager;
@@ -351,7 +350,7 @@ public class PySkeletonRefresher {
// Force loading packages // Force loading packages
PyPackageManager.getInstance(mySdk).getPackages(false); PyPackageManager.getInstance(mySdk).getPackages(false);
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
// ignore - already logged // ignore - already logged
} }
} }

View File

@@ -15,6 +15,7 @@
*/ */
package com.jetbrains.python.testing; package com.jetbrains.python.testing;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.ServiceManager;
@@ -33,7 +34,6 @@ import com.intellij.util.messages.MessageBus;
import com.intellij.util.ui.update.MergingUpdateQueue; import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update; import com.intellij.util.ui.update.Update;
import com.jetbrains.python.PyNames; import com.jetbrains.python.PyNames;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackageManager; import com.jetbrains.python.packaging.PyPackageManager;
import com.jetbrains.python.sdk.PySdkUtil; import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkType; import com.jetbrains.python.sdk.PythonSdkType;
@@ -134,7 +134,7 @@ public class VFSTestFrameworkListener implements ApplicationComponent {
try { try {
return packageManager.findPackage(testPackageName, false) != null; return packageManager.findPackage(testPackageName, false) != null;
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
LOG.info("Can't load package list " + e.getMessage()); LOG.info("Can't load package list " + e.getMessage());
} }
return null; return null;

View File

@@ -15,6 +15,7 @@
*/ */
package com.jetbrains.python.testing.pytest; package com.jetbrains.python.testing.pytest;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Location; import com.intellij.execution.Location;
import com.intellij.execution.actions.ConfigurationContext; import com.intellij.execution.actions.ConfigurationContext;
import com.intellij.openapi.module.Module; import com.intellij.openapi.module.Module;
@@ -28,7 +29,6 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFileSystemItem; import com.intellij.psi.PsiFileSystemItem;
import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.webcore.packaging.PackageVersionComparator; import com.intellij.webcore.packaging.PackageVersionComparator;
import com.jetbrains.python.packaging.PyExternalProcessException;
import com.jetbrains.python.packaging.PyPackage; import com.jetbrains.python.packaging.PyPackage;
import com.jetbrains.python.packaging.PyPackageManager; import com.jetbrains.python.packaging.PyPackageManager;
import com.jetbrains.python.psi.PyClass; import com.jetbrains.python.psi.PyClass;
@@ -106,7 +106,7 @@ public class PyTestConfigurationProducer extends PythonTestConfigurationProducer
keywords = pyClass.getName() + "." + keywords; keywords = pyClass.getName() + "." + keywords;
} }
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
keywords = pyClass.getName() + "." + keywords; keywords = pyClass.getName() + "." + keywords;
} }
} }

View File

@@ -1,6 +1,7 @@
package com.jetbrains.env.python; package com.jetbrains.env.python;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
@@ -44,11 +45,7 @@ public class PyPackagingTest extends PyEnvTestCase {
try { try {
packages = PyPackageManager.getInstance(sdk).getPackages(false); packages = PyPackageManager.getInstance(sdk).getPackages(false);
} }
catch (PyExternalProcessException e) { catch (ExecutionException ignored) {
final int retcode = e.getRetcode();
if (retcode != PyPackageManagerImpl.ERROR_NO_PIP && retcode != PyPackageManagerImpl.ERROR_NO_SETUPTOOLS) {
fail(String.format("Error for interpreter '%s': %s", sdk.getHomePath(), e.getMessage()));
}
} }
if (packages != null) { if (packages != null) {
assertTrue(packages.size() > 0); assertTrue(packages.size() > 0);
@@ -87,7 +84,7 @@ public class PyPackagingTest extends PyEnvTestCase {
catch (IOException e) { catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
throw new RuntimeException(String.format("Error for interpreter '%s': %s", sdk.getHomePath(), e.getMessage()), e); throw new RuntimeException(String.format("Error for interpreter '%s': %s", sdk.getHomePath(), e.getMessage()), e);
} }
} }
@@ -123,7 +120,7 @@ public class PyPackagingTest extends PyEnvTestCase {
final PyPackage pip2 = findPackage("pip", packages3); final PyPackage pip2 = findPackage("pip", packages3);
assertNull(pip2); assertNull(pip2);
} }
catch (PyExternalProcessException e) { catch (ExecutionException e) {
new RuntimeException(String.format("Error for interpreter '%s': %s", sdk.getHomePath(), e.getMessage()), e); new RuntimeException(String.format("Error for interpreter '%s': %s", sdk.getHomePath(), e.getMessage()), e);
} }
catch (IOException e) { catch (IOException e) {