patch: Used "ThrowableComputable" instead of "TransparentlyFailedValueI"

This commit is contained in:
Konstantin Kolosovsky
2016-12-13 16:48:16 +03:00
parent 97d04d6ffa
commit a6c17364ad
8 changed files with 40 additions and 43 deletions
@@ -19,13 +19,11 @@ package com.intellij.openapi.diff.impl.patch;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Couple;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.text.LineTokenizer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValue;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -34,6 +32,9 @@ import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.intellij.util.containers.ContainerUtil.filter;
import static com.intellij.util.containers.ContainerUtil.findAll;
public class PatchReader {
@NonNls public static final String NO_NEWLINE_SIGNATURE = UnifiedDiffWriter.NO_NEWLINE_SIGNATURE;
private final List<String> myLines;
@@ -134,7 +135,7 @@ public class PatchReader {
@NotNull
public List<TextFilePatch> getTextPatches() {
return ContainerUtil.findAll(myPatches, TextFilePatch.class);
return findAll(myPatches, TextFilePatch.class);
}
@NotNull
@@ -184,25 +185,23 @@ public class PatchReader {
myPatches = myPatchContentParser.getResult();
}
public TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> getAdditionalInfo(final Set<String> filterByPaths) {
final TransparentlyFailedValue<Map<String, Map<String, CharSequence>>, PatchSyntaxException>
value = new TransparentlyFailedValue<>();
@NotNull
public ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> getAdditionalInfo(@Nullable Set<String> paths) {
ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> result;
PatchSyntaxException e = myAdditionalInfoParser.getSyntaxException();
final Map<String, Map<String, CharSequence>> map = myAdditionalInfoParser.getResultMap();
final Map<String, Map<String, CharSequence>>newMap = new HashMap<>();
for (Map.Entry<String, Map<String, CharSequence>> entry : map.entrySet()) {
final Map<String, CharSequence> innerMap = entry.getValue();
if (filterByPaths == null || filterByPaths.contains(entry.getKey())) {
newMap.put(entry.getKey(), innerMap);
}
}
value.set(newMap);
final PatchSyntaxException e = myAdditionalInfoParser.getSyntaxException();
if (e != null) {
value.fail(e);
result = () -> {
throw e;
};
}
return value;
else {
Map<String, Map<String, CharSequence>> additionalInfo =
filter(myAdditionalInfoParser.getResultMap(), path -> paths == null || paths.contains(path));
result = () -> additionalInfo;
}
return result;
}
private static class AdditionalInfoParser implements Parser {
@@ -20,9 +20,9 @@ import com.intellij.openapi.diff.impl.patch.formove.PatchApplier;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vcs.changes.CommitContext;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
@@ -54,7 +54,7 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor<AbstractFil
public void apply(@NotNull List<FilePatch> remaining, @NotNull MultiMap<VirtualFile, AbstractFilePatchInProgress> patchGroupsToApply,
@Nullable LocalChangeList localList,
@Nullable String fileName,
@Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
final CommitContext commitContext = new CommitContext();
applyAdditionalInfoBefore(myProject, additionalInfo, commitContext);
final Collection<PatchApplier> appliers = getPatchAppliers(patchGroupsToApply, localList, commitContext);
@@ -62,7 +62,7 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor<AbstractFil
}
protected ApplyPatchStatus executeAndApplyAdditionalInfo(@Nullable LocalChangeList localList,
@Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
@NotNull CommitContext commitContext,
@NotNull Collection<PatchApplier> appliers) {
final ApplyPatchStatus applyPatchStatus = PatchApplier.executePatchGroup(appliers, localList);
@@ -92,8 +92,8 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor<AbstractFil
public static void applyAdditionalInfoBefore(final Project project,
TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
CommitContext commitContext) {
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
CommitContext commitContext) {
applyAdditionalInfoImpl(project, additionalInfo, commitContext, new Consumer<InfoGroup>() {
@Override
public void consume(InfoGroup infoGroup) {
@@ -103,8 +103,8 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor<AbstractFil
}
private static void applyAdditionalInfo(final Project project,
TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
CommitContext commitContext) {
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
CommitContext commitContext) {
applyAdditionalInfoImpl(project, additionalInfo, commitContext, new Consumer<InfoGroup>() {
@Override
public void consume(InfoGroup infoGroup) {
@@ -114,14 +114,13 @@ public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor<AbstractFil
}
private static void applyAdditionalInfoImpl(final Project project,
TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo,
CommitContext commitContext, final Consumer<InfoGroup> worker) {
final PatchEP[] extensions = Extensions.getExtensions(PatchEP.EP_NAME, project);
if (extensions.length == 0) return;
if (additionalInfo != null) {
try {
final Map<String, Map<String, CharSequence>> map = additionalInfo.get();
for (Map.Entry<String, Map<String, CharSequence>> entry : map.entrySet()) {
for (Map.Entry<String, Map<String, CharSequence>> entry : additionalInfo.compute().entrySet()) {
final String path = entry.getKey();
final Map<String, CharSequence> innerMap = entry.getValue();
@@ -17,8 +17,8 @@ package com.intellij.openapi.vcs.changes.patch;
import com.intellij.openapi.diff.impl.patch.FilePatch;
import com.intellij.openapi.diff.impl.patch.PatchSyntaxException;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.Nls;
@@ -40,5 +40,5 @@ public interface ApplyPatchExecutor<T extends AbstractFilePatchInProgress> {
void apply(@NotNull List<FilePatch> remaining, @NotNull final MultiMap<VirtualFile, T> patchGroupsToApply,
@Nullable final LocalChangeList localList,
@Nullable String fileName,
@Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo);
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo);
}
@@ -23,12 +23,12 @@ import com.intellij.openapi.diff.impl.patch.TextFilePatch;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.AbstractVcsHelper;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.CommitContext;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI;
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
import com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList;
import com.intellij.openapi.vcs.changes.shelf.ShelvedChangesViewManager;
@@ -65,7 +65,7 @@ public class ImportToShelfExecutor implements ApplyPatchExecutor<TextFilePatchIn
public void apply(@NotNull List<FilePatch> remaining, @NotNull final MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply,
@Nullable LocalChangeList localList,
@Nullable final String fileName,
@Nullable final TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
if (fileName == null) {
LOG.error("Patch file name shouldn't be null");
return;
@@ -94,7 +94,7 @@ public class ImportToShelfExecutor implements ApplyPatchExecutor<TextFilePatchIn
if (additionalInfo != null) {
try {
final Map<String, PatchEP> extensions = new HashMap<>();
for (Map.Entry<String, Map<String, CharSequence>> entry : additionalInfo.get().entrySet()) {
for (Map.Entry<String, Map<String, CharSequence>> entry : additionalInfo.compute().entrySet()) {
final String filePath = entry.getKey();
Map<String, CharSequence> extToValue = entry.getValue();
for (Map.Entry<String, CharSequence> innerEntry : extToValue.entrySet()) {
@@ -21,9 +21,9 @@ import com.intellij.openapi.diff.impl.patch.FilePatch;
import com.intellij.openapi.diff.impl.patch.PatchSyntaxException;
import com.intellij.openapi.diff.impl.patch.formove.PatchApplier;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vcs.changes.CommitContext;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI;
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
import com.intellij.openapi.vcs.changes.shelf.ShelvedBinaryFilePatch;
import com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList;
@@ -53,7 +53,7 @@ public class UnshelvePatchDefaultExecutor extends ApplyPatchDefaultExecutor {
@NotNull MultiMap<VirtualFile, AbstractFilePatchInProgress> patchGroupsToApply,
@Nullable LocalChangeList localList,
@Nullable String fileName,
@Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
final CommitContext commitContext = new CommitContext();
applyAdditionalInfoBefore(myProject, additionalInfo, commitContext);
final Collection<PatchApplier> appliers = getPatchAppliers(patchGroupsToApply, localList, commitContext);
@@ -966,9 +966,7 @@ public class ShelveChangesManager extends AbstractProjectComponent implements JD
char[] text = FileUtil.loadFileText(new File(patchPath), CharsetToolkit.UTF8);
PatchReader reader = new PatchReader(new CharArrayCharSequence(text), loadContent);
final List<TextFilePatch> textFilePatches = reader.readTextPatches();
final TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo = reader.getAdditionalInfo(
null);
ApplyPatchDefaultExecutor.applyAdditionalInfoBefore(project, additionalInfo, commitContext);
ApplyPatchDefaultExecutor.applyAdditionalInfoBefore(project, reader.getAdditionalInfo(null), commitContext);
return textFilePatches;
}
@@ -24,9 +24,9 @@ import com.intellij.openapi.fileChooser.FileSaverDescriptor;
import com.intellij.openapi.fileChooser.FileSaverDialog;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vcs.changes.CommitContext;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.TransparentlyFailedValueI;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchExecutor;
import com.intellij.openapi.vcs.changes.patch.PatchWriter;
import com.intellij.openapi.vcs.changes.patch.TextFilePatchInProgress;
@@ -74,7 +74,7 @@ public class ApplyPatchSaveToFileExecutor implements ApplyPatchExecutor<TextFile
@NotNull MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply,
@Nullable LocalChangeList localList,
@Nullable String fileName,
@Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Save Patch to", ""), myProject);
VirtualFileWrapper targetFile = dialog.save(myProject.getBaseDir(), "TheirsChanges.patch");
@@ -31,6 +31,7 @@ import com.intellij.openapi.ui.MessageDialogBuilder;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.actions.BackgroundTaskGroup;
import com.intellij.openapi.vcs.changes.*;
@@ -202,7 +203,7 @@ public class MergeFromTheirsResolver extends BackgroundTaskGroup {
@NotNull MultiMap<VirtualFile, TextFilePatchInProgress> patchGroupsToApply,
@Nullable LocalChangeList localList,
@Nullable String fileName,
@Nullable TransparentlyFailedValueI<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
@Nullable ThrowableComputable<Map<String, Map<String, CharSequence>>, PatchSyntaxException> additionalInfo) {
List<FilePatch> patches = null;
VcsException exception = null;
try {