Added in a number of new tasks to demonstrate interaction with tasklet runtime. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268316 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -30,9 +30,10 @@ import org.apache.ant.project.ProjectListener; | |||||
| import org.apache.ant.project.ProjectToListenerAdapter; | import org.apache.ant.project.ProjectToListenerAdapter; | ||||
| import org.apache.ant.tasklet.JavaVersion; | import org.apache.ant.tasklet.JavaVersion; | ||||
| import org.apache.ant.tasklet.TaskletContext; | import org.apache.ant.tasklet.TaskletContext; | ||||
| import org.apache.ant.tasklet.engine.TaskletEngine; | |||||
| import org.apache.ant.tasklet.engine.TskDeployer; | |||||
| import org.apache.avalon.Disposable; | import org.apache.avalon.Disposable; | ||||
| import org.apache.avalon.Initializable; | import org.apache.avalon.Initializable; | ||||
| import org.apache.avalon.camelot.Deployer; | |||||
| import org.apache.avalon.camelot.DeploymentException; | import org.apache.avalon.camelot.DeploymentException; | ||||
| import org.apache.avalon.util.ObjectUtil; | import org.apache.avalon.util.ObjectUtil; | ||||
| import org.apache.avalon.util.StringUtil; | import org.apache.avalon.util.StringUtil; | ||||
| @@ -241,7 +242,7 @@ public class Main | |||||
| * @param clOptions the list of command line options | * @param clOptions the list of command line options | ||||
| */ | */ | ||||
| protected void execute( final List clOptions ) | protected void execute( final List clOptions ) | ||||
| throws Throwable | |||||
| throws Exception | |||||
| { | { | ||||
| final int size = clOptions.size(); | final int size = clOptions.size(); | ||||
| final ArrayList targets = new ArrayList(); | final ArrayList targets = new ArrayList(); | ||||
| @@ -384,7 +385,7 @@ public class Main | |||||
| final ExtensionFileFilter filter = new ExtensionFileFilter( ".tsk" ); | final ExtensionFileFilter filter = new ExtensionFileFilter( ".tsk" ); | ||||
| final File[] files = taskLibDirectory.listFiles( filter ); | final File[] files = taskLibDirectory.listFiles( filter ); | ||||
| final Deployer deployer = engine.getDeployer(); | |||||
| final TskDeployer deployer = engine.getTaskletEngine().getTskDeployer(); | |||||
| for( int i = 0; i < files.length; i++ ) | for( int i = 0; i < files.length; i++ ) | ||||
| { | { | ||||
| @@ -25,5 +25,5 @@ public interface Converter | |||||
| * @exception Exception if an error occurs | * @exception Exception if an error occurs | ||||
| */ | */ | ||||
| Object convert( Class destination, Object original ) | Object convert( Class destination, Object original ) | ||||
| throws Exception; | |||||
| throws ConverterException, Exception; | |||||
| } | } | ||||
| @@ -0,0 +1,20 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.convert; | |||||
| import org.apache.avalon.Component; | |||||
| import org.apache.log.Logger; | |||||
| public interface ConverterEngine | |||||
| extends Component, Converter | |||||
| { | |||||
| void setLogger( Logger logger ); | |||||
| ConverterRegistry getConverterRegistry(); | |||||
| ConverterFactory getConverterFactory(); | |||||
| } | |||||
| @@ -0,0 +1,41 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.convert; | |||||
| import org.apache.ant.AntException; | |||||
| /** | |||||
| * ConverterException thrown when a problem occurs during convertion etc. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class ConverterException | |||||
| extends AntException | |||||
| { | |||||
| /** | |||||
| * Basic constructor with a message | |||||
| * | |||||
| * @param message the message | |||||
| */ | |||||
| public ConverterException( final String message ) | |||||
| { | |||||
| this( message, null ); | |||||
| } | |||||
| /** | |||||
| * Constructor that builds cascade so that other exception information can be retained. | |||||
| * | |||||
| * @param message the message | |||||
| * @param throwable the throwable | |||||
| */ | |||||
| public ConverterException( final String message, final Throwable throwable ) | |||||
| { | |||||
| super( message, throwable ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,72 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.convert; | |||||
| import org.apache.ant.AntException; | |||||
| import org.apache.avalon.Component; | |||||
| import org.apache.avalon.Initializable; | |||||
| import org.apache.log.Logger; | |||||
| public class DefaultConverterEngine | |||||
| implements ConverterEngine, Initializable | |||||
| { | |||||
| protected ConverterFactory m_converterFactory; | |||||
| protected ConverterRegistry m_converterRegistry; | |||||
| protected Logger m_logger; | |||||
| public void setLogger( final Logger logger ) | |||||
| { | |||||
| m_logger = logger; | |||||
| } | |||||
| public ConverterRegistry getConverterRegistry() | |||||
| { | |||||
| return m_converterRegistry; | |||||
| } | |||||
| public ConverterFactory getConverterFactory() | |||||
| { | |||||
| return m_converterFactory; | |||||
| } | |||||
| public void init() | |||||
| throws Exception | |||||
| { | |||||
| m_converterRegistry = createConverterRegistry(); | |||||
| m_converterFactory = createConverterFactory(); | |||||
| } | |||||
| protected ConverterRegistry createConverterRegistry() | |||||
| { | |||||
| return new DefaultConverterRegistry(); | |||||
| } | |||||
| protected ConverterFactory createConverterFactory() | |||||
| { | |||||
| return new DefaultConverterFactory(); | |||||
| } | |||||
| public Object convert( Class destination, final Object original ) | |||||
| throws Exception | |||||
| { | |||||
| final ConverterInfo info = | |||||
| m_converterRegistry.getConverterInfo( original.getClass().getName(), | |||||
| destination.getName() ); | |||||
| if( null == info ) | |||||
| { | |||||
| throw new ConverterException( "Unable to find converter for " + | |||||
| original.getClass() + " to " + destination + | |||||
| " conversion" ); | |||||
| } | |||||
| final ConverterEntry entry = m_converterFactory.create( info ); | |||||
| final Converter converter = entry.getConverter(); | |||||
| return converter.convert( destination, original ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,31 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.convert.core; | |||||
| import org.apache.ant.convert.AbstractConverter; | |||||
| /** | |||||
| * String to class converter | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class StringToClassConverter | |||||
| extends AbstractConverter | |||||
| { | |||||
| public StringToClassConverter() | |||||
| { | |||||
| super( String.class, Class.class ); | |||||
| } | |||||
| public Object convert( final Object original ) | |||||
| throws Exception | |||||
| { | |||||
| return Class.forName( (String)original ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,32 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.convert.core; | |||||
| import java.net.URL; | |||||
| import org.apache.ant.convert.AbstractConverter; | |||||
| /** | |||||
| * String to url converter | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class StringToURLConverter | |||||
| extends AbstractConverter | |||||
| { | |||||
| public StringToURLConverter() | |||||
| { | |||||
| super( String.class, URL.class ); | |||||
| } | |||||
| public Object convert( final Object original ) | |||||
| throws Exception | |||||
| { | |||||
| return new URL( (String)original ); | |||||
| } | |||||
| } | |||||
| @@ -4,3 +4,5 @@ org.apache.ant.convert.core.StringToShortConverter=java.lang.String, java.lang.S | |||||
| org.apache.ant.convert.core.StringToByteConverter=java.lang.String, java.lang.Byte | org.apache.ant.convert.core.StringToByteConverter=java.lang.String, java.lang.Byte | ||||
| org.apache.ant.convert.core.StringToDoubleConverter=java.lang.String, java.lang.Double | org.apache.ant.convert.core.StringToDoubleConverter=java.lang.String, java.lang.Double | ||||
| org.apache.ant.convert.core.StringToFloatConverter=java.lang.String, java.lang.Float | org.apache.ant.convert.core.StringToFloatConverter=java.lang.String, java.lang.Float | ||||
| org.apache.ant.convert.core.StringToClassConverter=java.lang.String, java.lang.Class | |||||
| org.apache.ant.convert.core.StringToURLConverter=java.lang.String, java.net.URL | |||||
| @@ -11,31 +11,19 @@ import java.util.ArrayList; | |||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import org.apache.ant.AntException; | import org.apache.ant.AntException; | ||||
| import org.apache.ant.configuration.Configuration; | import org.apache.ant.configuration.Configuration; | ||||
| import org.apache.ant.convert.ConverterRegistry; | |||||
| import org.apache.ant.convert.DefaultConverterRegistry; | |||||
| import org.apache.ant.tasklet.DefaultTaskletContext; | import org.apache.ant.tasklet.DefaultTaskletContext; | ||||
| import org.apache.ant.tasklet.TaskletContext; | import org.apache.ant.tasklet.TaskletContext; | ||||
| import org.apache.ant.tasklet.engine.DefaultTaskletEngine; | import org.apache.ant.tasklet.engine.DefaultTaskletEngine; | ||||
| import org.apache.ant.tasklet.engine.DefaultTaskletInfo; | |||||
| import org.apache.ant.tasklet.engine.DefaultTaskletRegistry; | |||||
| import org.apache.ant.tasklet.engine.TaskletEngine; | import org.apache.ant.tasklet.engine.TaskletEngine; | ||||
| import org.apache.ant.tasklet.engine.TaskletRegistry; | |||||
| import org.apache.ant.tasklet.engine.TskDeployer; | |||||
| import org.apache.avalon.Composer; | import org.apache.avalon.Composer; | ||||
| import org.apache.avalon.DefaultComponentManager; | import org.apache.avalon.DefaultComponentManager; | ||||
| import org.apache.avalon.Disposable; | import org.apache.avalon.Disposable; | ||||
| import org.apache.avalon.Initializable; | import org.apache.avalon.Initializable; | ||||
| import org.apache.avalon.camelot.Deployer; | |||||
| import org.apache.avalon.camelot.DeploymentException; | |||||
| import org.apache.avalon.camelot.RegistryException; | |||||
| import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
| public class DefaultProjectEngine | public class DefaultProjectEngine | ||||
| implements ProjectEngine, Initializable, Disposable | implements ProjectEngine, Initializable, Disposable | ||||
| { | { | ||||
| protected Deployer m_deployer; | |||||
| protected TaskletRegistry m_taskletRegistry; | |||||
| protected ConverterRegistry m_converterRegistry; | |||||
| protected TaskletEngine m_taskletEngine; | protected TaskletEngine m_taskletEngine; | ||||
| protected Logger m_logger; | protected Logger m_logger; | ||||
| protected ProjectListenerSupport m_listenerSupport; | protected ProjectListenerSupport m_listenerSupport; | ||||
| @@ -61,15 +49,13 @@ public class DefaultProjectEngine | |||||
| { | { | ||||
| m_listenerSupport = new ProjectListenerSupport(); | m_listenerSupport = new ProjectListenerSupport(); | ||||
| m_taskletRegistry = createTaskletRegistry(); | |||||
| m_converterRegistry = createConverterRegistry(); | |||||
| m_deployer = createDeployer(); | |||||
| setupTaskletEngine(); | setupTaskletEngine(); | ||||
| m_componentManager = new DefaultComponentManager(); | m_componentManager = new DefaultComponentManager(); | ||||
| m_componentManager.put( "org.apache.ant.project.ProjectEngine", this ); | m_componentManager.put( "org.apache.ant.project.ProjectEngine", this ); | ||||
| m_componentManager.put( "org.apache.ant.tasklet.engine.TaskletEngine", m_taskletEngine ); | m_componentManager.put( "org.apache.ant.tasklet.engine.TaskletEngine", m_taskletEngine ); | ||||
| m_componentManager.put( "org.apache.ant.convert.ConverterEngine", | |||||
| m_taskletEngine.getConverterEngine() ); | |||||
| } | } | ||||
| public void dispose() | public void dispose() | ||||
| @@ -81,9 +67,9 @@ public class DefaultProjectEngine | |||||
| } | } | ||||
| } | } | ||||
| public Deployer getDeployer() | |||||
| public TaskletEngine getTaskletEngine() | |||||
| { | { | ||||
| return m_deployer; | |||||
| return m_taskletEngine; | |||||
| } | } | ||||
| protected void setupTaskletEngine() | protected void setupTaskletEngine() | ||||
| @@ -92,17 +78,6 @@ public class DefaultProjectEngine | |||||
| m_taskletEngine = createTaskletEngine(); | m_taskletEngine = createTaskletEngine(); | ||||
| m_taskletEngine.setLogger( m_logger ); | m_taskletEngine.setLogger( m_logger ); | ||||
| if( m_taskletEngine instanceof Composer ) | |||||
| { | |||||
| final DefaultComponentManager componentManager = new DefaultComponentManager(); | |||||
| componentManager.put( "org.apache.ant.tasklet.engine.TaskletRegistry", | |||||
| m_taskletRegistry ); | |||||
| componentManager.put( "org.apache.ant.convert.ConverterRegistry", | |||||
| m_converterRegistry ); | |||||
| ((Composer)m_taskletEngine).compose( componentManager ); | |||||
| } | |||||
| if( m_taskletEngine instanceof Initializable ) | if( m_taskletEngine instanceof Initializable ) | ||||
| { | { | ||||
| ((Initializable)m_taskletEngine).init(); | ((Initializable)m_taskletEngine).init(); | ||||
| @@ -114,24 +89,6 @@ public class DefaultProjectEngine | |||||
| return new DefaultTaskletEngine(); | return new DefaultTaskletEngine(); | ||||
| } | } | ||||
| protected TaskletRegistry createTaskletRegistry() | |||||
| { | |||||
| return new DefaultTaskletRegistry(); | |||||
| } | |||||
| protected ConverterRegistry createConverterRegistry() | |||||
| { | |||||
| return new DefaultConverterRegistry(); | |||||
| } | |||||
| protected Deployer createDeployer() | |||||
| { | |||||
| final TskDeployer deployer = | |||||
| new TskDeployer( m_taskletRegistry, m_converterRegistry ); | |||||
| deployer.setLogger( m_logger ); | |||||
| return deployer; | |||||
| } | |||||
| public void execute( final Project project, final String target ) | public void execute( final Project project, final String target ) | ||||
| throws AntException | throws AntException | ||||
| { | { | ||||
| @@ -9,20 +9,23 @@ package org.apache.ant.project; | |||||
| import org.apache.ant.AntException; | import org.apache.ant.AntException; | ||||
| import org.apache.ant.tasklet.TaskletContext; | import org.apache.ant.tasklet.TaskletContext; | ||||
| import org.apache.ant.tasklet.engine.TaskletEngine; | |||||
| import org.apache.avalon.Component; | import org.apache.avalon.Component; | ||||
| import org.apache.avalon.camelot.Deployer; | |||||
| import org.apache.avalon.camelot.Registry; | |||||
| import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
| public interface ProjectEngine | public interface ProjectEngine | ||||
| extends Component | extends Component | ||||
| { | { | ||||
| Deployer getDeployer(); | |||||
| void setLogger( Logger logger ); | |||||
| TaskletEngine getTaskletEngine(); | |||||
| void addProjectListener( ProjectListener listener ); | void addProjectListener( ProjectListener listener ); | ||||
| void removeProjectListener( ProjectListener listener ); | void removeProjectListener( ProjectListener listener ); | ||||
| void setLogger( Logger logger ); | |||||
| void execute( Project project, String target ) | void execute( Project project, String target ) | ||||
| throws AntException; | throws AntException; | ||||
| void execute( Project project, String target, TaskletContext context ) | void execute( Project project, String target, TaskletContext context ) | ||||
| throws AntException; | throws AntException; | ||||
| } | } | ||||
| @@ -14,10 +14,7 @@ import java.util.Iterator; | |||||
| import org.apache.ant.configuration.Configurable; | import org.apache.ant.configuration.Configurable; | ||||
| import org.apache.ant.configuration.Configuration; | import org.apache.ant.configuration.Configuration; | ||||
| import org.apache.ant.convert.Converter; | import org.apache.ant.convert.Converter; | ||||
| import org.apache.ant.convert.ConverterEntry; | |||||
| import org.apache.ant.convert.ConverterFactory; | |||||
| import org.apache.ant.convert.ConverterInfo; | |||||
| import org.apache.ant.convert.ConverterRegistry; | |||||
| import org.apache.ant.convert.ConverterException; | |||||
| import org.apache.ant.tasklet.Tasklet; | import org.apache.ant.tasklet.Tasklet; | ||||
| import org.apache.avalon.ComponentManager; | import org.apache.avalon.ComponentManager; | ||||
| import org.apache.avalon.ComponentNotAccessibleException; | import org.apache.avalon.ComponentNotAccessibleException; | ||||
| @@ -25,7 +22,6 @@ import org.apache.avalon.ComponentNotFoundException; | |||||
| import org.apache.avalon.Composer; | import org.apache.avalon.Composer; | ||||
| import org.apache.avalon.ConfigurationException; | import org.apache.avalon.ConfigurationException; | ||||
| import org.apache.avalon.Context; | import org.apache.avalon.Context; | ||||
| import org.apache.avalon.camelot.FactoryException; | |||||
| import org.apache.avalon.util.PropertyException; | import org.apache.avalon.util.PropertyException; | ||||
| import org.apache.avalon.util.PropertyUtil; | import org.apache.avalon.util.PropertyUtil; | ||||
| @@ -47,16 +43,12 @@ public class DefaultTaskletConfigurer | |||||
| "content" | "content" | ||||
| }; | }; | ||||
| protected ConverterRegistry m_converterRegistry; | |||||
| protected ConverterFactory m_converterFactory; | |||||
| protected Converter m_converter; | |||||
| public void compose( final ComponentManager componentManager ) | public void compose( final ComponentManager componentManager ) | ||||
| throws ComponentNotFoundException, ComponentNotAccessibleException | throws ComponentNotFoundException, ComponentNotAccessibleException | ||||
| { | { | ||||
| m_converterRegistry = (ConverterRegistry)componentManager. | |||||
| lookup( "org.apache.ant.convert.ConverterRegistry" ); | |||||
| m_converterFactory = (ConverterFactory)componentManager. | |||||
| lookup( "org.apache.ant.convert.ConverterFactory" ); | |||||
| m_converter = (Converter)componentManager.lookup( "org.apache.ant.convert.Converter" ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -240,23 +232,13 @@ public class DefaultTaskletConfigurer | |||||
| if( !parameterType.isAssignableFrom( sourceClass ) ) | if( !parameterType.isAssignableFrom( sourceClass ) ) | ||||
| { | { | ||||
| final String destination = parameterType.getName(); | |||||
| try | try | ||||
| { | { | ||||
| final ConverterInfo info = m_converterRegistry. | |||||
| getConverterInfo( source, destination ); | |||||
| if( null == info ) return false; | |||||
| final ConverterEntry entry = m_converterFactory.create( info ); | |||||
| final Converter converter = entry.getConverter(); | |||||
| value = converter.convert( parameterType, value ); | |||||
| value = m_converter.convert( parameterType, object ); | |||||
| } | } | ||||
| catch( final FactoryException fe ) | |||||
| catch( final ConverterException ce ) | |||||
| { | { | ||||
| throw new ConfigurationException( "Badly configured ConverterFactory ", | |||||
| fe ); | |||||
| return false; | |||||
| } | } | ||||
| catch( final Exception e ) | catch( final Exception e ) | ||||
| { | { | ||||
| @@ -11,14 +11,13 @@ import java.util.HashMap; | |||||
| import org.apache.ant.AntException; | import org.apache.ant.AntException; | ||||
| import org.apache.ant.configuration.Configurable; | import org.apache.ant.configuration.Configurable; | ||||
| import org.apache.ant.configuration.Configuration; | import org.apache.ant.configuration.Configuration; | ||||
| import org.apache.ant.convert.ConverterEngine; | |||||
| import org.apache.ant.convert.ConverterFactory; | import org.apache.ant.convert.ConverterFactory; | ||||
| import org.apache.ant.convert.ConverterRegistry; | |||||
| import org.apache.ant.tasklet.Tasklet; | import org.apache.ant.tasklet.Tasklet; | ||||
| import org.apache.ant.tasklet.TaskletContext; | import org.apache.ant.tasklet.TaskletContext; | ||||
| import org.apache.avalon.ComponentManager; | |||||
| import org.apache.avalon.ComponentNotAccessibleException; | |||||
| import org.apache.avalon.ComponentNotFoundException; | |||||
| import org.apache.avalon.Component; | |||||
| import org.apache.avalon.Composer; | import org.apache.avalon.Composer; | ||||
| import org.apache.avalon.ComponentManager; | |||||
| import org.apache.avalon.Context; | import org.apache.avalon.Context; | ||||
| import org.apache.avalon.Contextualizable; | import org.apache.avalon.Contextualizable; | ||||
| import org.apache.avalon.DefaultComponentManager; | import org.apache.avalon.DefaultComponentManager; | ||||
| @@ -29,76 +28,102 @@ import org.apache.avalon.camelot.RegistryException; | |||||
| import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
| public class DefaultTaskletEngine | public class DefaultTaskletEngine | ||||
| implements TaskletEngine, Initializable, Composer | |||||
| implements TaskletEngine, Initializable | |||||
| { | { | ||||
| protected TskDeployer m_tskDeployer; | |||||
| protected TaskletFactory m_taskletFactory; | protected TaskletFactory m_taskletFactory; | ||||
| protected ConverterFactory m_converterFactory; | |||||
| protected TaskletRegistry m_taskletRegistry; | protected TaskletRegistry m_taskletRegistry; | ||||
| protected ConverterRegistry m_converterRegistry; | |||||
| protected TaskletConfigurer m_configurer; | protected TaskletConfigurer m_configurer; | ||||
| protected Logger m_logger; | protected Logger m_logger; | ||||
| protected ConverterEngine m_converterEngine; | |||||
| public void setLogger( final Logger logger ) | public void setLogger( final Logger logger ) | ||||
| { | { | ||||
| m_logger = logger; | m_logger = logger; | ||||
| } | } | ||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentNotFoundException, ComponentNotAccessibleException | |||||
| public TskDeployer getTskDeployer() | |||||
| { | { | ||||
| m_taskletRegistry = (TaskletRegistry)componentManager. | |||||
| lookup( "org.apache.ant.tasklet.engine.TaskletRegistry" ); | |||||
| m_converterRegistry = (ConverterRegistry)componentManager. | |||||
| lookup( "org.apache.ant.convert.ConverterRegistry" ); | |||||
| return m_tskDeployer; | |||||
| } | } | ||||
| public TaskletRegistry getTaskletRegistry() | |||||
| public ConverterEngine getConverterEngine() | |||||
| { | { | ||||
| return m_taskletRegistry; | |||||
| return m_converterEngine; | |||||
| } | } | ||||
| public ConverterRegistry getConverterRegistry() | |||||
| public TaskletRegistry getTaskletRegistry() | |||||
| { | { | ||||
| return m_converterRegistry; | |||||
| return m_taskletRegistry; | |||||
| } | } | ||||
| public void init() | public void init() | ||||
| throws Exception | throws Exception | ||||
| { | { | ||||
| m_taskletRegistry = createTaskletRegistry(); | |||||
| m_taskletFactory = createTaskletFactory(); | m_taskletFactory = createTaskletFactory(); | ||||
| m_converterFactory = createConverterFactory(); | |||||
| m_converterEngine = createConverterEngine(); | |||||
| m_converterEngine.setLogger( m_logger ); | |||||
| setupSubComponent( m_converterEngine ); | |||||
| m_configurer = createTaskletConfigurer(); | m_configurer = createTaskletConfigurer(); | ||||
| setupSubComponent( m_configurer ); | |||||
| if( m_configurer instanceof Composer ) | |||||
| m_tskDeployer = createTskDeployer(); | |||||
| m_tskDeployer.setLogger( m_logger ); | |||||
| setupSubComponent( m_tskDeployer ); | |||||
| } | |||||
| protected void setupSubComponent( final Component component ) | |||||
| throws Exception | |||||
| { | |||||
| if( component instanceof Composer ) | |||||
| { | { | ||||
| final DefaultComponentManager componentManager = new DefaultComponentManager(); | final DefaultComponentManager componentManager = new DefaultComponentManager(); | ||||
| componentManager.put( "org.apache.ant.convert.ConverterFactory", | |||||
| m_converterFactory ); | |||||
| componentManager.put( "org.apache.ant.convert.ConverterRegistry", | |||||
| m_converterRegistry ); | |||||
| componentManager.put( "org.apache.ant.convert.Converter", | |||||
| getConverterEngine() ); | |||||
| componentManager.put( "org.apache.ant.convert.ConverterEngine", | |||||
| getConverterEngine() ); | |||||
| componentManager.put( "org.apache.ant.tasklet.engine.TaskletEngine", | |||||
| this ); | |||||
| ((Composer)m_configurer).compose( componentManager ); | |||||
| ((Composer)component).compose( componentManager ); | |||||
| } | } | ||||
| if( m_configurer instanceof Initializable ) | |||||
| if( component instanceof Initializable ) | |||||
| { | { | ||||
| ((Initializable)m_configurer).init(); | |||||
| ((Initializable)component).init(); | |||||
| } | } | ||||
| } | } | ||||
| protected TskDeployer createTskDeployer() | |||||
| { | |||||
| return new DefaultTskDeployer(); | |||||
| } | |||||
| protected TaskletConfigurer createTaskletConfigurer() | protected TaskletConfigurer createTaskletConfigurer() | ||||
| { | { | ||||
| return new DefaultTaskletConfigurer(); | return new DefaultTaskletConfigurer(); | ||||
| } | } | ||||
| protected TaskletRegistry createTaskletRegistry() | |||||
| { | |||||
| return new DefaultTaskletRegistry(); | |||||
| } | |||||
| protected TaskletFactory createTaskletFactory() | protected TaskletFactory createTaskletFactory() | ||||
| { | { | ||||
| return new DefaultTaskletFactory(); | return new DefaultTaskletFactory(); | ||||
| } | } | ||||
| protected ConverterFactory createConverterFactory() | |||||
| protected ConverterEngine createConverterEngine() | |||||
| { | { | ||||
| return (ConverterFactory)m_taskletFactory; | |||||
| //this is done so that the loaders are shared | |||||
| //which results in much less overhead | |||||
| final TaskletConverterEngine engine = new TaskletConverterEngine(); | |||||
| engine.setConverterFactory( (ConverterFactory)m_taskletFactory ); | |||||
| return engine; | |||||
| } | } | ||||
| public void execute( final Configuration task, | public void execute( final Configuration task, | ||||
| @@ -0,0 +1,309 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.tasklet.engine; | |||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import java.net.MalformedURLException; | |||||
| import java.net.URL; | |||||
| import java.util.Enumeration; | |||||
| import java.util.Properties; | |||||
| import java.util.zip.ZipEntry; | |||||
| import java.util.zip.ZipException; | |||||
| import java.util.zip.ZipFile; | |||||
| import org.apache.ant.convert.ConverterEngine; | |||||
| import org.apache.ant.convert.ConverterRegistry; | |||||
| import org.apache.ant.convert.DefaultConverterInfo; | |||||
| import org.apache.ant.tasklet.engine.DefaultTaskletInfo; | |||||
| import org.apache.avalon.Component; | |||||
| import org.apache.avalon.ComponentManager; | |||||
| import org.apache.avalon.ComponentNotAccessibleException; | |||||
| import org.apache.avalon.ComponentNotFoundException; | |||||
| import org.apache.avalon.Composer; | |||||
| import org.apache.avalon.camelot.AbstractDeployer; | |||||
| import org.apache.avalon.camelot.DeploymentException; | |||||
| import org.apache.avalon.camelot.RegistryException; | |||||
| import org.apache.log.Logger; | |||||
| /** | |||||
| * This class deploys a .tsk file into a registry. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class DefaultTskDeployer | |||||
| extends AbstractDeployer | |||||
| implements Composer, TskDeployer | |||||
| { | |||||
| protected final static String TASKDEF_FILE = "TASK-LIB/taskdefs.properties"; | |||||
| protected final static String CONVERTER_FILE = "TASK-LIB/converters.properties"; | |||||
| protected TaskletRegistry m_taskletRegistry; | |||||
| protected ConverterRegistry m_converterRegistry; | |||||
| /** | |||||
| * Default constructor. | |||||
| */ | |||||
| public DefaultTskDeployer() | |||||
| { | |||||
| m_autoUndeploy = true; | |||||
| m_type = "Tasklet"; | |||||
| } | |||||
| /** | |||||
| * Retrieve relevent services needed to deploy. | |||||
| * | |||||
| * @param componentManager the ComponentManager | |||||
| * @exception ComponentNotFoundException if an error occurs | |||||
| * @exception ComponentNotAccessibleException if an error occurs | |||||
| */ | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentNotFoundException, ComponentNotAccessibleException | |||||
| { | |||||
| final ConverterEngine converterEngine = (ConverterEngine)componentManager. | |||||
| lookup( "org.apache.ant.convert.ConverterEngine" ); | |||||
| m_converterRegistry = converterEngine.getConverterRegistry(); | |||||
| final TaskletEngine taskletEngine = (TaskletEngine)componentManager. | |||||
| lookup( "org.apache.ant.tasklet.engine.TaskletEngine" ); | |||||
| m_taskletRegistry = taskletEngine.getTaskletRegistry(); | |||||
| } | |||||
| public void setLogger( final Logger logger ) | |||||
| { | |||||
| m_logger = logger; | |||||
| } | |||||
| protected boolean isValidLocation( final String location ) | |||||
| { | |||||
| //TODO: Make sure it is valid JavaIdentifier | |||||
| //that optionally has '-' embedded in it | |||||
| return true; | |||||
| } | |||||
| /** | |||||
| * Deploy Tasklets from a .tsk file. | |||||
| * Eventually this should be cached for performance reasons. | |||||
| * | |||||
| * @param location the location | |||||
| * @param file the file | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| protected void deployFromFile( final String location, final File file ) | |||||
| throws DeploymentException | |||||
| { | |||||
| m_logger.info( "Deploying .tsk file (" + file + ") as " + location ); | |||||
| final ZipFile zipFile = getZipFileFor( file ); | |||||
| try | |||||
| { | |||||
| final Properties taskdefs = loadProperties( zipFile, TASKDEF_FILE ); | |||||
| final Properties converters = loadProperties( zipFile, CONVERTER_FILE ); | |||||
| try { zipFile.close(); } | |||||
| catch( final IOException ioe ) {} | |||||
| URL url = null; | |||||
| try { url = file.toURL(); } | |||||
| catch( final MalformedURLException mue ) {} | |||||
| handleTasklets( taskdefs, url ); | |||||
| handleConverters( converters, url ); | |||||
| } | |||||
| catch( final DeploymentException de ) | |||||
| { | |||||
| try { zipFile.close(); } | |||||
| catch( final IOException ioe ) {} | |||||
| throw de; | |||||
| } | |||||
| } | |||||
| public void deployConverter( String name, String location, URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| checkDeployment( location, url ); | |||||
| final ZipFile zipFile = getZipFileFor( url ); | |||||
| final Properties converters = loadProperties( zipFile, CONVERTER_FILE ); | |||||
| final String value = converters.getProperty( name ); | |||||
| if( null == value ) | |||||
| { | |||||
| throw new DeploymentException( "Unable to locate converter named " + name ); | |||||
| } | |||||
| handleConverter( name, value, url ); | |||||
| } | |||||
| public void deployTasklet( final String name, final String location, final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| checkDeployment( location, url ); | |||||
| final ZipFile zipFile = getZipFileFor( url ); | |||||
| final Properties tasklets = loadProperties( zipFile, TASKDEF_FILE ); | |||||
| final String value = tasklets.getProperty( name ); | |||||
| if( null == value ) | |||||
| { | |||||
| throw new DeploymentException( "Unable to locate tasklet named " + name ); | |||||
| } | |||||
| handleTasklet( name, value, url ); | |||||
| } | |||||
| protected ZipFile getZipFileFor( final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final File file = getFileFor( url ); | |||||
| return getZipFileFor( file ); | |||||
| } | |||||
| protected ZipFile getZipFileFor( final File file ) | |||||
| throws DeploymentException | |||||
| { | |||||
| try { return new ZipFile( file ); } | |||||
| catch( final IOException ioe ) | |||||
| { | |||||
| throw new DeploymentException( "Error opening " + file + | |||||
| " due to " + ioe.getMessage(), | |||||
| ioe ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Create and register Infos for all converters stored in deployment. | |||||
| * | |||||
| * @param properties the properties | |||||
| * @param url the url of deployment | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| protected void handleConverters( final Properties properties, final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final Enumeration enum = properties.propertyNames(); | |||||
| while( enum.hasMoreElements() ) | |||||
| { | |||||
| final String key = (String)enum.nextElement(); | |||||
| final String value = (String)properties.get( key ); | |||||
| handleConverter( key, value, url ); | |||||
| } | |||||
| } | |||||
| protected void handleConverter( final String name, final String param, final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final int index = param.indexOf( ',' ); | |||||
| if( -1 == index ) | |||||
| { | |||||
| throw new DeploymentException( "Malformed converter definition (" + name + ")" ); | |||||
| } | |||||
| final String source = param.substring( 0, index ).trim(); | |||||
| final String destination = param.substring( index + 1 ).trim(); | |||||
| final DefaultConverterInfo info = | |||||
| new DefaultConverterInfo( source, destination, name, url ); | |||||
| try { m_converterRegistry.register( name, info ); } | |||||
| catch( final RegistryException re ) | |||||
| { | |||||
| throw new DeploymentException( "Error registering converter " + | |||||
| name + " due to " + re, | |||||
| re ); | |||||
| } | |||||
| m_logger.debug( "Registered converter " + name + " that converts from " + | |||||
| source + " to " + destination ); | |||||
| } | |||||
| /** | |||||
| * Create and register Infos for all tasklets stored in deployment. | |||||
| * | |||||
| * @param properties the properties | |||||
| * @param url the url of deployment | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| protected void handleTasklets( final Properties properties, final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final Enumeration enum = properties.propertyNames(); | |||||
| while( enum.hasMoreElements() ) | |||||
| { | |||||
| final String key = (String)enum.nextElement(); | |||||
| final String value = (String)properties.get( key ); | |||||
| handleTasklet( key, value, url ); | |||||
| } | |||||
| } | |||||
| protected void handleTasklet( final String name, final String classname, final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final DefaultTaskletInfo info = new DefaultTaskletInfo( classname, url ); | |||||
| try { m_taskletRegistry.register( name, info ); } | |||||
| catch( final RegistryException re ) | |||||
| { | |||||
| throw new DeploymentException( "Error registering " + name + " due to " + re, | |||||
| re ); | |||||
| } | |||||
| m_logger.debug( "Registered tasklet " + name + " as " + classname ); | |||||
| } | |||||
| /** | |||||
| * Utility method to load properties from zip. | |||||
| * | |||||
| * @param zipFile the zip file | |||||
| * @param filename the property filename | |||||
| * @return the Properties | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| protected Properties loadProperties( final ZipFile zipFile, final String filename ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final ZipEntry entry = zipFile.getEntry( filename ); | |||||
| if( null == entry ) | |||||
| { | |||||
| throw new DeploymentException( "Unable to locate " + filename + | |||||
| " in " + zipFile.getName() ); | |||||
| } | |||||
| Properties properties = new Properties(); | |||||
| try | |||||
| { | |||||
| properties.load( zipFile.getInputStream( entry ) ); | |||||
| } | |||||
| catch( final IOException ioe ) | |||||
| { | |||||
| throw new DeploymentException( "Error reading " + filename + | |||||
| " from " + zipFile.getName(), | |||||
| ioe ); | |||||
| } | |||||
| return properties; | |||||
| } | |||||
| protected boolean canUndeploy( final Component component ) | |||||
| throws DeploymentException | |||||
| { | |||||
| return true; | |||||
| } | |||||
| protected void shutdownDeployment( final Component component ) | |||||
| throws DeploymentException | |||||
| { | |||||
| } | |||||
| } | |||||
| @@ -9,6 +9,7 @@ package org.apache.ant.tasklet.engine; | |||||
| import org.apache.ant.configuration.Configuration; | import org.apache.ant.configuration.Configuration; | ||||
| import org.apache.ant.tasklet.Tasklet; | import org.apache.ant.tasklet.Tasklet; | ||||
| import org.apache.avalon.Component; | |||||
| import org.apache.avalon.ConfigurationException; | import org.apache.avalon.ConfigurationException; | ||||
| import org.apache.avalon.Context; | import org.apache.avalon.Context; | ||||
| @@ -18,6 +19,7 @@ import org.apache.avalon.Context; | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public interface TaskletConfigurer | public interface TaskletConfigurer | ||||
| extends Component | |||||
| { | { | ||||
| /** | /** | ||||
| * Configure a task based on a configuration in a particular context. | * Configure a task based on a configuration in a particular context. | ||||
| @@ -0,0 +1,29 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.tasklet.engine; | |||||
| import org.apache.ant.convert.ConverterFactory; | |||||
| import org.apache.ant.convert.DefaultConverterEngine; | |||||
| public class TaskletConverterEngine | |||||
| extends DefaultConverterEngine | |||||
| { | |||||
| /** | |||||
| * Set the ConverterFactory. | |||||
| * Package access intended. | |||||
| */ | |||||
| void setConverterFactory( final ConverterFactory converterFactory ) | |||||
| { | |||||
| m_converterFactory = converterFactory; | |||||
| } | |||||
| protected ConverterFactory createConverterFactory() | |||||
| { | |||||
| return m_converterFactory; | |||||
| } | |||||
| } | |||||
| @@ -9,12 +9,10 @@ package org.apache.ant.tasklet.engine; | |||||
| import org.apache.ant.AntException; | import org.apache.ant.AntException; | ||||
| import org.apache.ant.configuration.Configuration; | import org.apache.ant.configuration.Configuration; | ||||
| import org.apache.ant.convert.ConverterRegistry; | |||||
| import org.apache.ant.convert.ConverterEngine; | |||||
| import org.apache.ant.tasklet.TaskletContext; | import org.apache.ant.tasklet.TaskletContext; | ||||
| import org.apache.avalon.Component; | import org.apache.avalon.Component; | ||||
| import org.apache.avalon.ComponentManager; | import org.apache.avalon.ComponentManager; | ||||
| import org.apache.avalon.Composer; | |||||
| import org.apache.avalon.Contextualizable; | |||||
| import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
| /** | /** | ||||
| @@ -26,6 +24,13 @@ public interface TaskletEngine | |||||
| extends Component | extends Component | ||||
| { | { | ||||
| void setLogger( Logger logger ); | void setLogger( Logger logger ); | ||||
| /** | |||||
| * Retrieve deployer for engine. | |||||
| * | |||||
| * @return the deployer | |||||
| */ | |||||
| TskDeployer getTskDeployer(); | |||||
| /** | /** | ||||
| * Retrieve tasklet registry associated with engine. | * Retrieve tasklet registry associated with engine. | ||||
| @@ -35,11 +40,11 @@ public interface TaskletEngine | |||||
| TaskletRegistry getTaskletRegistry(); | TaskletRegistry getTaskletRegistry(); | ||||
| /** | /** | ||||
| * Retrieve converter registry associated with engine. | |||||
| * Retrieve converter engine. | |||||
| * | * | ||||
| * @return the ConverterRegistry | |||||
| * @return the ConverterEngine | |||||
| */ | */ | ||||
| ConverterRegistry getConverterRegistry(); | |||||
| ConverterEngine getConverterEngine(); | |||||
| /** | /** | ||||
| * execute a task. | * execute a task. | ||||
| @@ -7,22 +7,9 @@ | |||||
| */ | */ | ||||
| package org.apache.ant.tasklet.engine; | package org.apache.ant.tasklet.engine; | ||||
| import java.io.File; | |||||
| import java.io.IOException; | |||||
| import java.net.MalformedURLException; | |||||
| import java.net.URL; | import java.net.URL; | ||||
| import java.util.Enumeration; | |||||
| import java.util.Properties; | |||||
| import java.util.zip.ZipEntry; | |||||
| import java.util.zip.ZipException; | |||||
| import java.util.zip.ZipFile; | |||||
| import org.apache.ant.tasklet.engine.DefaultTaskletInfo; | |||||
| import org.apache.ant.convert.ConverterRegistry; | |||||
| import org.apache.ant.convert.DefaultConverterInfo; | |||||
| import org.apache.avalon.Component; | |||||
| import org.apache.avalon.camelot.AbstractDeployer; | |||||
| import org.apache.avalon.camelot.Deployer; | |||||
| import org.apache.avalon.camelot.DeploymentException; | import org.apache.avalon.camelot.DeploymentException; | ||||
| import org.apache.avalon.camelot.RegistryException; | |||||
| import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
| /** | /** | ||||
| @@ -30,176 +17,14 @@ import org.apache.log.Logger; | |||||
| * | * | ||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public class TskDeployer | |||||
| extends AbstractDeployer | |||||
| public interface TskDeployer | |||||
| extends Deployer | |||||
| { | { | ||||
| protected final static String TASKDEF_FILE = "TASK-LIB/taskdefs.properties"; | |||||
| protected final static String CONVERTER_FILE = "TASK-LIB/converters.properties"; | |||||
| void setLogger( Logger logger ); | |||||
| protected TaskletRegistry m_taskletRegistry; | |||||
| protected ConverterRegistry m_converterRegistry; | |||||
| public TskDeployer( final TaskletRegistry taskletRegistry, | |||||
| final ConverterRegistry converterRegistry ) | |||||
| { | |||||
| m_taskletRegistry = taskletRegistry; | |||||
| m_converterRegistry = converterRegistry; | |||||
| m_autoUndeploy = true; | |||||
| m_type = "Tasklet"; | |||||
| } | |||||
| public void setLogger( final Logger logger ) | |||||
| { | |||||
| m_logger = logger; | |||||
| } | |||||
| protected boolean isValidLocation( final String location ) | |||||
| { | |||||
| //TODO: Make sure it is valid JavaIdentifier | |||||
| //that optionally has '-' embedded in it | |||||
| return true; | |||||
| } | |||||
| /** | |||||
| * Deploy Tasklets from a .tsk file. | |||||
| * Eventually this should be cached for performance reasons. | |||||
| * | |||||
| * @param location the location | |||||
| * @param file the file | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| protected void deployFromFile( final String location, final File file ) | |||||
| throws DeploymentException | |||||
| { | |||||
| m_logger.info( "Deploying .tsk file (" + file + ") as " + location ); | |||||
| ZipFile zipFile = null; | |||||
| try { zipFile = new ZipFile( file ); } | |||||
| catch( final IOException ioe ) | |||||
| { | |||||
| throw new DeploymentException( "Error opening " + file + | |||||
| " due to " + ioe.getMessage(), | |||||
| ioe ); | |||||
| } | |||||
| try | |||||
| { | |||||
| final Properties taskdefs = loadProperties( zipFile, TASKDEF_FILE ); | |||||
| final Properties converters = loadProperties( zipFile, CONVERTER_FILE ); | |||||
| try { zipFile.close(); } | |||||
| catch( final IOException ioe ) {} | |||||
| URL url = null; | |||||
| try { url = file.toURL(); } | |||||
| catch( final MalformedURLException mue ) {} | |||||
| handleTaskdefs( taskdefs, url ); | |||||
| handleConverters( converters, url ); | |||||
| } | |||||
| catch( final DeploymentException de ) | |||||
| { | |||||
| try { zipFile.close(); } | |||||
| catch( final IOException ioe ) {} | |||||
| throw de; | |||||
| } | |||||
| } | |||||
| protected void handleConverters( final Properties properties, final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final Enumeration enum = properties.propertyNames(); | |||||
| while( enum.hasMoreElements() ) | |||||
| { | |||||
| final String key = (String)enum.nextElement(); | |||||
| final String value = (String)properties.get( key ); | |||||
| final int index = value.indexOf( ',' ); | |||||
| if( -1 == index ) | |||||
| { | |||||
| throw new DeploymentException( "Malformed converter definition (" + | |||||
| key + ")" ); | |||||
| } | |||||
| final String source = value.substring( 0, index ).trim(); | |||||
| final String destination = value.substring( index + 1 ).trim(); | |||||
| final DefaultConverterInfo info = | |||||
| new DefaultConverterInfo( source, destination, key, url ); | |||||
| try { m_converterRegistry.register( key, info ); } | |||||
| catch( final RegistryException re ) | |||||
| { | |||||
| throw new DeploymentException( "Error registering converter " + | |||||
| key + " due to " + re, | |||||
| re ); | |||||
| } | |||||
| m_logger.debug( "Registered converter " + key + " that converts from " + | |||||
| source + " to " + destination ); | |||||
| } | |||||
| } | |||||
| protected void handleTaskdefs( final Properties properties, final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final Enumeration enum = properties.propertyNames(); | |||||
| while( enum.hasMoreElements() ) | |||||
| { | |||||
| final String key = (String)enum.nextElement(); | |||||
| final String value = (String)properties.get( key ); | |||||
| final DefaultTaskletInfo info = new DefaultTaskletInfo( value, url ); | |||||
| try { m_taskletRegistry.register( key, info ); } | |||||
| catch( final RegistryException re ) | |||||
| { | |||||
| throw new DeploymentException( "Error registering " + key + " due to " + re, | |||||
| re ); | |||||
| } | |||||
| m_logger.debug( "Registered tasklet " + key + " as " + value ); | |||||
| } | |||||
| } | |||||
| protected Properties loadProperties( final ZipFile zipFile, final String filename ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final ZipEntry entry = zipFile.getEntry( filename ); | |||||
| if( null == entry ) | |||||
| { | |||||
| throw new DeploymentException( "Unable to locate " + filename + | |||||
| " in " + zipFile.getName() ); | |||||
| } | |||||
| Properties properties = new Properties(); | |||||
| try | |||||
| { | |||||
| properties.load( zipFile.getInputStream( entry ) ); | |||||
| } | |||||
| catch( final IOException ioe ) | |||||
| { | |||||
| throw new DeploymentException( "Error reading " + filename + | |||||
| " from " + zipFile.getName(), | |||||
| ioe ); | |||||
| } | |||||
| return properties; | |||||
| } | |||||
| protected boolean canUndeploy( final Component component ) | |||||
| throws DeploymentException | |||||
| { | |||||
| return true; | |||||
| } | |||||
| void deployConverter( String name, String location, URL url ) | |||||
| throws DeploymentException; | |||||
| protected void shutdownDeployment( final Component component ) | |||||
| throws DeploymentException | |||||
| { | |||||
| } | |||||
| void deployTasklet( String name, String location, URL url ) | |||||
| throws DeploymentException; | |||||
| } | } | ||||
| @@ -0,0 +1,103 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.tasks.core; | |||||
| import java.io.File; | |||||
| import java.net.MalformedURLException; | |||||
| import java.net.URL; | |||||
| import org.apache.ant.AntException; | |||||
| import org.apache.ant.tasklet.AbstractTasklet; | |||||
| import org.apache.ant.tasklet.engine.DefaultTaskletInfo; | |||||
| import org.apache.ant.tasklet.engine.TaskletEngine; | |||||
| import org.apache.avalon.ComponentManager; | |||||
| import org.apache.avalon.ComponentNotAccessibleException; | |||||
| import org.apache.avalon.ComponentNotFoundException; | |||||
| import org.apache.avalon.Composer; | |||||
| import org.apache.avalon.camelot.RegistryException; | |||||
| /** | |||||
| * Method to register a single tasklet. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public abstract class AbstractResourceRegisterer | |||||
| extends AbstractTasklet | |||||
| implements Composer | |||||
| { | |||||
| protected String m_lib; | |||||
| protected String m_name; | |||||
| protected String m_classname; | |||||
| protected TaskletEngine m_engine; | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentNotFoundException, ComponentNotAccessibleException | |||||
| { | |||||
| m_engine = (TaskletEngine)componentManager. | |||||
| lookup( "org.apache.ant.tasklet.engine.TaskletEngine" ); | |||||
| } | |||||
| public void setLib( final String lib ) | |||||
| { | |||||
| m_lib = lib; | |||||
| } | |||||
| public void setName( final String name ) | |||||
| { | |||||
| m_name = name; | |||||
| } | |||||
| public void setClassname( final String classname ) | |||||
| { | |||||
| m_classname = classname; | |||||
| } | |||||
| public void run() | |||||
| throws AntException | |||||
| { | |||||
| if( null == m_name ) | |||||
| { | |||||
| throw new AntException( "Must specify name parameter" ); | |||||
| } | |||||
| else if( null == m_lib && null == m_classname ) | |||||
| { | |||||
| throw new AntException( "Must specify classname if you don't specify " + | |||||
| "lib parameter" ); | |||||
| } | |||||
| final URL url = getURL( m_lib ); | |||||
| try | |||||
| { | |||||
| registerResource( m_name, m_classname, url ); | |||||
| } | |||||
| catch( final RegistryException re ) | |||||
| { | |||||
| throw new AntException( "Error registering resource", re ); | |||||
| } | |||||
| } | |||||
| protected URL getURL( final String libName ) | |||||
| { | |||||
| if( null != libName ) | |||||
| { | |||||
| final File lib = new File( getContext().resolveFilename( libName ) ); | |||||
| try { return lib.toURL(); } | |||||
| catch( final MalformedURLException mue ) | |||||
| { | |||||
| throw new AntException( "Malformed task-lib parameter " + m_lib, mue ); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| protected abstract void registerResource( String name, String classname, URL url ) | |||||
| throws AntException, RegistryException; | |||||
| } | |||||
| @@ -0,0 +1,139 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.tasks.core; | |||||
| import java.io.File; | |||||
| import java.net.URL; | |||||
| import java.net.MalformedURLException; | |||||
| import org.apache.ant.AntException; | |||||
| import org.apache.ant.convert.DefaultConverterInfo; | |||||
| import org.apache.ant.convert.ConverterEngine; | |||||
| import org.apache.ant.tasklet.AbstractTasklet; | |||||
| import org.apache.ant.tasklet.engine.TaskletEngine; | |||||
| import org.apache.avalon.ComponentManager; | |||||
| import org.apache.avalon.ComponentNotAccessibleException; | |||||
| import org.apache.avalon.ComponentNotFoundException; | |||||
| import org.apache.avalon.Composer; | |||||
| import org.apache.avalon.camelot.DeploymentException; | |||||
| import org.apache.avalon.camelot.RegistryException; | |||||
| /** | |||||
| * Method to register a single converter. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class RegisterConverter | |||||
| extends AbstractTasklet | |||||
| implements Composer | |||||
| { | |||||
| protected String m_sourceType; | |||||
| protected String m_destinationType; | |||||
| protected String m_lib; | |||||
| protected String m_classname; | |||||
| protected TaskletEngine m_engine; | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentNotFoundException, ComponentNotAccessibleException | |||||
| { | |||||
| m_engine = (TaskletEngine)componentManager. | |||||
| lookup( "org.apache.ant.tasklet.engine.TaskletEngine" ); | |||||
| } | |||||
| public void setLib( final String lib ) | |||||
| { | |||||
| m_lib = lib; | |||||
| } | |||||
| public void setClassname( final String classname ) | |||||
| { | |||||
| m_classname = classname; | |||||
| } | |||||
| public void setSourceType( final String sourceType ) | |||||
| { | |||||
| m_sourceType = sourceType; | |||||
| } | |||||
| public void setDestinationType( final String destinationType ) | |||||
| { | |||||
| m_destinationType = destinationType; | |||||
| } | |||||
| public void run() | |||||
| throws AntException | |||||
| { | |||||
| if( null == m_classname ) | |||||
| { | |||||
| throw new AntException( "Must specify classname parameter" ); | |||||
| } | |||||
| final URL url = getURL( m_lib ); | |||||
| boolean isFullyDefined = true; | |||||
| if( null == m_sourceType && null == m_destinationType ) | |||||
| { | |||||
| isFullyDefined = false; | |||||
| } | |||||
| else if( null == m_sourceType || null == m_destinationType ) | |||||
| { | |||||
| throw new AntException( "Must specify the source-type and destination-type " + | |||||
| "parameters when supplying a name" ); | |||||
| } | |||||
| if( !isFullyDefined && null == url ) | |||||
| { | |||||
| throw new AntException( "Must supply parameter if not fully specifying converter" ); | |||||
| } | |||||
| if( !isFullyDefined ) | |||||
| { | |||||
| try | |||||
| { | |||||
| m_engine.getTskDeployer().deployConverter( m_classname, url.toString(), url ); | |||||
| } | |||||
| catch( final DeploymentException de ) | |||||
| { | |||||
| throw new AntException( "Failed deploying " + m_classname + | |||||
| " from " + url, de ); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| final DefaultConverterInfo info = | |||||
| new DefaultConverterInfo( m_sourceType, m_destinationType, m_classname, url ); | |||||
| try | |||||
| { | |||||
| m_engine.getConverterEngine(). | |||||
| getConverterRegistry().register( m_classname, info ); | |||||
| } | |||||
| catch( final RegistryException re ) | |||||
| { | |||||
| throw new AntException( "Error registering resource", re ); | |||||
| } | |||||
| } | |||||
| } | |||||
| protected URL getURL( final String libName ) | |||||
| { | |||||
| if( null != libName ) | |||||
| { | |||||
| final File lib = new File( getContext().resolveFilename( libName ) ); | |||||
| try { return lib.toURL(); } | |||||
| catch( final MalformedURLException mue ) | |||||
| { | |||||
| throw new AntException( "Malformed task-lib parameter " + m_lib, mue ); | |||||
| } | |||||
| } | |||||
| else | |||||
| { | |||||
| return null; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -7,18 +7,10 @@ | |||||
| */ | */ | ||||
| package org.apache.ant.tasks.core; | package org.apache.ant.tasks.core; | ||||
| import java.io.File; | |||||
| import java.net.MalformedURLException; | |||||
| import java.net.URL; | import java.net.URL; | ||||
| import org.apache.ant.AntException; | import org.apache.ant.AntException; | ||||
| import org.apache.ant.tasklet.AbstractTasklet; | |||||
| import org.apache.ant.tasklet.engine.DefaultTaskletInfo; | import org.apache.ant.tasklet.engine.DefaultTaskletInfo; | ||||
| import org.apache.ant.tasklet.engine.TaskletEngine; | |||||
| import org.apache.ant.tasklet.engine.TaskletRegistry; | |||||
| import org.apache.avalon.ComponentManager; | |||||
| import org.apache.avalon.ComponentNotAccessibleException; | |||||
| import org.apache.avalon.ComponentNotFoundException; | |||||
| import org.apache.avalon.Composer; | |||||
| import org.apache.avalon.camelot.DeploymentException; | |||||
| import org.apache.avalon.camelot.RegistryException; | import org.apache.avalon.camelot.RegistryException; | ||||
| /** | /** | ||||
| @@ -27,90 +19,25 @@ import org.apache.avalon.camelot.RegistryException; | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public class RegisterTasklet | public class RegisterTasklet | ||||
| extends AbstractTasklet | |||||
| implements Composer | |||||
| extends AbstractResourceRegisterer | |||||
| { | { | ||||
| protected TaskletRegistry m_taskletRegistry; | |||||
| protected String m_tasklib; | |||||
| protected String m_taskName; | |||||
| protected String m_classname; | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentNotFoundException, ComponentNotAccessibleException | |||||
| { | |||||
| final TaskletEngine engine = (TaskletEngine)componentManager. | |||||
| lookup( "org.apache.ant.tasklet.engine.TaskletEngine" ); | |||||
| m_taskletRegistry = engine.getTaskletRegistry(); | |||||
| } | |||||
| public void setTaskLib( final String tasklib ) | |||||
| { | |||||
| m_tasklib = tasklib; | |||||
| } | |||||
| public void setTaskName( final String taskName ) | |||||
| { | |||||
| m_taskName = taskName; | |||||
| } | |||||
| public void setClassname( final String classname ) | |||||
| { | |||||
| m_classname = classname; | |||||
| } | |||||
| public void run() | |||||
| throws AntException | |||||
| protected void registerResource( final String name, | |||||
| final String classname, | |||||
| final URL url ) | |||||
| throws AntException, RegistryException | |||||
| { | { | ||||
| /* | |||||
| if( null == m_tasklib ) | |||||
| { | |||||
| throw new AntException( "Must specify tasklib parameter" ); | |||||
| } | |||||
| */ | |||||
| if( null == m_taskName ) | |||||
| if( null == classname ) | |||||
| { | { | ||||
| throw new AntException( "Must specify taskname parameter" ); | |||||
| } | |||||
| if( null == m_tasklib && null == m_classname ) | |||||
| { | |||||
| throw new AntException( "Must specify classname if don't specify " + | |||||
| "tasklib parameter" ); | |||||
| } | |||||
| if( null == m_classname ) | |||||
| { | |||||
| m_classname = getDefaultClassName(); | |||||
| } | |||||
| try | |||||
| { | |||||
| URL url = null; | |||||
| if( null != m_tasklib ) | |||||
| try { m_engine.getTskDeployer().deployTasklet( name, url.toString(), url ); } | |||||
| catch( final DeploymentException de ) | |||||
| { | { | ||||
| final File tasklib = new File( getContext().resolveFilename( m_tasklib ) ); | |||||
| url = tasklib.toURL(); | |||||
| throw new AntException( "Failed deploying " + name + " from " + url, de ); | |||||
| } | } | ||||
| final DefaultTaskletInfo info = new DefaultTaskletInfo( m_classname, url ); | |||||
| m_taskletRegistry.register( m_taskName, info ); | |||||
| } | |||||
| catch( final MalformedURLException mue ) | |||||
| { | |||||
| throw new AntException( "Malformed task-lib parameter " + m_tasklib, mue ); | |||||
| } | } | ||||
| catch( final RegistryException re ) | |||||
| else | |||||
| { | { | ||||
| throw new AntException( "Error registering " + m_taskName + " due to " + re, re ); | |||||
| final DefaultTaskletInfo info = new DefaultTaskletInfo( classname, url ); | |||||
| m_engine.getTaskletRegistry().register( name, info ); | |||||
| } | } | ||||
| } | } | ||||
| protected String getDefaultClassName() | |||||
| throws AntException | |||||
| { | |||||
| //TODO: | |||||
| throw new AntException( "Not yet capable of automagically finding classname" ); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,72 @@ | |||||
| /* | |||||
| * Copyright (C) The Apache Software Foundation. All rights reserved. | |||||
| * | |||||
| * This software is published under the terms of the Apache Software License | |||||
| * version 1.1, a copy of which has been included with this distribution in | |||||
| * the LICENSE file. | |||||
| */ | |||||
| package org.apache.ant.tasks.core; | |||||
| import java.io.File; | |||||
| import java.net.MalformedURLException; | |||||
| import java.net.URL; | |||||
| import org.apache.ant.AntException; | |||||
| import org.apache.ant.tasklet.AbstractTasklet; | |||||
| import org.apache.ant.tasklet.engine.TaskletEngine; | |||||
| import org.apache.avalon.ComponentManager; | |||||
| import org.apache.avalon.ComponentNotAccessibleException; | |||||
| import org.apache.avalon.ComponentNotFoundException; | |||||
| import org.apache.avalon.Composer; | |||||
| import org.apache.avalon.camelot.DeploymentException; | |||||
| /** | |||||
| * Method to register a tasklib. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public class RegisterTasklib | |||||
| extends AbstractTasklet | |||||
| implements Composer | |||||
| { | |||||
| protected String m_lib; | |||||
| protected TaskletEngine m_engine; | |||||
| public void compose( final ComponentManager componentManager ) | |||||
| throws ComponentNotFoundException, ComponentNotAccessibleException | |||||
| { | |||||
| m_engine = (TaskletEngine)componentManager. | |||||
| lookup( "org.apache.ant.tasklet.engine.TaskletEngine" ); | |||||
| } | |||||
| public void setLib( final String lib ) | |||||
| { | |||||
| m_lib = lib; | |||||
| } | |||||
| public void run() | |||||
| throws AntException | |||||
| { | |||||
| if( null == m_lib ) | |||||
| { | |||||
| throw new AntException( "Must specify lib parameter" ); | |||||
| } | |||||
| URL url = null; | |||||
| final File lib = new File( getContext().resolveFilename( m_lib ) ); | |||||
| try { url = lib.toURL(); } | |||||
| catch( final MalformedURLException mue ) | |||||
| { | |||||
| throw new AntException( "Malformed task-lib parameter " + m_lib, mue ); | |||||
| } | |||||
| try | |||||
| { | |||||
| m_engine.getTskDeployer().deploy( url.toString(), url ); | |||||
| } | |||||
| catch( final DeploymentException de ) | |||||
| { | |||||
| throw new AntException( "Error registering resource", de ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -6,4 +6,6 @@ conf-test=org.apache.ant.tasks.core.ConfigurationTest | |||||
| content-test=org.apache.ant.tasks.core.ContentTest | content-test=org.apache.ant.tasks.core.ContentTest | ||||
| property=org.apache.ant.tasks.core.Property | property=org.apache.ant.tasks.core.Property | ||||
| register-tasklet=org.apache.ant.tasks.core.RegisterTasklet | register-tasklet=org.apache.ant.tasks.core.RegisterTasklet | ||||
| register-converter=org.apache.ant.tasks.core.RegisterConverter | |||||
| register-tasklib=org.apache.ant.tasks.core.RegisterTasklib | |||||
| ant-call=org.apache.ant.tasks.core.AntCall | ant-call=org.apache.ant.tasks.core.AntCall | ||||
| @@ -58,10 +58,18 @@ Legal: | |||||
| <property name="blah" value="fred" /> | <property name="blah" value="fred" /> | ||||
| <property name="${blah}" value="barney" /> | <property name="${blah}" value="barney" /> | ||||
| <register-tasklet task-lib="../../dist/lib/core.tsk" | |||||
| task-name="echo2" | |||||
| <register-tasklet lib="../../dist/lib/core.tsk" | |||||
| name="echo2" | |||||
| classname="org.apache.ant.tasks.core.Echo" /> | classname="org.apache.ant.tasks.core.Echo" /> | ||||
| <!-- | |||||
| <register-tasklib lib="../../dist/lib/core.tsk" /> | |||||
| <register-converter classname="org.apache.ant.convert.core.StringToClassConverter" | |||||
| source-type="java.lang.String" | |||||
| destination-type="java.lang.Class" | |||||
| lib="../../dist/lib/core.tsk" /> | |||||
| --> | |||||
| <echo message="Doing the funky Echo with ${blah} ${fred} Year=${year}!"/> | <echo message="Doing the funky Echo with ${blah} ${fred} Year=${year}!"/> | ||||
| <echo2 message="Luke to Echo base. Can you hear me?"/> | <echo2 message="Luke to Echo base. Can you hear me?"/> | ||||
| @@ -74,6 +82,7 @@ Legal: | |||||
| <target name="property-test2"> | <target name="property-test2"> | ||||
| <echo message="This should fail ...."/> | <echo message="This should fail ...."/> | ||||
| <echo message="${blah}"/> | <echo message="${blah}"/> | ||||
| <echo message="Whoa - it no fail. Did you use ant-call to call me and set param blah?"/> | |||||
| </target> | </target> | ||||
| </project> | </project> | ||||
| @@ -25,7 +25,7 @@ while [ -h "$PRG" ] ; do | |||||
| fi | fi | ||||
| done | done | ||||
| ANT_HOME=`dirname "$PRG"`/.. | |||||
| MYRMIDON_HOME=`dirname "$PRG"`/.. | |||||
| if [ "$JAVA_HOME" == "" ] ; then | if [ "$JAVA_HOME" == "" ] ; then | ||||
| @@ -42,4 +42,4 @@ else | |||||
| fi | fi | ||||
| fi | fi | ||||
| $JAVACMD $ANT_OPTS -jar ant.jar --ant-home=${ANT_HOME} $@ | |||||
| $JAVACMD $ANT_OPTS -jar ant.jar --ant-home=${MYRMIDON_HOME} $@ | |||||