You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2011/05/10 14:57:16 UTC

svn commit: r1101447 - /james/mailet/maven-mailetdocs-plugin/trunk/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java

Author: rdonkin
Date: Tue May 10 12:57:16 2011
New Revision: 1101447

URL: http://svn.apache.org/viewvc?rev=1101447&view=rev
Log:
MAILETDOCS-6 Catch exception when mailet info cannot be loaded and log some details.

Modified:
    james/mailet/maven-mailetdocs-plugin/trunk/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java

Modified: james/mailet/maven-mailetdocs-plugin/trunk/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java
URL: http://svn.apache.org/viewvc/james/mailet/maven-mailetdocs-plugin/trunk/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java?rev=1101447&r1=1101446&r2=1101447&view=diff
==============================================================================
--- james/mailet/maven-mailetdocs-plugin/trunk/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java (original)
+++ james/mailet/maven-mailetdocs-plugin/trunk/src/main/java/org/apache/james/mailet/DefaultDescriptorsExtractor.java Tue May 10 12:57:16 2011
@@ -107,18 +107,10 @@ public class DefaultDescriptorsExtractor
 
         } catch (ClassNotFoundException e) {
             log.error("NotFound: " + e.getMessage());
-        } catch (InstantiationException e) {
-            log.info("IE: " + e.getMessage()+" / Probably an abstract mailet/matcher: "+nextClass.getName());
-        } catch (IllegalAccessException e) {
-            log.error("IAE: " + e.getMessage());
         } catch (SecurityException e) {
             log.error("SE: " + e.getMessage());
-        } catch (NoSuchMethodException e) {
-            log.error("NSME: " + e.getMessage());
         } catch (IllegalArgumentException e) {
             log.error("IAE2: " + e.getMessage());
-        } catch (InvocationTargetException e) {
-            log.error("ITE: " + e.getMessage());
         }
 
         logInterfacesImplemented(log, nextClass);
@@ -127,11 +119,9 @@ public class DefaultDescriptorsExtractor
 
     private MailetMatcherDescriptor describeMatcher(Log log,
             final JavaClass nextClass, final String nameOfNextClass,
-            final Class<?> klass) throws InstantiationException,
-            IllegalAccessException, InvocationTargetException,
-            NoSuchMethodException {
+            final Class<?> klass) {
         
-        final MailetMatcherDescriptor result = buildDescriptor(nextClass,
+        final MailetMatcherDescriptor result = buildDescriptor(log, nextClass,
                 nameOfNextClass, klass, "getMatcherInfo", MailetMatcherDescriptor.Type.MATCHER);
         
         log.info("Found a Matcher: " + klass.getName());
@@ -139,33 +129,50 @@ public class DefaultDescriptorsExtractor
     }
 
 
-    private MailetMatcherDescriptor buildDescriptor(final JavaClass nextClass,
-            final String nameOfNextClass, final Class<?> klass,
-            final String infoMethodName, final Type type)
-            throws InstantiationException, IllegalAccessException,
-            InvocationTargetException, NoSuchMethodException {
+    private MailetMatcherDescriptor buildDescriptor(final Log log, final JavaClass nextClass,
+            final String nameOfClass, final Class<?> klass,
+            final String infoMethodName, final Type type) {
         final MailetMatcherDescriptor result = new MailetMatcherDescriptor();
         result.setName(nextClass.getName());
-        result.setFullyQualifiedName(nameOfNextClass);
+        result.setFullyQualifiedName(nameOfClass);
         result.setClassDocs(nextClass.getComment());
         result.setType(type);
 
-        final Object instance = klass.newInstance();
-        final String info = (String) klass.getMethod(infoMethodName).invoke(instance);
-        if (info != null && info.length() > 0) {
-            result.setInfo(info);
+        try {
+            final Object instance = klass.newInstance();
+            final String info = (String) klass.getMethod(infoMethodName).invoke(instance);
+            if (info != null && info.length() > 0) {
+                result.setInfo(info);
+            }
+        } catch (InstantiationException e) {
+            handleInfoLoadFailure(log, nameOfClass, type, e);
+        } catch (IllegalAccessException e) {
+            handleInfoLoadFailure(log, nameOfClass, type, e);
+        } catch (IllegalArgumentException e) {
+            handleInfoLoadFailure(log, nameOfClass, type, e);
+        } catch (SecurityException e) {
+            handleInfoLoadFailure(log, nameOfClass, type, e);
+        } catch (InvocationTargetException e) {
+            handleInfoLoadFailure(log, nameOfClass, type, e);
+        } catch (NoSuchMethodException e) {
+            handleInfoLoadFailure(log, nameOfClass, type, e);
         }
         return result;
     }
 
 
+    private void handleInfoLoadFailure(final Log log, final String nameOfClass,
+            final Type type, Exception e) {
+        log.info("Cannot load " + type + " info for " + nameOfClass + ": " + e.getMessage());
+        log.debug(e);
+    }
+
+
     private MailetMatcherDescriptor describeMailet(Log log,
             final JavaClass nextClass, final String nameOfNextClass,
-            final Class<?> klass) throws InstantiationException,
-            IllegalAccessException, InvocationTargetException,
-            NoSuchMethodException {
+            final Class<?> klass) {
 
-        final MailetMatcherDescriptor result = buildDescriptor(nextClass,
+        final MailetMatcherDescriptor result = buildDescriptor(log, nextClass,
                 nameOfNextClass, klass, "getMailetInfo", MailetMatcherDescriptor.Type.MAILET);
         
         log.info("Found a Mailet: " + klass.getName());



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org