mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[lvcs]: create wrapper for exception occurred in lvcs module; handle it in a user friendly manner when rollback patch
This commit is contained in:
@@ -32,7 +32,7 @@ public interface Label {
|
||||
}
|
||||
};
|
||||
|
||||
void revert(@NotNull Project project, @NotNull VirtualFile file);
|
||||
void revert(@NotNull Project project, @NotNull VirtualFile file) throws LocalHistoryException;
|
||||
|
||||
ByteContent getByteContent(String path);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.history;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper for any exception occurred during local history actions and processes
|
||||
*/
|
||||
public class LocalHistoryException extends Exception {
|
||||
public LocalHistoryException(@NotNull String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public LocalHistoryException(@NotNull String message, @Nullable Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,6 @@ import com.intellij.history.integration.ui.models.DirectoryHistoryDialogModel;
|
||||
import com.intellij.history.integration.ui.models.EntireFileHistoryDialogModel;
|
||||
import com.intellij.history.integration.ui.models.HistoryDialogModel;
|
||||
import com.intellij.history.utils.LocalHistoryLog;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
@@ -193,7 +190,7 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone
|
||||
private Label label(final LabelImpl impl) {
|
||||
return new Label() {
|
||||
@Override
|
||||
public void revert(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
public void revert(@NotNull Project project, @NotNull VirtualFile file) throws LocalHistoryException {
|
||||
revertToLabel(project, file, impl);
|
||||
}
|
||||
|
||||
@@ -249,16 +246,13 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone
|
||||
return myGateway;
|
||||
}
|
||||
|
||||
private void revertToLabel(@NotNull Project project, @NotNull VirtualFile f, @NotNull LabelImpl impl) {
|
||||
private void revertToLabel(@NotNull Project project, @NotNull VirtualFile f, @NotNull LabelImpl impl) throws LocalHistoryException{
|
||||
HistoryDialogModel dirHistoryModel = f.isDirectory()
|
||||
? new DirectoryHistoryDialogModel(project, myGateway, myVcs, f)
|
||||
: new EntireFileHistoryDialogModel(project, myGateway, myVcs, f);
|
||||
int leftRev = findRevisionIndexToRevert(dirHistoryModel, impl);
|
||||
if (leftRev < 0) {
|
||||
notifyUser(project,
|
||||
String.format("Couldn't find label revision. Try to use local history dialog for %s and perform revert manually.",
|
||||
f.getName()));
|
||||
return;
|
||||
throw new LocalHistoryException("Couldn't find label revision");
|
||||
}
|
||||
if (leftRev == 0) return; // we shouldn't revert because no changes found to revert;
|
||||
try {
|
||||
@@ -266,12 +260,7 @@ public class LocalHistoryImpl extends LocalHistory implements ApplicationCompone
|
||||
dirHistoryModel.createReverter().revert();
|
||||
}
|
||||
catch (IOException e) {
|
||||
LocalHistoryLog.LOG.error(String.format("Couldn't revert %s to local history label.", f.getName()), e);
|
||||
throw new LocalHistoryException(String.format("Couldn't revert %s to local history label.", f.getName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyUser(@NotNull Project project, @NotNull String message) {
|
||||
new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Can't rollback some changes", message,
|
||||
NotificationType.ERROR).notify(project);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -17,11 +17,10 @@ package com.intellij.history.integration.revertion;
|
||||
|
||||
import com.intellij.history.Label;
|
||||
import com.intellij.history.LocalHistory;
|
||||
import com.intellij.history.LocalHistoryException;
|
||||
import com.intellij.history.integration.IntegrationTestCase;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HistoryReverterToLabelTest extends IntegrationTestCase {
|
||||
|
||||
public void testFileCreation() throws Exception {
|
||||
@@ -33,7 +32,7 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase {
|
||||
assertNotNull(myRoot.findChild("first.txt"));
|
||||
}
|
||||
|
||||
private void revertToLabel(Label testLabel, VirtualFile root) {
|
||||
private void revertToLabel(Label testLabel, VirtualFile root) throws LocalHistoryException {
|
||||
testLabel.revert(myProject, root);
|
||||
}
|
||||
|
||||
@@ -44,7 +43,7 @@ public class HistoryReverterToLabelTest extends IntegrationTestCase {
|
||||
assertNull(myRoot.findChild("foo.txt"));
|
||||
}
|
||||
|
||||
public void testPutLabelAndRevertInstantly() throws IOException {
|
||||
public void testPutLabelAndRevertInstantly() throws Exception {
|
||||
VirtualFile f = createChildData(myRoot, "foo.txt");
|
||||
setBinaryContent(f, new byte[]{123}, -1, 4000, this);
|
||||
final Label testLabel = LocalHistory.getInstance().putSystemLabel(myProject, "testLabel");
|
||||
|
||||
+12
-1
@@ -16,12 +16,15 @@
|
||||
package com.intellij.openapi.diff.impl.patch.formove;
|
||||
|
||||
import com.intellij.history.Label;
|
||||
import com.intellij.history.LocalHistoryException;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsNotifier;
|
||||
import com.intellij.openapi.vcs.changes.ui.FilePathChangesTreeList;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -87,7 +90,15 @@ class UndoApplyPatchDialog extends DialogWrapper {
|
||||
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
myBeforeLabel.revert(myProject, myProject.getBaseDir());
|
||||
final VirtualFile baseDir = myProject.getBaseDir();
|
||||
try {
|
||||
myBeforeLabel.revert(myProject, baseDir);
|
||||
}
|
||||
catch (LocalHistoryException e) {
|
||||
VcsNotifier.getInstance(myProject)
|
||||
.notifyImportantWarning("Rollback Failed", String.format("Try to use local history dialog for %s and perform revert manually.",
|
||||
baseDir.getName()));
|
||||
}
|
||||
}
|
||||
}, "Rollback Applied Changes...", true, myProject);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user