diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/TaskAdapter.java b/proposal/myrmidon/src/main/org/apache/tools/ant/TaskAdapter.java index 91151d8ba..90b9321b4 100644 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/TaskAdapter.java +++ b/proposal/myrmidon/src/main/org/apache/tools/ant/TaskAdapter.java @@ -8,6 +8,7 @@ package org.apache.tools.ant; import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import org.apache.myrmidon.api.TaskException; /** @@ -16,74 +17,42 @@ import org.apache.myrmidon.api.TaskException; * * @author costin@dnt.ro */ -public class TaskAdapter extends Task +public class TaskAdapter + extends Task { - Object proxy; + private Object m_proxy; - /** - * Set the target object class - * - * @param o The new Proxy value - */ - public void setProxy( Object o ) + public void setProxy( final Object proxy ) { - this.proxy = o; + this.m_proxy = proxy; } - public Object getProxy() - { - return this.proxy; - } - - /** - * Do the execution. - * - * @exception TaskException Description of Exception - */ public void execute() throws TaskException { - Method setProjectM = null; try { - Class c = proxy.getClass(); - setProjectM = - c.getMethod( "setProject", new Class[]{Project.class} ); - if( setProjectM != null ) - { - setProjectM.invoke( proxy, new Object[]{getProject()} ); - } + final Class clazz = m_proxy.getClass(); + final Method method = clazz.getMethod( "execute", new Class[ 0 ] ); + method.invoke( m_proxy, null ); } - catch( NoSuchMethodException e ) + catch( final NoSuchMethodException nsme ) { - // ignore this if the class being used as a task does not have - // a set project method. + final String message = "No public execute() in " + m_proxy.getClass(); + getLogger().error( message ); + throw new TaskException( message ); } - catch( Exception ex ) + catch( final Exception e ) { - final String message = "Error setting project in " + proxy.getClass(); - getLogger().error( message, ex ); - throw new TaskException( "Error", ex ); - } - - Method executeM = null; - try - { - Class c = proxy.getClass(); - executeM = c.getMethod( "execute", new Class[ 0 ] ); - if( executeM == null ) + Throwable target = e; + if( e instanceof InvocationTargetException ) { - getLogger().error( "No public execute() in " + proxy.getClass() ); - throw new TaskException( "No public execute() in " + proxy.getClass() ); + target = ((InvocationTargetException)e).getTargetException(); } - executeM.invoke( proxy, null ); - return; - } - catch( Exception ex ) - { - getLogger().error( "Error in " + proxy.getClass() ); - throw new TaskException( "Error", ex ); - } + final String message = "Error invoking " + m_proxy.getClass(); + getLogger().error( message, target ); + throw new TaskException( message, target ); + } } } diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/TaskAdapter.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/TaskAdapter.java index 91151d8ba..90b9321b4 100644 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/TaskAdapter.java +++ b/proposal/myrmidon/src/todo/org/apache/tools/ant/TaskAdapter.java @@ -8,6 +8,7 @@ package org.apache.tools.ant; import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; import org.apache.myrmidon.api.TaskException; /** @@ -16,74 +17,42 @@ import org.apache.myrmidon.api.TaskException; * * @author costin@dnt.ro */ -public class TaskAdapter extends Task +public class TaskAdapter + extends Task { - Object proxy; + private Object m_proxy; - /** - * Set the target object class - * - * @param o The new Proxy value - */ - public void setProxy( Object o ) + public void setProxy( final Object proxy ) { - this.proxy = o; + this.m_proxy = proxy; } - public Object getProxy() - { - return this.proxy; - } - - /** - * Do the execution. - * - * @exception TaskException Description of Exception - */ public void execute() throws TaskException { - Method setProjectM = null; try { - Class c = proxy.getClass(); - setProjectM = - c.getMethod( "setProject", new Class[]{Project.class} ); - if( setProjectM != null ) - { - setProjectM.invoke( proxy, new Object[]{getProject()} ); - } + final Class clazz = m_proxy.getClass(); + final Method method = clazz.getMethod( "execute", new Class[ 0 ] ); + method.invoke( m_proxy, null ); } - catch( NoSuchMethodException e ) + catch( final NoSuchMethodException nsme ) { - // ignore this if the class being used as a task does not have - // a set project method. + final String message = "No public execute() in " + m_proxy.getClass(); + getLogger().error( message ); + throw new TaskException( message ); } - catch( Exception ex ) + catch( final Exception e ) { - final String message = "Error setting project in " + proxy.getClass(); - getLogger().error( message, ex ); - throw new TaskException( "Error", ex ); - } - - Method executeM = null; - try - { - Class c = proxy.getClass(); - executeM = c.getMethod( "execute", new Class[ 0 ] ); - if( executeM == null ) + Throwable target = e; + if( e instanceof InvocationTargetException ) { - getLogger().error( "No public execute() in " + proxy.getClass() ); - throw new TaskException( "No public execute() in " + proxy.getClass() ); + target = ((InvocationTargetException)e).getTargetException(); } - executeM.invoke( proxy, null ); - return; - } - catch( Exception ex ) - { - getLogger().error( "Error in " + proxy.getClass() ); - throw new TaskException( "Error", ex ); - } + final String message = "Error invoking " + m_proxy.getClass(); + getLogger().error( message, target ); + throw new TaskException( message, target ); + } } }