diff options
| author | Philipp Thun | 2011-02-24 12:06:02 +0000 |
|---|---|---|
| committer | Philipp Thun | 2011-02-25 17:45:08 +0000 |
| commit | f0cf09a66e8895dc0c7ac56a15d50d64194e4f0b (patch) | |
| tree | f660ce3ac4afdbb08b120d9be0fda78d0e6a8ff0 | |
| parent | af995baba72d1ea74b71b9109fd0bbff79ca267b (diff) | |
| download | egit-f0cf09a66e8895dc0c7ac56a15d50d64194e4f0b.tar.gz egit-f0cf09a66e8895dc0c7ac56a15d50d64194e4f0b.tar.xz egit-f0cf09a66e8895dc0c7ac56a15d50d64194e4f0b.zip | |
Improve exception handling during resource decoration
In case a resource cannot be decorated, do not show/ log an error, but
silently ignore this problem (and trace the information). Also keep
track of 'not decoratable' resources and do not try to decorate them
again.
Catch all exceptions that occur during decoration and trace them. Do
not show/ log them as errors - they are only confusing.
Bug: 337116
Bug: 337671
Change-Id: Iae63ecf51b47073c9216762b3d2dee8c458dbb77
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
4 files changed, 73 insertions, 67 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index fbcfa55096..1e0cf7843b 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -2942,12 +2942,6 @@ public class UIText extends NLS { public static String GitBranchSynchronizeWizardPage_deselectAll; /** */ - public static String GitLightweightDecorator_AsynchronousDecorationError; - - /** */ - public static String GitLightweightDecorator_ResourceError; - - /** */ public static String GitTraceConfigurationDialog_ApplyButton; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java index 5cb108ebb9..904525d255 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitDecoratorJob.java @@ -15,6 +15,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.egit.ui.internal.trace.GitTraceLocation; /** * Job decorating Git resources asynchronously @@ -81,8 +82,18 @@ public class GitDecoratorJob extends Job { elements = elementList.toArray(new Object[elementList.size()]); elementList.clear(); } - // Call GitLightweightDecorator to process the decoration requests - GitLightweightDecorator.processDecoration(elements); + try { + // Call GitLightweightDecorator to process the decoration + // requests + GitLightweightDecorator.processDecoration(elements); + } catch (Exception e) { + // Exceptions can be caused by concurrent threads and thus + // should be ignored + if (GitTraceLocation.DECORATION.isActive()) + GitTraceLocation.getTrace().trace( + GitTraceLocation.DECORATION.getLocation(), + "An error occurred during resource decoration", e); //$NON-NLS-1$ + } } return Status.OK_STATUS; } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java index eef36783fa..f1d68208cf 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java @@ -43,6 +43,7 @@ import org.eclipse.egit.ui.UIIcons; import org.eclipse.egit.ui.UIPreferences; import org.eclipse.egit.ui.UIText; import org.eclipse.egit.ui.internal.decorators.IDecoratableResource.Staged; +import org.eclipse.egit.ui.internal.trace.GitTraceLocation; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.IPropertyChangeListener; @@ -98,6 +99,9 @@ public class GitLightweightDecorator extends LabelProvider implements private static final QualifiedName DECORATABLE_RESOURCE_KEY = new QualifiedName( Activator.getPluginId(), "decoratableResource"); //$NON-NLS-1$ + private static final QualifiedName NOT_DECORATABLE_KEY = new QualifiedName( + Activator.getPluginId(), "notDecoratable"); //$NON-NLS-1$ + /** * Bit-mask describing interesting changes for IResourceChangeListener * events @@ -216,23 +220,30 @@ public class GitLightweightDecorator extends LabelProvider implements return; try { - final Long refreshed = (Long) resource - .getSessionProperty(REFRESHED_KEY); - if (refreshed != null) { - // Stored decoratable resource is available - final Long refresh = (Long) resource.getWorkspace().getRoot() - .getSessionProperty(REFRESH_KEY); - if (refresh == null - || refresh.longValue() <= refreshed.longValue()) { - // Stored decoratable resource is up-to-date - final IDecoratableResource decoratableResource = (IDecoratableResource) resource - .getSessionProperty(DECORATABLE_RESOURCE_KEY); - if (decoratableResource != null) { - // Use stored decoratable resource - final DecorationHelper helper = new DecorationHelper( - activator.getPreferenceStore()); - helper.decorate(decoration, decoratableResource); - return; + final Boolean notDecoratable = (Boolean) resource + .getSessionProperty(NOT_DECORATABLE_KEY); + if (notDecoratable != null && notDecoratable.equals(Boolean.TRUE)) { + // Resource is not decoratable, do not try again + return; + } else { + final Long refreshed = (Long) resource + .getSessionProperty(REFRESHED_KEY); + if (refreshed != null) { + // Stored decoratable resource is available + final Long refresh = (Long) resource.getWorkspace() + .getRoot().getSessionProperty(REFRESH_KEY); + if (refresh == null + || refresh.longValue() <= refreshed.longValue()) { + // Stored decoratable resource is up-to-date + final IDecoratableResource decoratableResource = (IDecoratableResource) resource + .getSessionProperty(DECORATABLE_RESOURCE_KEY); + if (decoratableResource != null) { + // Use stored decoratable resource + final DecorationHelper helper = new DecorationHelper( + activator.getPreferenceStore()); + helper.decorate(decoration, decoratableResource); + return; + } } } } @@ -267,21 +278,20 @@ public class GitLightweightDecorator extends LabelProvider implements * * @param elements * the list of elements to be decorated + * @throws IOException */ - static void processDecoration(final Object[] elements) { + static void processDecoration(final Object[] elements) throws IOException { final GitLightweightDecorator decorator = (GitLightweightDecorator) Activator .getDefault().getWorkbench().getDecoratorManager() .getBaseLabelProvider(DECORATOR_ID); if (decorator != null) decorator.prepareDecoration(elements); else - exceptions - .handleException(new CoreException( - Activator - .createErrorStatus(UIText.GitLightweightDecorator_AsynchronousDecorationError))); + throw new RuntimeException( + "Could not retrieve GitLightweightDecorator"); //$NON-NLS-1$ } - private void prepareDecoration(final Object[] elements) { + private void prepareDecoration(final Object[] elements) throws IOException { if (elements == null) return; @@ -291,42 +301,36 @@ public class GitLightweightDecorator extends LabelProvider implements resources[i] = getResource(elements[i]); } - try { - // Calculate resource decorations - IDecoratableResource[] decoratableResources = DecoratableResourceHelper - .createDecoratableResources(resources); - - // Store decoration result in session property for each resource - for (int i = 0; i < decoratableResources.length; i++) { - try { - if (decoratableResources[i] != null) { - // Store decoratable resource in session - resources[i].setSessionProperty( - DECORATABLE_RESOURCE_KEY, - decoratableResources[i]); - // Set (new) 'refreshed' timestamp - resources[i].setSessionProperty(REFRESHED_KEY, - Long.valueOf(System.currentTimeMillis())); - } else { - if (resources[i] != null) - handleException( - resources[i], - new CoreException( - Activator - .createErrorStatus(UIText.GitLightweightDecorator_ResourceError))); + // Calculate resource decorations + IDecoratableResource[] decoratableResources = DecoratableResourceHelper + .createDecoratableResources(resources); + + // Store decoration result in session property for each resource + for (int i = 0; i < decoratableResources.length; i++) { + try { + if (decoratableResources[i] != null) { + // Store decoratable resource in session + resources[i].setSessionProperty(DECORATABLE_RESOURCE_KEY, + decoratableResources[i]); + // Set (new) 'refreshed' timestamp + resources[i].setSessionProperty(REFRESHED_KEY, + Long.valueOf(System.currentTimeMillis())); + } else { + if (resources[i] != null) { + // Set 'notDecoratable' session property + resources[i].setSessionProperty(NOT_DECORATABLE_KEY, + Boolean.TRUE); + if (GitTraceLocation.DECORATION.isActive()) + GitTraceLocation + .getTrace() + .trace(GitTraceLocation.DECORATION + .getLocation(), + "Could not decorate resource: " + resources[i].getFullPath()); //$NON-NLS-1$ } - } catch (CoreException e) { - handleException(resources[i], e); } + } catch (CoreException e) { + handleException(resources[i], e); } - } catch (IOException e) { - exceptions - .handleException(new CoreException( - Activator - .createErrorStatus( - UIText.GitLightweightDecorator_AsynchronousDecorationError, - e))); - return; } // Re-trigger decoration process (in UI thread) diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 8a051f5f51..a90072cd29 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -1035,9 +1035,6 @@ GitBranchSynchronizeWizardPage_branches=Branches GitBranchSynchronizeWizardPage_selectAll=Select All GitBranchSynchronizeWizardPage_deselectAll=Deselect All -GitLightweightDecorator_AsynchronousDecorationError=Asynchronous decoration requests for Git resources could not be processed -GitLightweightDecorator_ResourceError=Resource could not be decorated - GitTraceConfigurationDialog_ApplyButton=&Apply GitTraceConfigurationDialog_DefaultButton=&Default GitTraceConfigurationDialog_DialogTitle=Maintain the Git Trace Configuration |
