Added getFixes() to PyExternalProcessException instead of withHandler()

These exceptions and fixes are now used for displaying notifications in
the notification area of the package management panel.
This commit is contained in:
Andrey Vlasovskikh
2014-09-23 17:05:44 +04:00
parent f4d21231ee
commit 00cdaa2b96
5 changed files with 142 additions and 116 deletions

View File

@@ -0,0 +1,27 @@
/*
* 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 com.intellij.openapi.projectRoots.Sdk;
import org.jetbrains.annotations.NotNull;
/**
* @author vlan
*/
public interface PyExecutionFix {
@NotNull String getName();
void run(@NotNull Sdk sdk);
}

View File

@@ -16,11 +16,11 @@
package com.jetbrains.python.packaging;
import com.intellij.execution.ExecutionException;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
@@ -30,19 +30,22 @@ import java.util.regex.Pattern;
public class PyExternalProcessException extends ExecutionException {
private static final Pattern WITH_CR_DELIMITER_PATTERN = Pattern.compile("(?<=\r|\n|\r\n)");
private final int myRetcode;
@NotNull private String myName;
@NotNull private List<String> myArgs;
@NotNull private String myMessage;
@NotNull private final List<? extends PyExecutionFix> myFixes;
private Pair<String, Runnable> myHandler = null;
public PyExternalProcessException(@NotNull String name, @NotNull List<String> args, @NotNull String message) {
this(name, args, message, Collections.<PyExecutionFix>emptyList());
}
public PyExternalProcessException(int retcode, @NotNull String name, @NotNull List<String> args, @NotNull String message) {
public PyExternalProcessException(@NotNull String name, @NotNull List<String> args, @NotNull String message,
@NotNull List<? extends PyExecutionFix> fixes) {
super(String.format("External process error '%s %s':\n%s", name, StringUtil.join(args, " "), message));
myRetcode = retcode;
myName = name;
myArgs = args;
myMessage = stripLinesWithoutLineFeeds(message);
myFixes = fixes;
}
@Override
@@ -57,10 +60,6 @@ public class PyExternalProcessException extends ExecutionException {
return b.toString();
}
public int getRetcode() {
return myRetcode;
}
@NotNull
public String getName() {
return myName;
@@ -88,17 +87,8 @@ public class PyExternalProcessException extends ExecutionException {
return StringUtil.join(result, "");
}
public PyExternalProcessException withHandler(@NotNull String name, @NotNull Runnable handler) {
myHandler = Pair.create(name, handler);
return this;
}
public boolean hasHandler() {
return myHandler != null;
}
public Pair<String, Runnable> getHandler() {
return myHandler;
@NotNull
public List<? extends PyExecutionFix> getFixes() {
return myFixes;
}
}