mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-78314 SVN; Commit doesn't happen: prevent pre-commit check runtime exception from killing to parent commit process
report to the user that code analysis failed
This commit is contained in:
+7
-1
@@ -152,8 +152,14 @@ public class CodeAnalysisBeforeCheckinHandler extends CheckinHandler {
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
return ReturnResult.CANCEL;
|
||||
} catch (Exception e) {
|
||||
if (Messages.showOkCancelDialog(myProject,
|
||||
"Code analysis failed with exception: " + e.getClass().getName() + ": " + e.getMessage(),
|
||||
"Code analysis failed", "&Commit", "&Cancel", null) == DialogWrapper.OK_EXIT_CODE) {
|
||||
return ReturnResult.COMMIT;
|
||||
}
|
||||
return ReturnResult.CANCEL;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
return ReturnResult.COMMIT;
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.ide.errorTreeView.NewErrorTreeViewPanel;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
@@ -41,8 +42,10 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.ui.MessageCategory;
|
||||
import com.intellij.vcsUtil.Rethrow;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import sun.util.LocaleServiceProviderPool;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -51,6 +54,8 @@ import java.util.*;
|
||||
*/
|
||||
public class CodeSmellDetectorImpl extends CodeSmellDetector {
|
||||
private final Project myProject;
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.impl.CodeSmellDetectorImpl");
|
||||
private Exception myException;
|
||||
|
||||
public CodeSmellDetectorImpl(final Project project) {
|
||||
myProject = project;
|
||||
@@ -107,31 +112,41 @@ public class CodeSmellDetectorImpl extends CodeSmellDetector {
|
||||
|
||||
boolean completed = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
public void run() {
|
||||
@Nullable final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
|
||||
for (int i = 0; i < filesToCheck.size(); i++) {
|
||||
int i = 0;
|
||||
try {
|
||||
@Nullable final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
|
||||
for (; i < filesToCheck.size(); i++) {
|
||||
|
||||
if (progress != null && progress.isCanceled()) throw new ProcessCanceledException();
|
||||
if (progress != null && progress.isCanceled()) throw new ProcessCanceledException();
|
||||
|
||||
VirtualFile file = filesToCheck.get(i);
|
||||
VirtualFile file = filesToCheck.get(i);
|
||||
|
||||
if (progress != null) {
|
||||
progress.setText(VcsBundle.message("searching.for.code.smells.processing.file.progress.text", file.getPresentableUrl()));
|
||||
progress.setFraction((double)i / (double)filesToCheck.size());
|
||||
}
|
||||
|
||||
final PsiFile psiFile = manager.findFile(file);
|
||||
if (psiFile != null) {
|
||||
final Document document = fileManager.getDocument(file);
|
||||
if (document != null) {
|
||||
final List<CodeSmellInfo> codeSmells = findCodeSmells(psiFile, progress, document);
|
||||
result.addAll(codeSmells);
|
||||
if (progress != null) {
|
||||
progress.setText(VcsBundle.message("searching.for.code.smells.processing.file.progress.text", file.getPresentableUrl()));
|
||||
progress.setFraction((double)i / (double)filesToCheck.size());
|
||||
}
|
||||
|
||||
final PsiFile psiFile = manager.findFile(file);
|
||||
if (psiFile != null) {
|
||||
final Document document = fileManager.getDocument(file);
|
||||
if (document != null) {
|
||||
final List<CodeSmellInfo> codeSmells = findCodeSmells(psiFile, progress, document);
|
||||
result.addAll(codeSmells);
|
||||
}
|
||||
}
|
||||
throw new NullPointerException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error(e);
|
||||
myException = e;
|
||||
}
|
||||
}
|
||||
}, VcsBundle.message("checking.code.smells.progress.title"), true, myProject);
|
||||
|
||||
if (!completed) throw new ProcessCanceledException();
|
||||
if (myException != null) {
|
||||
Rethrow.reThrowRuntime(myException);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user