From 5bdfaab5a1062aebf2a0db2559f4870359d0aac0 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sun, 30 Dec 2001 03:30:07 +0000 Subject: [PATCH] Cleaned up class and removed some uneeded (and never working ?) cruft git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270447 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/TaskAdapter.java | 73 ++++++------------- .../org/apache/tools/ant/TaskAdapter.java | 73 ++++++------------- 2 files changed, 42 insertions(+), 104 deletions(-) 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 ); + } } }