Better CVS error reporting

This commit is contained in:
Bas Leijdekkers
2011-10-21 16:35:10 +02:00
parent cd737cc4bc
commit bc17c2a7c3
11 changed files with 113 additions and 147 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -22,64 +22,76 @@ import com.intellij.openapi.vcs.VcsException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Iterator;
/**
* author: lesya
*/
public class CvsResultEx implements CvsResult {
private final List<VcsException> myErrors = new ArrayList<VcsException>();
private final List<VcsException> myWarnings = new ArrayList<VcsException>();
private boolean myIsCanceled = false;
@Override
public void setIsCanceled() {
myIsCanceled = true;
}
@Override
public List<VcsException> getErrors() {
return myErrors;
final ArrayList<VcsException> errors = new ArrayList<VcsException>();
for (VcsException error : myErrors) {
if (!error.isWarning()) {
errors.add(error);
}
}
return errors;
}
public List<VcsException> getWarnings() {
return myWarnings;
final ArrayList<VcsException> warnings = new ArrayList<VcsException>();
for (VcsException error : myErrors) {
if (error.isWarning()) {
warnings.add(error);
}
}
return warnings;
}
@Override
public boolean isCanceled() {
return myIsCanceled;
}
@Override
public void addAllErrors(Collection<VcsException> errors) {
myErrors.addAll(errors);
}
public void addAllWarnings(Collection<VcsException> warnings) {
myWarnings.addAll(warnings);
}
@Override
public boolean hasNoErrors() {
return myErrors.isEmpty();
for (VcsException error : myErrors) {
if (!error.isWarning()) {
return false;
}
}
return true;
}
@Override
public VcsException composeError() {
return myErrors.iterator().next();
}
@Override
public void addError(VcsException error) {
myErrors.add(error);
}
@Override
public List<VcsException> getErrorsAndWarnings() {
ArrayList<VcsException> result = new ArrayList<VcsException>();
result.addAll(myErrors);
for (Iterator<VcsException> iterator = myWarnings.iterator(); iterator.hasNext();) {
VcsException vcsException = iterator.next();
vcsException.setIsWarning(true);
}
result.addAll(myWarnings);
return result;
return myErrors;
}
public boolean finishedUnsuccessfully(boolean shouldBeLoggedIn, CvsHandler handler) {
public boolean finishedUnsuccessfully(CvsHandler handler) {
checkIsCanceled(handler);
if (!hasNoErrors()) return true;
if (isCanceled()) return true;
@@ -132,8 +132,6 @@ public abstract class StickyHeadGetter {
public void addError(VcsException ex) {
logSuccess.set(Boolean.FALSE);
}
public void addWarning(VcsException ex) {
}
public List<VcsException> getErrors() {
return null;
}
@@ -42,9 +42,11 @@ import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.pom.Navigatable;
import com.intellij.ui.content.ContentManager;
import com.intellij.ui.errorView.ContentManagerProvider;
import com.intellij.ui.errorView.ErrorViewFactory;
import com.intellij.util.text.DateFormatUtil;
import com.intellij.util.ui.ErrorTreeView;
import com.intellij.util.ui.MessageCategory;
import org.jetbrains.annotations.NotNull;
@@ -91,9 +93,7 @@ public class CvsOperationExecutor {
this(true, project, modalityState);
}
public void performActionSync(final CvsHandler handler,
final CvsOperationExecutorCallback callback) {
public void performActionSync(final CvsHandler handler, final CvsOperationExecutorCallback callback) {
final CvsTabbedWindow tabbedWindow = myIsQuietOperation ? null : openTabbedWindow(handler);
final Runnable finish = new Runnable() {
@@ -101,15 +101,14 @@ public class CvsOperationExecutor {
public void run() {
try {
myResult.addAllErrors(handler.getErrorsExceptAborted());
myResult.addAllWarnings(handler.getWarnings());
handler.finish();
if (myProject == null || myProject != null && !myProject.isDisposed()) {
showErrors(handler.getErrorsExceptAborted(), handler.getWarnings(), tabbedWindow);
showErrors(handler, tabbedWindow);
}
}
finally {
try {
if (myResult.finishedUnsuccessfully(true, handler)) {
if (myResult.finishedUnsuccessfully(handler)) {
callback.executionFinished(false);
}
else {
@@ -136,12 +135,12 @@ public class CvsOperationExecutor {
handler.beforeLogin();
if (myResult.finishedUnsuccessfully(false, handler)) return;
if (myResult.finishedUnsuccessfully(handler)) return;
setText(CvsBundle.message("progress.text.preparing.for.action", handler.getTitle()));
handler.run(myProject, myExecutor);
if (myResult.finishedUnsuccessfully(true, handler)) return;
if (myResult.finishedUnsuccessfully(handler)) return;
}
catch (ProcessCanceledException ex) {
@@ -200,72 +199,49 @@ public class CvsOperationExecutor {
return ProgressManager.getInstance().getProgressIndicator() != null;
}
protected void showErrors(final List<VcsException> errors, CvsTabbedWindow tabbedWindow) {
showErrors(errors, new ArrayList<VcsException>(), tabbedWindow);
}
protected void showErrors(final List<VcsException> errors,
final List<VcsException> warnings,
final CvsTabbedWindow tabbedWindow) {
protected void showErrors(final CvsHandler handler, final CvsTabbedWindow tabbedWindow) {
final List<VcsException> errors = handler.getErrorsExceptAborted();
if (!myShowErrors || myIsQuietOperation) return;
if (tabbedWindow == null) {
if (errors.isEmpty() && warnings.isEmpty()) return;
if (errors.isEmpty()) return;
final List<String> messages = new ArrayList<String>();
for (VcsException error : errors) {
if (! StringUtil.isEmptyOrSpaces(error.getMessage())) {
messages.add(error.getMessage());
}
}
for (VcsException error : warnings) {
if (! StringUtil.isEmptyOrSpaces(error.getMessage())) {
messages.add(error.getMessage());
}
}
final String errorMessage = StringUtil.join(messages, "\n");
Messages.showErrorDialog(errorMessage, "CVS error");
Messages.showErrorDialog(errorMessage, "CVS Error");
return;
}
if (errors.isEmpty() && warnings.isEmpty()) {
if (errors.isEmpty()) {
tabbedWindow.hideErrors();
}
else {
ErrorTreeView errorTreeView = tabbedWindow.addErrorsTreeView(ErrorViewFactory.SERVICE.getInstance()
.createErrorTreeView(myProject,
null,
true,
new AnAction[]{
(DefaultActionGroup)ActionManager.getInstance()
.getAction("CvsActions")},
new AnAction[]{new AnAction(
CvsBundle.message(
"configure.global.cvs.settings.action.name"), null,
IconLoader.getIcon("/nodes/cvs_global.png")) {
public void actionPerformed(AnActionEvent e) {
new ConfigureCvsGlobalSettingsDialog().show();
}
}, new ReconfigureCvsRootAction()
},
new ContentManagerProvider() {
public ContentManager getParentContent() {
return tabbedWindow.getContentManager();
}
}));
fillErrors(errors, warnings, errorTreeView);
ErrorTreeView errorTreeView = tabbedWindow.addErrorsTreeView(
ErrorViewFactory.SERVICE.getInstance().createErrorTreeView(
myProject, null, true,
new AnAction[]{(DefaultActionGroup)ActionManager.getInstance().getAction("CvsActions")},
new AnAction[]{new GlobalCvsSettingsAction(), new ReconfigureCvsRootAction()},
new ContentManagerProvider() {
public ContentManager getParentContent() {
return tabbedWindow.getContentManager();
}
}));
for (final VcsException exception : errors) {
final String groupName = DateFormatUtil.formatDateTime(System.currentTimeMillis()) + ' ' + handler.getTitle();
if (exception.isWarning()) {
errorTreeView.addMessage(MessageCategory.WARNING, exception.getMessages(), groupName, DummyNavigatable.INSTANCE,
null, null, exception);
} else {
errorTreeView.addMessage(MessageCategory.ERROR, exception.getMessages(), groupName, DummyNavigatable.INSTANCE,
null, null, exception);
}
}
tabbedWindow.ensureVisible(myProject);
}
}
private static void fillErrors(final List<VcsException> errors, final List<VcsException> warnings, final ErrorTreeView errorTreeView) {
for (final VcsException exception : errors) {
errorTreeView.addMessage(MessageCategory.ERROR, exception.getMessages(), exception.getVirtualFile(), -1, -1, exception);
}
for (final VcsException exception : warnings) {
errorTreeView.addMessage(MessageCategory.WARNING, exception.getMessages(), exception.getVirtualFile(), -1, -1, exception);
}
}
@NotNull private static Editor createView(Project project) {
EditorFactory editorFactory = EditorFactory.getInstance();
Document document = editorFactory.createDocument("");
@@ -288,7 +264,6 @@ public class CvsOperationExecutor {
}
}
@Nullable
public CvsTabbedWindow openTabbedWindow(final CvsHandler output) {
if (ApplicationManager.getApplication().isUnitTestMode()) return null;
@@ -334,6 +309,35 @@ public class CvsOperationExecutor {
return myResult;
}
private static class DummyNavigatable implements Navigatable {
public static final Navigatable INSTANCE = new DummyNavigatable();
private DummyNavigatable() {}
@Override
public void navigate(boolean requestFocus) {}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
}
private static class GlobalCvsSettingsAction extends AnAction {
public GlobalCvsSettingsAction() {
super(CvsBundle.message("configure.global.cvs.settings.action.name"), null, IconLoader.getIcon("/nodes/cvs_global.png"));
}
public void actionPerformed(AnActionEvent e) {
new ConfigureCvsGlobalSettingsDialog().show();
}
}
private class ReconfigureCvsRootAction extends AnAction {
public ReconfigureCvsRootAction() {
super(CvsBundle.message("action.name.reconfigure.cvs.root"), null, IconLoader.getIcon("/nodes/cvs_roots.png"));
@@ -102,10 +102,6 @@ public abstract class CvsHandler extends CvsMessagesAdapter{
return result;
}
public List<VcsException> getWarnings() {
return myErrorMessageProcessor.getWarnings();
}
@Override
public void addFileMessage(String message, ICvsFileSystem cvsFileSystem) {
setText2(message);
@@ -27,34 +27,21 @@ import java.util.List;
public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorProcessor {
private final List<VcsException> myErrors;
private final List<VcsException> myWarnings;
public ErrorMessagesProcessor(List<VcsException> errors) {
myErrors = errors;
myWarnings = new ArrayList<VcsException>();
}
public ErrorMessagesProcessor() {
this(new ArrayList<VcsException>());
}
public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) {
addErrorOnCurrentMessage(relativeFilePath, message, cvsFileSystem, myErrors, cvsRoot);
}
public void addWarning(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) {
addErrorOnCurrentMessage(relativeFilePath, message, cvsFileSystem, myWarnings, cvsRoot);
}
private static void addErrorOnCurrentMessage(String relativeFileName,
String message,
ICvsFileSystem cvsFileSystem,
List<VcsException> collection,
String cvsRoot) {
VirtualFile vFile = getVirtualFile(cvsFileSystem, relativeFileName);
public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot, boolean warning) {
VirtualFile vFile = getVirtualFile(cvsFileSystem, relativeFilePath);
VcsException vcsException = new CvsException(message, cvsRoot);
if (vFile != null) vcsException.setVirtualFile(vFile);
collection.add(vcsException);
vcsException.setIsWarning(warning);
myErrors.add(vcsException);
}
private static VirtualFile getVirtualFile(ICvsFileSystem cvsFileSystem, String relativeFileName) {
@@ -67,20 +54,7 @@ public class ErrorMessagesProcessor extends CvsMessagesAdapter implements ErrorP
return myErrors;
}
public List<VcsException> getWarnings() {
return myWarnings;
}
public void clear() {
myErrors.clear();
myWarnings.clear();
}
public void addError(VcsException ex) {
myErrors.add(ex);
}
public void addWarning(VcsException ex) {
myWarnings.add(ex);
}
}
@@ -25,6 +25,6 @@ import java.util.List;
public interface ErrorProcessor {
void addError(VcsException ex);
void addWarning(VcsException ex);
List<VcsException> getErrors();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -41,7 +41,6 @@ public class CvsCompositeListener implements CvsListenersCollection, CvsMessages
for (final Object myListener : myListeners) {
((CvsMessagesListener)myListener).addFileMessage(message);
}
}
public void addMessage(String message) {
@@ -62,25 +61,15 @@ public class CvsCompositeListener implements CvsListenersCollection, CvsMessages
}
}
public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) {
public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot, boolean warning) {
for (final Object myListener : myListeners) {
((CvsMessagesListener)myListener).addError(message, relativeFilePath, cvsFileSystem, cvsRoot);
((CvsMessagesListener)myListener).addError(message, relativeFilePath, cvsFileSystem, cvsRoot, warning);
}
}
public void addWarning(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) {
for (final Object myListener : myListeners) {
((CvsMessagesListener)myListener).addWarning(message, relativeFilePath, cvsFileSystem, cvsRoot);
}
}
public void addFileMessage(String message, ICvsFileSystem cvsFileSystem) {
for (final Object myListener : myListeners) {
((CvsMessagesListener)myListener).addFileMessage(message, cvsFileSystem);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -15,8 +15,6 @@
*/
package com.intellij.cvsSupport2.cvsoperations.cvsMessages;
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.MessageEvent;
import com.intellij.cvsSupport2.cvsoperations.cvsMessages.MessageEvent;
import org.netbeans.lib.cvsclient.file.ICvsFileSystem;
/**
@@ -35,10 +33,7 @@ public class CvsMessagesAdapter implements CvsMessagesListener{
public void commandStarted(String command) {
}
public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) {
}
public void addWarning(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot) {
public void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot, boolean warning) {
}
public void addFileMessage(String message, ICvsFileSystem cvsFileSystem) {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -15,21 +15,22 @@
*/
package com.intellij.cvsSupport2.cvsoperations.cvsMessages;
import com.intellij.CvsBundle;
import org.netbeans.lib.cvsclient.file.ICvsFileSystem;
import java.text.MessageFormat;
public interface CvsMessagesListener {
CvsMessagesListener STANDARD_OUTPUT = new CvsMessagesAdapter() {
@Override
public void addMessage(MessageEvent event) {
if (event.getMessage().length() > 0)
System.out.println(event.getMessage());
System.out.flush();
}
@Override
public void commandStarted(String command) {
System.out.println(com.intellij.CvsBundle.message("output.command.started", command));
System.out.println(CvsBundle.message("output.command.started", command));
System.out.flush();
}
@@ -43,9 +44,7 @@ public interface CvsMessagesListener {
void commandStarted(String command);
void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot);
void addWarning(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot);
void addError(String message, String relativeFilePath, ICvsFileSystem cvsFileSystem, String cvsRoot, boolean warning);
void addFileMessage(String message, ICvsFileSystem cvsFileSystem);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -159,7 +159,8 @@ public class StoringLineSeparatorsLocalFileWriter implements ILocalFileWriter {
}
finally {
CvsUtil.skip(inputStream, length);
myErrorProcessor.addWarning(vcsEx);
vcsEx.setIsWarning(true);
myErrorProcessor.addError(vcsEx);
}
}
@@ -175,7 +176,7 @@ public class StoringLineSeparatorsLocalFileWriter implements ILocalFileWriter {
}
}
private String getLineSeparatorFor(VirtualFile virtualFile) {
private static String getLineSeparatorFor(VirtualFile virtualFile) {
try {
return FileDocumentManager.getInstance().getLineSeparator(virtualFile, null);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2011 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.
@@ -31,8 +31,6 @@ public interface CvsResult {
void addAllErrors(Collection<VcsException> errors);
void addAllWarnings(Collection<VcsException> warnings);
boolean hasNoErrors();
VcsException composeError();