From ad9b6eba2a2d615967e150bbfdbc531150bbfda9 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Tue, 15 Feb 2011 19:39:01 +0000 Subject: [PATCH] o Improved robustness against incompatible event spies git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1071027 13f79535-47bb-0310-9956-ffa450edef68 --- .../eventspy/internal/EventSpyDispatcher.java | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java b/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java index da15391b9c..e527336faa 100644 --- a/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java +++ b/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java @@ -85,15 +85,11 @@ public class EventSpyDispatcher } catch ( Exception e ) { - String msg = "Failed to initialize spy " + eventSpy.getClass().getName() + ": " + e.getMessage(); - if ( logger.isDebugEnabled() ) - { - logger.warn( msg, e ); - } - else - { - logger.warn( msg ); - } + logError( "initialize", e, eventSpy ); + } + catch ( LinkageError e ) + { + logError( "initialize", e, eventSpy ); } } } @@ -112,15 +108,11 @@ public class EventSpyDispatcher } catch ( Exception e ) { - String msg = "Failed to forward event to spy " + eventSpy.getClass().getName() + ": " + e.getMessage(); - if ( logger.isDebugEnabled() ) - { - logger.warn( msg, e ); - } - else - { - logger.warn( msg ); - } + logError( "notify", e, eventSpy ); + } + catch ( LinkageError e ) + { + logError( "notify", e, eventSpy ); } } } @@ -139,17 +131,27 @@ public class EventSpyDispatcher } catch ( Exception e ) { - String msg = "Failed to close spy " + eventSpy.getClass().getName() + ": " + e.getMessage(); - if ( logger.isDebugEnabled() ) - { - logger.warn( msg, e ); - } - else - { - logger.warn( msg ); - } + logError( "close", e, eventSpy ); + } + catch ( LinkageError e ) + { + logError( "close", e, eventSpy ); } } } + private void logError( String action, Throwable e, EventSpy spy ) + { + String msg = "Failed to " + action + " spy " + spy.getClass().getName() + ": " + e.getMessage(); + + if ( logger.isDebugEnabled() ) + { + logger.warn( msg, e ); + } + else + { + logger.warn( msg ); + } + } + }