mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-145065 test git executable under cancellable modal progress
This commit is contained in:
@@ -46,8 +46,9 @@ import static com.intellij.notification.NotificationDisplayType.STICKY_BALLOON;
|
||||
*/
|
||||
public abstract class ExecutableValidator {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(ExecutableValidator.class);
|
||||
public static final int TIMEOUT_MS = Registry.intValue("vcs.executable.validator.timeout.sec", 60) * 1000;
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(ExecutableValidator.class);
|
||||
private static final NotificationGroup ourNotificationGroup = new NotificationGroup("External Executable Critical Failures",
|
||||
STICKY_BALLOON, true);
|
||||
@NotNull protected final Project myProject;
|
||||
@@ -106,7 +107,7 @@ public abstract class ExecutableValidator {
|
||||
commandLine.setExePath(executable);
|
||||
commandLine.addParameters(processParameters);
|
||||
CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset());
|
||||
ProcessOutput result = handler.runProcess(Registry.intValue("vcs.executable.validator.timeout.sec", 60) * 1000);
|
||||
ProcessOutput result = handler.runProcess(TIMEOUT_MS);
|
||||
boolean timeout = result.isTimeout();
|
||||
int exitCode = result.getExitCode();
|
||||
String stderr = result.getStderr();
|
||||
|
||||
@@ -21,10 +21,13 @@ import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.application.ApplicationNamesInfo;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.EnumComboBoxModel;
|
||||
import com.intellij.ui.ListCellRendererWrapper;
|
||||
@@ -111,10 +114,19 @@ public class GitVcsPanel {
|
||||
if (myAppSettings != null) {
|
||||
myAppSettings.setPathToGit(executable);
|
||||
}
|
||||
final GitVersion version;
|
||||
GitVersion version;
|
||||
try {
|
||||
version = GitVersion.identifyVersion(executable);
|
||||
} catch (Exception e) {
|
||||
version = ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable<GitVersion, Exception>() {
|
||||
@Override
|
||||
public GitVersion compute() throws Exception {
|
||||
return GitVersion.identifyVersion(executable);
|
||||
}
|
||||
}, "Testing Git Executable...", true, myVcs.getProject());
|
||||
}
|
||||
catch (ProcessCanceledException pce) {
|
||||
return;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Messages.showErrorDialog(myRootPanel, e.getMessage(), GitBundle.getString("find.git.error.title"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,15 @@
|
||||
package git4idea.config;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.intellij.execution.ExecutableValidator;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.CapturingProcessHandler;
|
||||
import com.intellij.execution.process.ProcessOutput;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
@@ -142,11 +146,18 @@ public final class GitVersion implements Comparable<GitVersion> {
|
||||
commandLine.setExePath(gitExecutable);
|
||||
commandLine.addParameter("--version");
|
||||
CapturingProcessHandler handler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.getDefaultSystemCharset());
|
||||
ProcessOutput result = handler.runProcess(30 * 1000);
|
||||
ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
ProcessOutput result = indicator == null ?
|
||||
handler.runProcess(ExecutableValidator.TIMEOUT_MS) :
|
||||
handler.runProcessWithProgressIndicator(indicator);
|
||||
if (result.isTimeout()) {
|
||||
throw new TimeoutException("Couldn't identify the version of Git - stopped by timeout.");
|
||||
}
|
||||
if (result.getExitCode() != 0 || !result.getStderr().isEmpty()) {
|
||||
else if (result.isCancelled()) {
|
||||
LOG.info("Cancelled by user. exitCode=" + result.getExitCode());
|
||||
throw new ProcessCanceledException();
|
||||
}
|
||||
else if (result.getExitCode() != 0 || !result.getStderr().isEmpty()) {
|
||||
LOG.info("getVersion exitCode=" + result.getExitCode() + " errors: " + result.getStderr());
|
||||
// anyway trying to parse
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user