From 5441e20009212ddc412f77a2a8b0ba02ba806167 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 24 Jun 2010 17:06:05 +0400 Subject: [PATCH] [Mercurial] IDEA-55993: invoking HgSetExecutableDialog from the AWT thread; handling null returned from HgIdentifyCommand. --- .../zmlx/hg4idea/HgExecutableValidator.java | 52 +++++++++++++------ .../hg4idea/command/HgIdentifyCommand.java | 2 + .../org/zmlx/hg4idea/ui/HgCloneDialog.java | 12 ++--- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgExecutableValidator.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgExecutableValidator.java index d775d7fbec7c..ce8e3aeabff0 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgExecutableValidator.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgExecutableValidator.java @@ -12,41 +12,59 @@ // limitations under the License. package org.zmlx.hg4idea; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.ui.GuiUtils; import org.zmlx.hg4idea.command.HgVersionCommand; import org.zmlx.hg4idea.ui.HgSetExecutableDialog; +import java.lang.reflect.InvocationTargetException; + public class HgExecutableValidator { + private static final Logger LOG = Logger.getInstance(HgExecutableValidator.class.getName()); private final Project project; + private boolean myValidHgExecutable; public HgExecutableValidator(Project project) { this.project = project; } - public boolean check(HgGlobalSettings globalSettings) { - HgVersionCommand command = new HgVersionCommand(); + public boolean check(final HgGlobalSettings globalSettings) { + final HgVersionCommand command = new HgVersionCommand(); if (command.isValid(globalSettings.getHgExecutable())) { return true; } - String previousHgPath = globalSettings.getHgExecutable(); - boolean validHgExecutable; - HgSetExecutableDialog dialog; - do { - dialog = new HgSetExecutableDialog(project); - dialog.setBadHgPath(previousHgPath); - dialog.show(); - validHgExecutable = dialog.isOK() && command.isValid(dialog.getNewHgPath()); - previousHgPath = dialog.getNewHgPath(); - } while (!validHgExecutable && dialog.isOK()); - - if (validHgExecutable) { - globalSettings.setHgExecutable(dialog.getNewHgPath()); - return true; + if (ApplicationManager.getApplication().isUnitTestMode()) { + return false; } + myValidHgExecutable = false; - return false; + try { + GuiUtils.runOrInvokeAndWait(new Runnable() { + public void run() { + String previousHgPath = globalSettings.getHgExecutable(); + HgSetExecutableDialog dialog; + do { + dialog = new HgSetExecutableDialog(project); + dialog.setBadHgPath(previousHgPath); + dialog.show(); + myValidHgExecutable = dialog.isOK() && command.isValid(dialog.getNewHgPath()); + previousHgPath = dialog.getNewHgPath(); + } while (!myValidHgExecutable && dialog.isOK()); + if (myValidHgExecutable) { + globalSettings.setHgExecutable(dialog.getNewHgPath()); + } + } + }); + } catch (InvocationTargetException e) { + LOG.error(e); + } catch (InterruptedException e) { + LOG.error(e); + } + return myValidHgExecutable; } } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgIdentifyCommand.java b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgIdentifyCommand.java index fb1b8f6a0c32..8ff3a68e2a42 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgIdentifyCommand.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/command/HgIdentifyCommand.java @@ -1,6 +1,7 @@ package org.zmlx.hg4idea.command; import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.Nullable; import java.nio.charset.Charset; import java.util.Collections; @@ -24,6 +25,7 @@ public class HgIdentifyCommand { this.source = source; } + @Nullable public HgCommandResult execute() { List arguments = new LinkedList(); arguments.add(source); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCloneDialog.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCloneDialog.java index e420d5ca923e..d7f3702e36d3 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCloneDialog.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgCloneDialog.java @@ -20,9 +20,6 @@ import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.*; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.uiDesigner.core.GridConstraints; -import com.intellij.uiDesigner.core.GridLayoutManager; -import com.intellij.uiDesigner.core.Spacer; import org.zmlx.hg4idea.HgVcsMessages; import org.zmlx.hg4idea.command.HgCommandResult; import org.zmlx.hg4idea.command.HgIdentifyCommand; @@ -30,13 +27,11 @@ import org.zmlx.hg4idea.command.HgIdentifyCommand; import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.net.URI; import java.net.URISyntaxException; -import java.util.ResourceBundle; /** * A dialog for the mercurial clone options @@ -346,11 +341,10 @@ public class HgCloneDialog extends DialogWrapper { } private static boolean testRepository(Project project, final String repositoryUrl) { - HgIdentifyCommand identifyCommand = new HgIdentifyCommand(project); + final HgIdentifyCommand identifyCommand = new HgIdentifyCommand(project); identifyCommand.setSource(repositoryUrl); - HgCommandResult result = identifyCommand.execute(); - - return result.getExitValue() == 0; + final HgCommandResult result = identifyCommand.execute(); + return result != null && result.getExitValue() == 0; } }