Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2003-07-30 18:51:27 +0000
committerJean Michel-Lemieux2003-07-30 18:51:27 +0000
commitf4f8ce736d90fab6a156807bc7d57c5ef4eeabde (patch)
tree7ceb4db25b1f40c85b2cf0fc6a7a1d1511573cdb
parent5089b2f279d0fedc0db7ab0b87f06c92e4c43150 (diff)
downloadeclipse.platform.team-f4f8ce736d90fab6a156807bc7d57c5ef4eeabde.tar.gz
eclipse.platform.team-f4f8ce736d90fab6a156807bc7d57c5ef4eeabde.tar.xz
eclipse.platform.team-f4f8ce736d90fab6a156807bc7d57c5ef4eeabde.zip
Moved exception collector to team.core and is used by CVS decorator and subscribe revent handler.
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ExceptionCollector.java157
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java29
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ExceptionCollector.java99
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java2
4 files changed, 179 insertions, 108 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ExceptionCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ExceptionCollector.java
new file mode 100644
index 000000000..8fb182356
--- /dev/null
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ExceptionCollector.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.core;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * Collects exceptions and can be configured to ignore duplicates exceptions. Exceptions can be logged
+ * and a MultiStatus containing all collected exceptions can be returned.
+ *
+ * @see org.eclipse.core.runtime.MultiStatus
+ * @see org.eclipse.core.runtime.IStatus
+ *
+ * @since 3.0
+ */
+public class ExceptionCollector {
+
+ private Map exceptionBucket = new HashMap();
+ private List statuses = new ArrayList();
+ private String message;
+ private String pluginId;
+ private int severity;
+ private ILog log;
+ private boolean ignoreDuplicates = false;
+
+ /**
+ * Creates a collector and initializes the parameters for the top-level exception
+ * that would be returned from <code>getStatus</code> is exceptions are collected.
+ *
+ * @param message a human-readable message, localized to the current locale
+ * @param pluginId the unique identifier of the relevant plug-in
+ * @param severity the severity; one of <code>OK</code>,
+ * <code>ERROR</code>, <code>INFO</code>, or <code>WARNING</code>
+ * @param code the plug-in-specific status code, or <code>OK</code>
+ * @param log the log to output the exceptions to, or <code>null</code> if
+ * exceptions should not be logged.
+ */
+ public ExceptionCollector(String message, String pluginId, int severity, ILog log) {
+ this.message = message;
+ this.pluginId = pluginId;
+ this.severity = severity;
+ this.log = log;
+ }
+
+ /**
+ * Clears the exceptions collected.
+ */
+ public void clear() {
+ statuses.clear();
+ exceptionBucket.clear();
+ }
+
+ /**
+ * Returns a status that represents the exceptions collected. If the collector
+ * is empty <code>IStatus.OK</code> is returned. Otherwise a MultiStatus containing
+ * all collected exceptions is returned.
+ * @return a multistatus containing the exceptions collected or IStatus.OK if
+ * the collector is empty.
+ */
+ public IStatus getStatus() {
+ if(statuses.isEmpty()) {
+ return Status.OK_STATUS;
+ } else {
+ MultiStatus multiStatus = new MultiStatus(pluginId, severity, message, null);
+ Iterator it = statuses.iterator();
+ while (it.hasNext()) {
+ IStatus status = (IStatus) it.next();
+ multiStatus.merge(status);
+ }
+ return multiStatus;
+ }
+ }
+
+ /**
+ * Returns whether duplicate exceptions are being ignored.
+ * @return <code>true</code> if this collector is ignoring duplicate exceptions, and
+ * <code>false</code> otherwise.
+ */
+ public boolean isIgnoreDuplicates() {
+ return ignoreDuplicates;
+ }
+
+ /**
+ * Sets whether duplicate exceptions are being ignored.
+ * @param ignoreDuplicates <code>true</code> if this collector should ignore duplicate
+ * exceptions, and <code>false</code> otherwise.
+ */
+ public void setIgnoreDuplicates(boolean ignoreDuplicates) {
+ this.ignoreDuplicates = ignoreDuplicates;
+ }
+
+ /**
+ * Add this exception to the collector. If a log was specified in the constructor
+ * then the exception will be output to the log. You can retreive exceptions
+ * using <code>getStatus</code>.
+ *
+ * @param exception the exception to collect
+ */
+ public void handleException(Exception e) {
+ IStatus status = null;
+ if(e instanceof CoreException) {
+ status = ((CoreException)e).getStatus();
+ }
+ if(status != null) {
+ logStatus(status);
+ IStatus[] children = status.getChildren();
+ for (int i = 0; i < children.length; i++) {
+ IStatus status2 = children[i];
+ logStatus(status2);
+ }
+ }
+ }
+
+ /**
+ * Log and accumulate exceptions once for each {plugid,code} combination.
+ */
+ private void logStatus(IStatus status) {
+ String pluginId = status.getPlugin();
+ List codes = (List)exceptionBucket.get(pluginId);
+ Integer code = new Integer(status.getCode());
+ if(codes != null) {
+ if(codes.contains(code) && isIgnoreDuplicates()) {
+ return;
+ }
+ }
+ // collect the status
+ statuses.add(status);
+
+ // update counts for this exception
+ codes = new ArrayList(1);
+ codes.add(code);
+ exceptionBucket.put(pluginId, codes);
+
+ // log if necessary
+ if(log != null) {
+ log.log(new Status(status.getSeverity(), pluginId, status.getCode(), message, status.getException()));
+ }
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java
index 627d9b117..e43dc7f0e 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSLightweightDecorator.java
@@ -23,6 +23,7 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IDecoration;
@@ -46,6 +47,7 @@ import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.resources.EclipseSynchronizer;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
+import org.eclipse.team.internal.core.ExceptionCollector;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.ui.ISharedImages;
@@ -62,6 +64,8 @@ public class CVSLightweightDecorator
private static ImageDescriptor newResource;
private static ImageDescriptor edited;
+ private static ExceptionCollector exceptions;
+
/*
* Define a cached image descriptor which only creates the image data once
*/
@@ -92,6 +96,7 @@ public class CVSLightweightDecorator
public CVSLightweightDecorator() {
CVSProviderPlugin.addResourceStateChangeListener(this);
CVSProviderPlugin.broadcastDecoratorEnablementChanged(true /* enabled */);
+ exceptions = new ExceptionCollector(Policy.bind("CVSDecorator.exceptionMessage"), CVSUIPlugin.ID, IStatus.ERROR, CVSUIPlugin.getPlugin().getLog());
}
public static boolean isDirty(final ICVSResource cvsResource) {
@@ -99,7 +104,7 @@ public class CVSLightweightDecorator
return !cvsResource.isIgnored() && cvsResource.isModified(null);
} catch (CVSException e) {
//if we get an error report it to the log but assume dirty
- CVSUIPlugin.log(e);
+ handleException(e);
return true;
}
}
@@ -176,6 +181,7 @@ public class CVSLightweightDecorator
} catch (CVSException e) {
// The was an exception in isIgnored. Don't decorate
//todo should log this error
+ handleException(e);
return;
}
@@ -265,7 +271,7 @@ public class CVSLightweightDecorator
CVSDecoratorConfiguration.decorate(decoration, format, bindings);
} catch (CVSException e) {
- CVSUIPlugin.log(e);
+ handleException(e);
return;
}
}
@@ -343,7 +349,7 @@ public class CVSLightweightDecorator
}
}
} catch (CVSException e) {
- CVSUIPlugin.log(e);
+ handleException(e);
return null;
}
}
@@ -372,7 +378,7 @@ public class CVSLightweightDecorator
}
}
} catch (CVSException e) {
- CVSUIPlugin.log(e);
+ handleException(e);
return null;
}
}
@@ -382,7 +388,7 @@ public class CVSLightweightDecorator
try {
decorateEdited = provider.isWatchEditEnabled();
} catch (CVSException e1) {
- CVSUIPlugin.log(e1);
+ handleException(e1);
decorateEdited = false;
}
@@ -403,7 +409,7 @@ public class CVSLightweightDecorator
}
} catch (CVSException e) {
// log the exception and show the shared overlay
- CVSUIPlugin.log(e);
+ handleException(e);
}
}
return checkedIn;
@@ -449,7 +455,7 @@ public class CVSLightweightDecorator
});
postLabelEvent(new LabelProviderChangedEvent(this, resources.toArray()));
} catch (CoreException e) {
- CVSProviderPlugin.log(e);
+ handleException(e);
}
}
@@ -522,4 +528,11 @@ public class CVSLightweightDecorator
super.dispose();
CVSProviderPlugin.broadcastDecoratorEnablementChanged(false /* disabled */);
}
-}
+
+ /**
+ * Handle exceptions that occur in the decorator.
+ */
+ private static void handleException(Exception e) {
+ exceptions.handleException(e);
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ExceptionCollector.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ExceptionCollector.java
deleted file mode 100644
index 675d7a4ce..000000000
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ExceptionCollector.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2003 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.team.internal.ui;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.ILog;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
-
-public class ExceptionCollector {
-
- private Map exceptionBucket = new HashMap();
- private List statuses = new ArrayList();
- private String message;
- private String pluginId;
- private int code;
- private ILog log;
-
- public ExceptionCollector(String message, String pluginId, int code, ILog log) {
- this.message = message;
- this.pluginId = pluginId;
- this.code = code;
- this.log = log;
- }
-
- public void clear() {
- statuses.clear();
- exceptionBucket.clear();
- }
-
- public IStatus getStatus() {
- if(statuses.isEmpty()) {
- return Status.OK_STATUS;
- } else {
- MultiStatus multiStatus = new MultiStatus(pluginId, code, message, null);
- Iterator it = statuses.iterator();
- while (it.hasNext()) {
- IStatus status = (IStatus) it.next();
- multiStatus.merge(status);
- }
- return multiStatus;
- }
- }
-
- /**
- * Handle exceptions that occur in the decorator.
- */
- public void handleException(Exception e) {
- IStatus status = null;
- if(e instanceof CoreException) {
- status = ((CoreException)e).getStatus();
- }
- if(status != null) {
- logStatus(status);
- IStatus[] children = status.getChildren();
- for (int i = 0; i < children.length; i++) {
- IStatus status2 = children[i];
- logStatus(status2);
- }
- }
- }
-
- /**
- * Log exceptions once for each {plugid,code} combination. This is to avoid
- * flooding the log.
- */
- private void logStatus(IStatus status) {
- String pluginId = status.getPlugin();
- List codes = (List)exceptionBucket.get(pluginId);
- Integer code = new Integer(status.getCode());
- if(codes != null) {
- if(codes.contains(code)) {
- return;
- }
- }
- codes = new ArrayList(1);
- codes.add(code);
- exceptionBucket.put(pluginId, codes);
- statuses.add(status);
- if(log != null) {
- log.log(new Status(status.getSeverity(), pluginId, status.getCode(), message, status.getException()));
- }
- }
-}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java
index 7fd83dea2..746eb9785 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/sets/SubscriberEventHandler.java
@@ -22,7 +22,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.SyncInfo;
-import org.eclipse.team.internal.ui.ExceptionCollector;
+import org.eclipse.team.internal.core.ExceptionCollector;
import org.eclipse.team.internal.ui.IPreferenceIds;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.internal.ui.TeamUIPlugin;

Back to the top