[Mercurial] IDEA-55993: invoking HgSetExecutableDialog from the AWT thread; handling null returned from HgIdentifyCommand.

This commit is contained in:
Kirill Likhodedov
2010-06-24 17:06:05 +04:00
parent 7ada2f43e1
commit 5441e20009
3 changed files with 40 additions and 26 deletions
@@ -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;
}
}
@@ -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<String> arguments = new LinkedList<String>();
arguments.add(source);
@@ -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;
}
}