mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Refactor HgTagBranchCommand. Handle errors when load branches for action dialogs.
*Remove unnecessary usage of Consumers in HgTagBranchCommand method execution. *Check result of command execution and handle errors.
This commit is contained in:
@@ -114,6 +114,7 @@ hg4idea.merge.please-commit=Merged heads, please commit repository \"{0}\"
|
||||
hg4idea.error.invalidExecutable=\"{0}\" is not a valid mercurial executable
|
||||
hg4idea.integrate.other.head=Other head: {0}
|
||||
hg4idea.error.log.command.execution=Error during log command execution
|
||||
hg4idea.branches.error.description=Couldn't collect information about branches
|
||||
|
||||
hg4idea.dialog.login.password.required=Login and password required
|
||||
hg4idea.dialog.login.description=Login to {0}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.ui.MessageType;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -36,7 +35,7 @@ import org.zmlx.hg4idea.ui.HgPushDialog;
|
||||
import org.zmlx.hg4idea.util.HgErrorUtil;
|
||||
import org.zmlx.hg4idea.util.HgUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -66,7 +65,9 @@ public class HgPusher {
|
||||
}
|
||||
VirtualFile firstRepo = repositories.get(0);
|
||||
final List<HgTagBranch> branches = getBranches(myProject, firstRepo);
|
||||
|
||||
if (branches.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final AtomicReference<HgPushCommand> pushCommand = new AtomicReference<HgPushCommand>();
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
@@ -94,14 +95,13 @@ public class HgPusher {
|
||||
|
||||
@NotNull
|
||||
public static List<HgTagBranch> getBranches(@NotNull Project project, @NotNull VirtualFile root) {
|
||||
final List<HgTagBranch> branchesList = new ArrayList<HgTagBranch>();
|
||||
new HgTagBranchCommand(project, root).listBranches(new Consumer<List<HgTagBranch>>() {
|
||||
@Override
|
||||
public void consume(final List<HgTagBranch> branches) {
|
||||
branchesList.addAll(branches);
|
||||
}
|
||||
});
|
||||
return branchesList;
|
||||
HgCommandResult branchesResult = new HgTagBranchCommand(project, root).collectBranches();
|
||||
if (branchesResult == null) {
|
||||
new HgCommandResultNotifier(project)
|
||||
.notifyError(branchesResult, "Mercurial command failed", HgVcsMessages.message("hg4idea.branches.error.description"));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return HgTagBranchCommand.parseResult(branchesResult);
|
||||
}
|
||||
|
||||
private static void push(final Project project, HgPushCommand command) {
|
||||
|
||||
@@ -53,21 +53,9 @@ public class HgUpdateToAction extends HgAbstractGlobalAction {
|
||||
dialog.show();
|
||||
if (dialog.isOK()) {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
String updateToValue;
|
||||
if (dialog.isBranchSelected() && dialog.getBranch() != null) {
|
||||
updateToValue = dialog.getBranch().getName();
|
||||
}
|
||||
else if (dialog.isTagSelected() && dialog.getTag() != null) {
|
||||
updateToValue = dialog.getTag().getName();
|
||||
}
|
||||
else if (dialog.isRevisionSelected()) {
|
||||
updateToValue = dialog.getRevision();
|
||||
}
|
||||
else {
|
||||
new HgCommandResultNotifier(project).notifyError(null, "Update failed", "Couldn't execute Mercurial command");
|
||||
return;// hg execute command error occurs//
|
||||
}
|
||||
|
||||
String updateToValue = dialog.isBranchSelected()
|
||||
? dialog.getBranch().getName()
|
||||
: dialog.isTagSelected() ? dialog.getTag().getName() : dialog.getRevision();
|
||||
new Task.Backgroundable(project, HgVcsMessages.message("action.hg4idea.updateTo.description", updateToValue)) {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,13 +14,11 @@ package org.zmlx.hg4idea.command;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.zmlx.hg4idea.HgRevisionNumber;
|
||||
import org.zmlx.hg4idea.execution.HgCommandExecutor;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResultHandler;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -57,29 +55,15 @@ public class HgTagBranchCommand {
|
||||
return output.get(0).trim();
|
||||
}
|
||||
|
||||
public void listBranches(final Consumer<List<HgTagBranch>> branchListConsumer) {
|
||||
new HgCommandExecutor(project).execute(repo, "branches", null, new HgCommandResultHandler() {
|
||||
@Override
|
||||
public void process(@Nullable HgCommandResult result) {
|
||||
if (result != null) {
|
||||
branchListConsumer.consume(tokenize(result));
|
||||
}
|
||||
}
|
||||
});
|
||||
public HgCommandResult collectBranches() {
|
||||
return new HgCommandExecutor(project).executeInCurrentThread(repo, "branches", null);
|
||||
}
|
||||
|
||||
public void listTags(final Consumer<List<HgTagBranch>> tagListConsumer) {
|
||||
new HgCommandExecutor(project).execute(repo, "tags", null, new HgCommandResultHandler() {
|
||||
@Override
|
||||
public void process(@Nullable HgCommandResult result) {
|
||||
if (result != null) {
|
||||
tagListConsumer.consume(tokenize(result));
|
||||
}
|
||||
}
|
||||
});
|
||||
public HgCommandResult collectTags() {
|
||||
return new HgCommandExecutor(project).executeInCurrentThread(repo, "tags", null);
|
||||
}
|
||||
|
||||
private static List<HgTagBranch> tokenize(HgCommandResult result) {
|
||||
public static List<HgTagBranch> parseResult(HgCommandResult result) {
|
||||
List<HgTagBranch> branches = new LinkedList<HgTagBranch>();
|
||||
for (final String line : result.getOutputLines()) {
|
||||
Matcher matcher = BRANCH_LINE.matcher(line);
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.zmlx.hg4idea.HgRevisionNumber;
|
||||
@@ -25,6 +24,7 @@ import org.zmlx.hg4idea.command.HgHeadsCommand;
|
||||
import org.zmlx.hg4idea.command.HgTagBranch;
|
||||
import org.zmlx.hg4idea.command.HgTagBranchCommand;
|
||||
import org.zmlx.hg4idea.command.HgWorkingCopyRevisionsCommand;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
@@ -123,15 +123,13 @@ public class HgMergeDialog extends DialogWrapper {
|
||||
}
|
||||
|
||||
private void loadTags(VirtualFile root) {
|
||||
new HgTagBranchCommand(project, root).listTags(new Consumer<List<HgTagBranch>>() {
|
||||
HgCommandResult tagsResult = new HgTagBranchCommand(project, root).collectTags();
|
||||
assert tagsResult != null;
|
||||
final List<HgTagBranch> tags = HgTagBranchCommand.parseResult(tagsResult);
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void consume(final List<HgTagBranch> tags) {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
|
||||
}
|
||||
});
|
||||
public void run() {
|
||||
tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ package org.zmlx.hg4idea.ui;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.zmlx.hg4idea.command.HgTagBranch;
|
||||
import org.zmlx.hg4idea.command.HgTagBranchCommand;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
@@ -124,15 +124,13 @@ public class HgUpdateToDialog extends DialogWrapper {
|
||||
}
|
||||
|
||||
private void loadTags(VirtualFile root) {
|
||||
new HgTagBranchCommand(project, root).listTags(new Consumer<List<HgTagBranch>>() {
|
||||
HgCommandResult tagsResult = new HgTagBranchCommand(project, root).collectTags();
|
||||
assert tagsResult != null;
|
||||
final List<HgTagBranch> tags = HgTagBranchCommand.parseResult(tagsResult);
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void consume(final List<HgTagBranch> tags) {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
|
||||
}
|
||||
});
|
||||
public void run() {
|
||||
tagSelector.setModel(new DefaultComboBoxModel(tags.toArray()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,8 +22,11 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.zmlx.hg4idea.HgVcsMessages;
|
||||
import org.zmlx.hg4idea.action.HgCommandResultNotifier;
|
||||
import org.zmlx.hg4idea.command.HgTagBranch;
|
||||
import org.zmlx.hg4idea.command.HgTagBranchCommand;
|
||||
import org.zmlx.hg4idea.execution.HgCommandResult;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -42,15 +45,21 @@ public class HgUiUtil {
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
for (final VirtualFile repo : repos) {
|
||||
new HgTagBranchCommand(project, repo).listBranches(new Consumer<List<HgTagBranch>>() {
|
||||
@Override
|
||||
public void consume(final List<HgTagBranch> branches) {
|
||||
branchesForRepos.put(repo, branches);
|
||||
}
|
||||
});
|
||||
HgCommandResult result = new HgTagBranchCommand(project, repo).collectBranches();
|
||||
if (result == null) {
|
||||
indicator.cancel();
|
||||
return;
|
||||
}
|
||||
branchesForRepos.put(repo, HgTagBranchCommand.parseResult(result));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
new HgCommandResultNotifier(project)
|
||||
.notifyError(null, "Mercurial command failed", HgVcsMessages.message("hg4idea.branches.error.description"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
successHandler.consume(branchesForRepos);
|
||||
|
||||
Reference in New Issue
Block a user