git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270447 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -8,6 +8,7 @@ | |||||
| package org.apache.tools.ant; | package org.apache.tools.ant; | ||||
| import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
| import java.lang.reflect.InvocationTargetException; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| /** | /** | ||||
| @@ -16,74 +17,42 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * | * | ||||
| * @author costin@dnt.ro | * @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() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| Method setProjectM = null; | |||||
| try | 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 ); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -8,6 +8,7 @@ | |||||
| package org.apache.tools.ant; | package org.apache.tools.ant; | ||||
| import java.lang.reflect.Method; | import java.lang.reflect.Method; | ||||
| import java.lang.reflect.InvocationTargetException; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| /** | /** | ||||
| @@ -16,74 +17,42 @@ import org.apache.myrmidon.api.TaskException; | |||||
| * | * | ||||
| * @author costin@dnt.ro | * @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() | public void execute() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| Method setProjectM = null; | |||||
| try | 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 ); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||