git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268337 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -165,10 +165,8 @@ Legal: | |||
| --> | |||
| <mkdir dir="${build.classes}/TASK-LIB"/> | |||
| <copy file="${build.src}/org/apache/ant/tasks/core/taskdefs.properties" | |||
| todir="${build.classes}/TASK-LIB"/> | |||
| <copy file="${build.src}/org/apache/ant/convert/core/converters.properties" | |||
| todir="${build.classes}/TASK-LIB"/> | |||
| <copy file="${manifest.dir}/taskdefs.xml" todir="${build.classes}/TASK-LIB"/> | |||
| </target> | |||
| <!-- | |||
| @@ -5,10 +5,8 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.tasklet.engine; | |||
| package org.apache.ant.configuration; | |||
| import org.apache.ant.configuration.Configuration; | |||
| import org.apache.ant.tasklet.Tasklet; | |||
| import org.apache.avalon.Component; | |||
| import org.apache.avalon.ConfigurationException; | |||
| import org.apache.avalon.Context; | |||
| @@ -18,19 +16,19 @@ import org.apache.avalon.Context; | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface TaskletConfigurer | |||
| public interface Configurer | |||
| extends Component | |||
| { | |||
| /** | |||
| * Configure a task based on a configuration in a particular context. | |||
| * Configure an object based on a configuration in a particular context. | |||
| * This configuring can be done in different ways for different | |||
| * configurers. | |||
| * | |||
| * @param tasklet the tasklet | |||
| * @param object the object | |||
| * @param configuration the configuration | |||
| * @param context the Context | |||
| * @exception ConfigurationException if an error occurs | |||
| */ | |||
| void configure( Tasklet tasklet, Configuration configuration, Context context ) | |||
| void configure( Object object, Configuration configuration, Context context ) | |||
| throws ConfigurationException; | |||
| } | |||
| @@ -5,17 +5,14 @@ | |||
| * version 1.1, a copy of which has been included with this distribution in | |||
| * the LICENSE file. | |||
| */ | |||
| package org.apache.ant.tasklet.engine; | |||
| package org.apache.ant.configuration; | |||
| import java.lang.reflect.InvocationTargetException; | |||
| import java.lang.reflect.Method; | |||
| import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import org.apache.ant.configuration.Configurable; | |||
| import org.apache.ant.configuration.Configuration; | |||
| import org.apache.ant.convert.Converter; | |||
| import org.apache.ant.convert.ConverterException; | |||
| import org.apache.ant.tasklet.Tasklet; | |||
| import org.apache.avalon.ComponentManager; | |||
| import org.apache.avalon.ComponentNotAccessibleException; | |||
| import org.apache.avalon.ComponentNotFoundException; | |||
| @@ -30,8 +27,8 @@ import org.apache.avalon.util.PropertyUtil; | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultTaskletConfigurer | |||
| implements TaskletConfigurer, Composer | |||
| public class DefaultConfigurer | |||
| implements Configurer, Composer | |||
| { | |||
| protected final static String RESERVED_ATTRIBUTES[] = | |||
| { | |||
| @@ -51,27 +48,6 @@ public class DefaultTaskletConfigurer | |||
| m_converter = (Converter)componentManager.lookup( "org.apache.ant.convert.Converter" ); | |||
| } | |||
| /** | |||
| * Configure a task based on a configuration in a particular context. | |||
| * This configuring can be done in different ways for different | |||
| * configurers. | |||
| * This one does it by first checking if object implements Configurable | |||
| * and if it does will pass the task the configuration - else it will use | |||
| * ants rules to map configuration to types | |||
| * | |||
| * @param tasklet the tasklet | |||
| * @param configuration the configuration | |||
| * @param context the Context | |||
| * @exception ConfigurationException if an error occurs | |||
| */ | |||
| public void configure( final Tasklet tasklet, | |||
| final Configuration configuration, | |||
| final Context context ) | |||
| throws ConfigurationException | |||
| { | |||
| configure( (Object)tasklet, configuration, context ); | |||
| } | |||
| /** | |||
| * Configure a task based on a configuration in a particular context. | |||
| * This configuring can be done in different ways for different | |||
| @@ -8,13 +8,13 @@ | |||
| package org.apache.ant.convert; | |||
| import org.apache.avalon.Component; | |||
| import org.apache.avalon.Loggable; | |||
| import org.apache.avalon.camelot.LocatorRegistry; | |||
| import org.apache.log.Logger; | |||
| public interface ConverterEngine | |||
| extends Component, Converter | |||
| extends Component, Converter, Loggable | |||
| { | |||
| void setLogger( Logger logger ); | |||
| LocatorRegistry getLocatorRegistry(); | |||
| ConverterRegistry getConverterRegistry(); | |||
| ConverterFactory getConverterFactory(); | |||
| } | |||
| @@ -1,30 +0,0 @@ | |||
| /* | |||
| * 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.camelot.Factory; | |||
| import org.apache.avalon.camelot.FactoryException; | |||
| /** | |||
| * Facility used to load Converters. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface ConverterFactory | |||
| extends Factory | |||
| { | |||
| /** | |||
| * Create entries (ie instances) from infos (ie types). | |||
| * | |||
| * @param info the info | |||
| * @return the entry | |||
| * @exception FactoryException if an error occurs | |||
| */ | |||
| Converter createConverter( ConverterInfo info ) | |||
| throws FactoryException; | |||
| } | |||
| @@ -7,7 +7,6 @@ | |||
| */ | |||
| package org.apache.ant.convert; | |||
| import java.net.URL; | |||
| import org.apache.avalon.camelot.Info; | |||
| /** | |||
| @@ -33,19 +32,4 @@ public interface ConverterInfo | |||
| * @return the classname of the produced object | |||
| */ | |||
| String getDestination(); | |||
| /** | |||
| * Retrieve classname for concerter. | |||
| * | |||
| * @return the taskname | |||
| */ | |||
| String getClassname(); | |||
| /** | |||
| * Retrieve location of task library where task is contained. | |||
| * | |||
| * @return the location of task library | |||
| */ | |||
| URL getLocation(); | |||
| } | |||
| @@ -1,29 +0,0 @@ | |||
| /* | |||
| * 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.camelot.Loader; | |||
| /** | |||
| * Class used to load converters et al from a source. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface ConverterLoader | |||
| extends Loader | |||
| { | |||
| /** | |||
| * Load a particular converter. | |||
| * | |||
| * @param converter the converter name | |||
| * @return the loaded Converter | |||
| * @exception Exception if an error occurs | |||
| */ | |||
| Converter loadConverter( String converter ) | |||
| throws Exception; | |||
| } | |||
| @@ -17,11 +17,12 @@ public interface ConverterRegistry | |||
| extends Registry | |||
| { | |||
| /** | |||
| * Retrieve ConverterInfo that describes converter that converts from source to destination. | |||
| * Retrieve name of ConverterInfo that describes converter that converts | |||
| * from source to destination. | |||
| * | |||
| * @param source the source classname | |||
| * @param destination the destination classname | |||
| * @return the converter-info or null if none available | |||
| */ | |||
| ConverterInfo getConverterInfo( String source, String destination ); | |||
| String getConverterInfoName( String source, String destination ); | |||
| } | |||
| @@ -10,12 +10,17 @@ package org.apache.ant.convert; | |||
| import org.apache.ant.AntException; | |||
| import org.apache.avalon.Component; | |||
| import org.apache.avalon.Initializable; | |||
| import org.apache.avalon.camelot.DefaultFactory; | |||
| import org.apache.avalon.camelot.DefaultLocatorRegistry; | |||
| import org.apache.avalon.camelot.Locator; | |||
| import org.apache.avalon.camelot.LocatorRegistry; | |||
| import org.apache.log.Logger; | |||
| public class DefaultConverterEngine | |||
| implements ConverterEngine, Initializable | |||
| { | |||
| protected ConverterFactory m_converterFactory; | |||
| protected DefaultFactory m_factory; | |||
| protected LocatorRegistry m_locatorRegistry; | |||
| protected ConverterRegistry m_converterRegistry; | |||
| protected Logger m_logger; | |||
| @@ -24,21 +29,22 @@ public class DefaultConverterEngine | |||
| m_logger = logger; | |||
| } | |||
| public ConverterRegistry getConverterRegistry() | |||
| public LocatorRegistry getLocatorRegistry() | |||
| { | |||
| return m_converterRegistry; | |||
| return m_locatorRegistry; | |||
| } | |||
| public ConverterFactory getConverterFactory() | |||
| public ConverterRegistry getConverterRegistry() | |||
| { | |||
| return m_converterFactory; | |||
| return m_converterRegistry; | |||
| } | |||
| public void init() | |||
| throws Exception | |||
| { | |||
| m_converterRegistry = createConverterRegistry(); | |||
| m_converterFactory = createConverterFactory(); | |||
| m_locatorRegistry = createLocatorRegistry(); | |||
| m_factory = createFactory(); | |||
| } | |||
| protected ConverterRegistry createConverterRegistry() | |||
| @@ -46,26 +52,32 @@ public class DefaultConverterEngine | |||
| return new DefaultConverterRegistry(); | |||
| } | |||
| protected ConverterFactory createConverterFactory() | |||
| protected LocatorRegistry createLocatorRegistry() | |||
| { | |||
| return new DefaultLocatorRegistry(); | |||
| } | |||
| protected DefaultFactory createFactory() | |||
| { | |||
| return new DefaultConverterFactory(); | |||
| return new DefaultFactory(); | |||
| } | |||
| public Object convert( Class destination, final Object original ) | |||
| throws Exception | |||
| { | |||
| final ConverterInfo info = | |||
| m_converterRegistry.getConverterInfo( original.getClass().getName(), | |||
| destination.getName() ); | |||
| final String name = | |||
| m_converterRegistry.getConverterInfoName( original.getClass().getName(), | |||
| destination.getName() ); | |||
| if( null == info ) | |||
| if( null == name ) | |||
| { | |||
| throw new ConverterException( "Unable to find converter for " + | |||
| original.getClass() + " to " + destination + | |||
| " conversion" ); | |||
| } | |||
| final Converter converter = m_converterFactory.createConverter( info ); | |||
| final Locator locator = m_locatorRegistry.getLocator( name ); | |||
| final Converter converter = (Converter)m_factory.create( locator, Converter.class ); | |||
| return converter.convert( destination, original ); | |||
| } | |||
| } | |||
| @@ -1,98 +0,0 @@ | |||
| /* | |||
| * 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 java.net.URL; | |||
| import java.net.URLClassLoader; | |||
| import java.util.HashMap; | |||
| import org.apache.ant.convert.Converter; | |||
| import org.apache.avalon.camelot.Entry; | |||
| import org.apache.avalon.camelot.Factory; | |||
| import org.apache.avalon.camelot.Loader; | |||
| import org.apache.avalon.camelot.FactoryException; | |||
| import org.apache.avalon.camelot.Info; | |||
| /** | |||
| * Facility used to load Converters. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultConverterFactory | |||
| implements ConverterFactory | |||
| { | |||
| protected final HashMap m_loaders = new HashMap(); | |||
| /** | |||
| * Method for generic Factory. | |||
| * | |||
| * @param info generic info | |||
| * @return the created entry | |||
| * @exception FactoryException if an error occurs | |||
| */ | |||
| public Object create( final Info info ) | |||
| throws FactoryException | |||
| { | |||
| if( info.getClass().equals( ConverterInfo.class ) ) | |||
| { | |||
| throw new IllegalArgumentException( "Passed incorrect Info type to factory" ); | |||
| } | |||
| return create( (ConverterInfo)info ); | |||
| } | |||
| /** | |||
| * Non-generic factory method. | |||
| * | |||
| * @param info the info to create instance from | |||
| * @return the created entry | |||
| * @exception FactoryException if an error occurs | |||
| */ | |||
| public Converter createConverter( final ConverterInfo info ) | |||
| throws FactoryException | |||
| { | |||
| final ConverterLoader loader = getLoader( info.getLocation() ); | |||
| try { return (Converter)loader.load( info.getClassname() ); } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new FactoryException( "Failed loading converter from " + info.getLocation() + | |||
| " due to " + e, e ); | |||
| } | |||
| } | |||
| /** | |||
| * Get a loader for a particular location | |||
| * | |||
| * @param location the location | |||
| * @return the loader | |||
| */ | |||
| protected ConverterLoader getLoader( final URL location ) | |||
| { | |||
| ConverterLoader loader = (ConverterLoader)m_loaders.get( location ); | |||
| if( null == loader ) | |||
| { | |||
| loader = createLoader( location ); | |||
| m_loaders.put( location, loader ); | |||
| } | |||
| return loader; | |||
| } | |||
| /** | |||
| * Create a new loader. | |||
| * Put in another method so that it can be overridden. | |||
| * | |||
| * @param location the location the Loader will load from | |||
| * @return the loader | |||
| */ | |||
| protected ConverterLoader createLoader( final URL location ) | |||
| { | |||
| if( null != location ) return new DefaultConverterLoader( location ); | |||
| else return new DefaultConverterLoader(); | |||
| } | |||
| } | |||
| @@ -7,8 +7,6 @@ | |||
| */ | |||
| package org.apache.ant.convert; | |||
| import java.net.URL; | |||
| /** | |||
| * This info represents meta-information about a converter. | |||
| * | |||
| @@ -19,18 +17,11 @@ public class DefaultConverterInfo | |||
| { | |||
| protected final String m_source; | |||
| protected final String m_destination; | |||
| protected final String m_classname; | |||
| protected final URL m_location; | |||
| public DefaultConverterInfo( final String source, | |||
| final String destination, | |||
| final String classname, | |||
| final URL location ) | |||
| public DefaultConverterInfo( final String source, final String destination ) | |||
| { | |||
| m_source = source; | |||
| m_destination = destination; | |||
| m_classname = classname; | |||
| m_location = location; | |||
| } | |||
| /** | |||
| @@ -54,25 +45,5 @@ public class DefaultConverterInfo | |||
| { | |||
| return m_destination; | |||
| } | |||
| /** | |||
| * Retrieve classname for concerter. | |||
| * | |||
| * @return the taskname | |||
| */ | |||
| public String getClassname() | |||
| { | |||
| return m_classname; | |||
| } | |||
| /** | |||
| * Retrieve location of task library where task is contained. | |||
| * | |||
| * @return the location of task library | |||
| */ | |||
| public URL getLocation() | |||
| { | |||
| return m_location; | |||
| } | |||
| } | |||
| @@ -1,47 +0,0 @@ | |||
| /* | |||
| * 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 java.net.URL; | |||
| import java.net.URLClassLoader; | |||
| import org.apache.avalon.camelot.AbstractLoader; | |||
| /** | |||
| * Class used to load converters et al from a source. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultConverterLoader | |||
| extends AbstractLoader | |||
| implements ConverterLoader | |||
| { | |||
| public DefaultConverterLoader() | |||
| { | |||
| super( new URLClassLoader( new URL[0], | |||
| Thread.currentThread().getContextClassLoader() ) ); | |||
| } | |||
| public DefaultConverterLoader( final URL location ) | |||
| { | |||
| super( new URLClassLoader( new URL[] { location }, | |||
| Thread.currentThread().getContextClassLoader() ) ); | |||
| } | |||
| /** | |||
| * Load a Converter object. | |||
| * | |||
| * @param converter the converter classname | |||
| * @return the converter instance | |||
| * @exception Exception if an error occurs | |||
| */ | |||
| public Converter loadConverter( final String converter ) | |||
| throws Exception | |||
| { | |||
| return (Converter)load( converter ); | |||
| } | |||
| } | |||
| @@ -30,11 +30,11 @@ public class DefaultConverterRegistry | |||
| * @param destination the destination classname | |||
| * @return the converter-info or null if none available | |||
| */ | |||
| public ConverterInfo getConverterInfo( final String source, final String destination ) | |||
| public String getConverterInfoName( final String source, final String destination ) | |||
| { | |||
| final HashMap map = (HashMap)m_mapping.get( source ); | |||
| if( null == map ) return null; | |||
| return (ConverterInfo)map.get( destination ); | |||
| return (String)map.get( destination ); | |||
| } | |||
| protected void checkInfo( final String name, final Info info ) | |||
| @@ -53,7 +53,7 @@ public class DefaultConverterRegistry | |||
| m_mapping.put( source, map ); | |||
| } | |||
| map.put( destination, info ); | |||
| map.put( destination, name ); | |||
| } | |||
| protected Class getInfoClass() | |||
| @@ -1,8 +0,0 @@ | |||
| org.apache.ant.convert.core.StringToLongConverter=java.lang.String, java.lang.Long | |||
| org.apache.ant.convert.core.StringToIntegerConverter=java.lang.String, java.lang.Integer | |||
| org.apache.ant.convert.core.StringToShortConverter=java.lang.String, java.lang.Short | |||
| 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.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,19 +11,25 @@ import java.util.HashMap; | |||
| import org.apache.ant.AntException; | |||
| import org.apache.ant.configuration.Configurable; | |||
| import org.apache.ant.configuration.Configuration; | |||
| import org.apache.ant.configuration.Configurer; | |||
| import org.apache.ant.configuration.DefaultConfigurer; | |||
| import org.apache.ant.convert.ConverterEngine; | |||
| import org.apache.ant.convert.ConverterFactory; | |||
| import org.apache.ant.tasklet.Tasklet; | |||
| import org.apache.ant.tasklet.TaskletContext; | |||
| import org.apache.avalon.Component; | |||
| import org.apache.avalon.Composer; | |||
| import org.apache.avalon.ComponentManager; | |||
| import org.apache.avalon.Composer; | |||
| import org.apache.avalon.Context; | |||
| import org.apache.avalon.Contextualizable; | |||
| import org.apache.avalon.DefaultComponentManager; | |||
| import org.apache.avalon.Disposable; | |||
| import org.apache.avalon.Loggable; | |||
| import org.apache.avalon.Initializable; | |||
| import org.apache.avalon.camelot.DefaultFactory; | |||
| import org.apache.avalon.camelot.FactoryException; | |||
| import org.apache.avalon.camelot.LocatorRegistry; | |||
| import org.apache.avalon.camelot.Locator; | |||
| import org.apache.avalon.camelot.DefaultLocatorRegistry; | |||
| import org.apache.avalon.camelot.RegistryException; | |||
| import org.apache.log.Logger; | |||
| @@ -31,9 +37,9 @@ public class DefaultTaskletEngine | |||
| implements TaskletEngine, Initializable | |||
| { | |||
| protected TskDeployer m_tskDeployer; | |||
| protected TaskletFactory m_taskletFactory; | |||
| protected TaskletRegistry m_taskletRegistry; | |||
| protected TaskletConfigurer m_configurer; | |||
| protected DefaultFactory m_factory; | |||
| protected LocatorRegistry m_locatorRegistry; | |||
| protected Configurer m_configurer; | |||
| protected Logger m_logger; | |||
| protected ConverterEngine m_converterEngine; | |||
| @@ -52,22 +58,23 @@ public class DefaultTaskletEngine | |||
| return m_converterEngine; | |||
| } | |||
| public TaskletRegistry getTaskletRegistry() | |||
| public LocatorRegistry getLocatorRegistry() | |||
| { | |||
| return m_taskletRegistry; | |||
| return m_locatorRegistry; | |||
| } | |||
| public void init() | |||
| throws Exception | |||
| { | |||
| m_taskletRegistry = createTaskletRegistry(); | |||
| m_taskletFactory = createTaskletFactory(); | |||
| m_locatorRegistry = createLocatorRegistry(); | |||
| m_factory = createFactory(); | |||
| setupSubComponent( m_factory ); | |||
| m_converterEngine = createConverterEngine(); | |||
| m_converterEngine.setLogger( m_logger ); | |||
| setupSubComponent( m_converterEngine ); | |||
| m_configurer = createTaskletConfigurer(); | |||
| m_configurer = createConfigurer(); | |||
| setupSubComponent( m_configurer ); | |||
| m_tskDeployer = createTskDeployer(); | |||
| @@ -78,6 +85,11 @@ public class DefaultTaskletEngine | |||
| protected void setupSubComponent( final Component component ) | |||
| throws Exception | |||
| { | |||
| if( component instanceof Loggable ) | |||
| { | |||
| ((Loggable)component).setLogger( m_logger ); | |||
| } | |||
| if( component instanceof Composer ) | |||
| { | |||
| final DefaultComponentManager componentManager = new DefaultComponentManager(); | |||
| @@ -90,7 +102,7 @@ public class DefaultTaskletEngine | |||
| ((Composer)component).compose( componentManager ); | |||
| } | |||
| if( component instanceof Initializable ) | |||
| { | |||
| ((Initializable)component).init(); | |||
| @@ -102,19 +114,19 @@ public class DefaultTaskletEngine | |||
| return new DefaultTskDeployer(); | |||
| } | |||
| protected TaskletConfigurer createTaskletConfigurer() | |||
| protected Configurer createConfigurer() | |||
| { | |||
| return new DefaultTaskletConfigurer(); | |||
| return new DefaultConfigurer(); | |||
| } | |||
| protected TaskletRegistry createTaskletRegistry() | |||
| protected LocatorRegistry createLocatorRegistry() | |||
| { | |||
| return new DefaultTaskletRegistry(); | |||
| return new DefaultLocatorRegistry(); | |||
| } | |||
| protected TaskletFactory createTaskletFactory() | |||
| protected DefaultFactory createFactory() | |||
| { | |||
| return new DefaultTaskletFactory(); | |||
| return new DefaultFactory(); | |||
| } | |||
| protected ConverterEngine createConverterEngine() | |||
| @@ -122,7 +134,7 @@ public class DefaultTaskletEngine | |||
| //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 ); | |||
| engine.setFactory( m_factory ); | |||
| return engine; | |||
| } | |||
| @@ -236,21 +248,18 @@ public class DefaultTaskletEngine | |||
| throws AntException | |||
| { | |||
| final String name = configuration.getName(); | |||
| TaskletInfo info = null; | |||
| try { info = (TaskletInfo)m_taskletRegistry.getInfo( name ); } | |||
| try | |||
| { | |||
| final Locator locator = m_locatorRegistry.getLocator( name ); | |||
| return (Tasklet)m_factory.create( locator, Tasklet.class ); | |||
| } | |||
| catch( final RegistryException re ) | |||
| { | |||
| throw new AntException( "Unable to locate task " + name, re ); | |||
| } | |||
| try { return m_taskletFactory.createTasklet( info ); } | |||
| catch( final FactoryException fe ) | |||
| { | |||
| throw new AntException( "Unable to create task " + name + | |||
| " (of type " + info.getClassname() + " from " + | |||
| info.getLocation() + ")", | |||
| fe ); | |||
| throw new AntException( "Unable to create task " + name, fe ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,63 +0,0 @@ | |||
| /* | |||
| * 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.net.URL; | |||
| import java.net.URLClassLoader; | |||
| import java.util.HashMap; | |||
| import org.apache.ant.tasklet.Tasklet; | |||
| import org.apache.ant.convert.ConverterLoader; | |||
| import org.apache.ant.convert.DefaultConverterFactory; | |||
| import org.apache.avalon.camelot.Entry; | |||
| import org.apache.avalon.camelot.Factory; | |||
| import org.apache.avalon.camelot.FactoryException; | |||
| import org.apache.avalon.camelot.Info; | |||
| /** | |||
| * Facility used to load Tasklets. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultTaskletFactory | |||
| extends DefaultConverterFactory | |||
| implements TaskletFactory | |||
| { | |||
| public Object create( final Info info ) | |||
| throws FactoryException | |||
| { | |||
| if( !info.getClass().equals( TaskletInfo.class ) ) | |||
| { | |||
| return super.create( info ); | |||
| } | |||
| else | |||
| { | |||
| return createTasklet( (TaskletInfo)info ); | |||
| } | |||
| } | |||
| public Tasklet createTasklet( final TaskletInfo info ) | |||
| throws FactoryException | |||
| { | |||
| final TaskletLoader loader = (TaskletLoader)getLoader( info.getLocation() ); | |||
| Object object = null; | |||
| try { return (Tasklet)loader.load( info.getClassname() ); } | |||
| catch( final Exception e ) | |||
| { | |||
| throw new FactoryException( "Failed loading tasklet from " + info.getLocation() + | |||
| " due to " + e, e ); | |||
| } | |||
| } | |||
| protected ConverterLoader createLoader( final URL location ) | |||
| { | |||
| if( null != location ) return new DefaultTaskletLoader( location ); | |||
| else return new DefaultTaskletLoader(); | |||
| } | |||
| } | |||
| @@ -1,54 +0,0 @@ | |||
| /* | |||
| * 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.net.URL; | |||
| import org.apache.avalon.camelot.Info; | |||
| /** | |||
| * This is default container of information about a task. | |||
| * A BeanInfo equivelent for a task. Eventually it will auto-magically | |||
| * generate a schema via reflection for Validator/Editor tools. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultTaskletInfo | |||
| implements TaskletInfo | |||
| { | |||
| protected final String m_classname; | |||
| protected final URL m_location; | |||
| /** | |||
| * Constructor that takes classname and taskLibraryLocation. | |||
| */ | |||
| public DefaultTaskletInfo( final String classname, final URL location ) | |||
| { | |||
| m_location = location; | |||
| m_classname = classname; | |||
| } | |||
| /** | |||
| * Retrieve classname for task. | |||
| * | |||
| * @return the taskname | |||
| */ | |||
| public String getClassname() | |||
| { | |||
| return m_classname; | |||
| } | |||
| /** | |||
| * Retrieve tasklib location from which task is loaded. | |||
| * | |||
| * @return the location | |||
| */ | |||
| public URL getLocation() | |||
| { | |||
| return m_location; | |||
| } | |||
| } | |||
| @@ -1,44 +0,0 @@ | |||
| /* | |||
| * 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.net.URL; | |||
| import org.apache.ant.convert.DefaultConverterLoader; | |||
| import org.apache.ant.tasklet.Tasklet; | |||
| /** | |||
| * Class used to load tasks et al from a source. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultTaskletLoader | |||
| extends DefaultConverterLoader | |||
| implements TaskletLoader | |||
| { | |||
| public DefaultTaskletLoader() | |||
| { | |||
| } | |||
| public DefaultTaskletLoader( final URL location ) | |||
| { | |||
| super( location ); | |||
| } | |||
| /** | |||
| * Load a tasklet with a particular classname. | |||
| * | |||
| * @param tasklet the tasklet classname | |||
| * @return the tasklet | |||
| * @exception Exception if an error occurs | |||
| */ | |||
| public Tasklet loadTasklet( final String tasklet ) | |||
| throws Exception | |||
| { | |||
| return (Tasklet)load( tasklet ); | |||
| } | |||
| } | |||
| @@ -1,20 +0,0 @@ | |||
| /* | |||
| * 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.avalon.camelot.AbstractRegistry; | |||
| public class DefaultTaskletRegistry | |||
| extends AbstractRegistry | |||
| implements TaskletRegistry | |||
| { | |||
| protected Class getInfoClass() | |||
| { | |||
| return TaskletInfo.class; | |||
| } | |||
| } | |||
| @@ -11,22 +11,26 @@ 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.Iterator; | |||
| 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.Configuration; | |||
| import org.apache.avalon.ConfigurationException; | |||
| import org.apache.avalon.camelot.AbstractZipDeployer; | |||
| import org.apache.avalon.camelot.DefaultLocator; | |||
| import org.apache.avalon.camelot.DefaultLocatorRegistry; | |||
| import org.apache.avalon.camelot.DeploymentException; | |||
| import org.apache.avalon.camelot.Loader; | |||
| import org.apache.avalon.camelot.LocatorRegistry; | |||
| import org.apache.avalon.camelot.RegistryException; | |||
| import org.apache.log.Logger; | |||
| @@ -36,20 +40,21 @@ import org.apache.log.Logger; | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public class DefaultTskDeployer | |||
| extends AbstractDeployer | |||
| extends AbstractZipDeployer | |||
| implements Composer, TskDeployer | |||
| { | |||
| protected final static String TASKDEF_FILE = "TASK-LIB/taskdefs.properties"; | |||
| protected final static String CONVERTER_FILE = "TASK-LIB/converters.properties"; | |||
| protected final static String TSKDEF_FILE = "TASK-LIB/taskdefs.xml"; | |||
| protected TaskletRegistry m_taskletRegistry; | |||
| protected ConverterRegistry m_converterRegistry; | |||
| protected LocatorRegistry m_taskletRegistry; | |||
| protected LocatorRegistry m_converterRegistry; | |||
| protected ConverterRegistry m_converterInfoRegistry; | |||
| /** | |||
| * Default constructor. | |||
| */ | |||
| public DefaultTskDeployer() | |||
| { | |||
| super( false ); | |||
| m_autoUndeploy = true; | |||
| m_type = "Tasklet"; | |||
| } | |||
| @@ -67,12 +72,13 @@ public class DefaultTskDeployer | |||
| final ConverterEngine converterEngine = (ConverterEngine)componentManager. | |||
| lookup( "org.apache.ant.convert.ConverterEngine" ); | |||
| m_converterRegistry = converterEngine.getConverterRegistry(); | |||
| m_converterInfoRegistry = converterEngine.getConverterRegistry(); | |||
| m_converterRegistry = converterEngine.getLocatorRegistry(); | |||
| final TaskletEngine taskletEngine = (TaskletEngine)componentManager. | |||
| lookup( "org.apache.ant.tasklet.engine.TaskletEngine" ); | |||
| m_taskletRegistry = taskletEngine.getTaskletRegistry(); | |||
| m_taskletRegistry = taskletEngine.getLocatorRegistry(); | |||
| } | |||
| public void setLogger( final Logger logger ) | |||
| @@ -80,50 +86,30 @@ public class DefaultTskDeployer | |||
| 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 ) | |||
| protected void loadResources( final ZipFile zipFile, final String location, final URL url ) | |||
| throws DeploymentException | |||
| { | |||
| m_logger.info( "Deploying .tsk file (" + file + ") as " + location ); | |||
| final ZipFile zipFile = getZipFileFor( file ); | |||
| final Configuration taskdefs = loadConfiguration( zipFile, TSKDEF_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 ); | |||
| final Iterator tasks = taskdefs.getChildren( "task" ); | |||
| while( tasks.hasNext() ) | |||
| { | |||
| final Configuration task = (Configuration)tasks.next(); | |||
| handleTasklet( task, url ); | |||
| } | |||
| final Iterator converters = taskdefs.getChildren( "converter" ); | |||
| while( converters.hasNext() ) | |||
| { | |||
| final Configuration converter = (Configuration)converters.next(); | |||
| handleConverter( converter, url ); | |||
| } | |||
| } | |||
| catch( final DeploymentException de ) | |||
| catch( final ConfigurationException ce ) | |||
| { | |||
| try { zipFile.close(); } | |||
| catch( final IOException ioe ) {} | |||
| throw de; | |||
| throw new DeploymentException( "Malformed taskdefs.xml", ce ); | |||
| } | |||
| } | |||
| @@ -132,15 +118,25 @@ public class DefaultTskDeployer | |||
| { | |||
| checkDeployment( location, url ); | |||
| final ZipFile zipFile = getZipFileFor( url ); | |||
| final Properties converters = loadProperties( zipFile, CONVERTER_FILE ); | |||
| final String value = converters.getProperty( name ); | |||
| if( null == value ) | |||
| final Configuration taskdefs = loadConfiguration( zipFile, TSKDEF_FILE ); | |||
| try | |||
| { | |||
| throw new DeploymentException( "Unable to locate converter named " + name ); | |||
| final Iterator converters = taskdefs.getChildren( "converter" ); | |||
| while( converters.hasNext() ) | |||
| { | |||
| final Configuration converter = (Configuration)converters.next(); | |||
| if( converter.getAttribute( "classname" ).equals( name ) ) | |||
| { | |||
| handleConverter( converter, url ); | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| catch( final ConfigurationException ce ) | |||
| { | |||
| throw new DeploymentException( "Malformed taskdefs.xml", ce ); | |||
| } | |||
| handleConverter( name, value, url ); | |||
| } | |||
| public void deployTasklet( final String name, final String location, final URL url ) | |||
| @@ -148,109 +144,65 @@ public class DefaultTskDeployer | |||
| { | |||
| checkDeployment( location, url ); | |||
| final ZipFile zipFile = getZipFileFor( url ); | |||
| final Properties tasklets = loadProperties( zipFile, TASKDEF_FILE ); | |||
| final String value = tasklets.getProperty( name ); | |||
| final Configuration taskdefs = loadConfiguration( zipFile, TSKDEF_FILE ); | |||
| if( null == value ) | |||
| try | |||
| { | |||
| throw new DeploymentException( "Unable to locate tasklet named " + name ); | |||
| final Iterator tasks = taskdefs.getChildren( "task" ); | |||
| while( tasks.hasNext() ) | |||
| { | |||
| final Configuration task = (Configuration)tasks.next(); | |||
| if( task.getAttribute( "name" ).equals( name ) ) | |||
| { | |||
| handleTasklet( task, url ); | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| 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 ) | |||
| catch( final ConfigurationException ce ) | |||
| { | |||
| throw new DeploymentException( "Error opening " + file + | |||
| " due to " + ioe.getMessage(), | |||
| ioe ); | |||
| } | |||
| throw new DeploymentException( "Malformed taskdefs.xml", ce ); | |||
| } | |||
| } | |||
| /** | |||
| * 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 | |||
| protected void handleConverter( final Configuration converter, final URL url ) | |||
| throws DeploymentException, ConfigurationException | |||
| { | |||
| final Enumeration enum = properties.propertyNames(); | |||
| final String name = converter.getAttribute( "classname" ); | |||
| final String source = converter.getAttribute( "source" ); | |||
| final String destination = converter.getAttribute( "destination" ); | |||
| while( enum.hasMoreElements() ) | |||
| final DefaultConverterInfo info = new DefaultConverterInfo( source, destination ); | |||
| try { m_converterInfoRegistry.register( name, info ); } | |||
| catch( final RegistryException re ) | |||
| { | |||
| final String key = (String)enum.nextElement(); | |||
| final String value = (String)properties.get( key ); | |||
| handleConverter( key, value, url ); | |||
| throw new DeploymentException( "Error registering converter info " + | |||
| name + " due to " + re, | |||
| re ); | |||
| } | |||
| } | |||
| 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 ); } | |||
| final DefaultLocator locator = new DefaultLocator( name, url ); | |||
| try { m_converterRegistry.register( name, locator ); } | |||
| catch( final RegistryException re ) | |||
| { | |||
| throw new DeploymentException( "Error registering converter " + | |||
| throw new DeploymentException( "Error registering converter locator " + | |||
| 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 | |||
| protected void handleTasklet( final Configuration task, final URL url ) | |||
| throws DeploymentException, ConfigurationException | |||
| { | |||
| 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 ); | |||
| } | |||
| } | |||
| final String name = task.getAttribute( "name" ); | |||
| final String classname = task.getAttribute( "classname" ); | |||
| protected void handleTasklet( final String name, final String classname, final URL url ) | |||
| throws DeploymentException | |||
| { | |||
| final DefaultTaskletInfo info = new DefaultTaskletInfo( classname, url ); | |||
| final DefaultLocator info = new DefaultLocator( classname, url ); | |||
| try { m_taskletRegistry.register( name, info ); } | |||
| catch( final RegistryException re ) | |||
| @@ -261,49 +213,4 @@ public class DefaultTskDeployer | |||
| 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 | |||
| { | |||
| } | |||
| } | |||
| @@ -7,8 +7,8 @@ | |||
| */ | |||
| package org.apache.ant.tasklet.engine; | |||
| import org.apache.ant.convert.ConverterFactory; | |||
| import org.apache.ant.convert.DefaultConverterEngine; | |||
| import org.apache.avalon.camelot.DefaultFactory; | |||
| public class TaskletConverterEngine | |||
| extends DefaultConverterEngine | |||
| @@ -17,13 +17,13 @@ public class TaskletConverterEngine | |||
| * Set the ConverterFactory. | |||
| * Package access intended. | |||
| */ | |||
| void setConverterFactory( final ConverterFactory converterFactory ) | |||
| void setFactory( final DefaultFactory factory ) | |||
| { | |||
| m_converterFactory = converterFactory; | |||
| m_factory = factory; | |||
| } | |||
| protected ConverterFactory createConverterFactory() | |||
| protected DefaultFactory createFactory() | |||
| { | |||
| return m_converterFactory; | |||
| return m_factory; | |||
| } | |||
| } | |||
| @@ -12,7 +12,9 @@ import org.apache.ant.configuration.Configuration; | |||
| import org.apache.ant.convert.ConverterEngine; | |||
| import org.apache.ant.tasklet.TaskletContext; | |||
| import org.apache.avalon.Component; | |||
| import org.apache.avalon.Loggable; | |||
| import org.apache.avalon.ComponentManager; | |||
| import org.apache.avalon.camelot.LocatorRegistry; | |||
| import org.apache.log.Logger; | |||
| /** | |||
| @@ -21,10 +23,8 @@ import org.apache.log.Logger; | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface TaskletEngine | |||
| extends Component | |||
| extends Component, Loggable | |||
| { | |||
| void setLogger( Logger logger ); | |||
| /** | |||
| * Retrieve deployer for engine. | |||
| * | |||
| @@ -33,11 +33,11 @@ public interface TaskletEngine | |||
| TskDeployer getTskDeployer(); | |||
| /** | |||
| * Retrieve tasklet registry associated with engine. | |||
| * Retrieve locator registry associated with engine. | |||
| * | |||
| * @return the TaskletRegistry | |||
| * @return the LocatorRegistry | |||
| */ | |||
| TaskletRegistry getTaskletRegistry(); | |||
| LocatorRegistry getLocatorRegistry(); | |||
| /** | |||
| * Retrieve converter engine. | |||
| @@ -1,24 +0,0 @@ | |||
| /* | |||
| * 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.avalon.camelot.Factory; | |||
| import org.apache.avalon.camelot.FactoryException; | |||
| import org.apache.ant.tasklet.Tasklet; | |||
| /** | |||
| * Facility used to load Tasklets. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface TaskletFactory | |||
| extends Factory | |||
| { | |||
| Tasklet createTasklet( TaskletInfo info ) | |||
| throws FactoryException; | |||
| } | |||
| @@ -1,36 +0,0 @@ | |||
| /* | |||
| * 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.net.URL; | |||
| import org.apache.avalon.camelot.Info; | |||
| /** | |||
| * This is information about a task. | |||
| * A BeanInfo equivelent for a task. Eventually it will auto-magically | |||
| * generate a schema via reflection for Validator/Editor tools. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface TaskletInfo | |||
| extends Info | |||
| { | |||
| /** | |||
| * Retrieve classname for task. | |||
| * | |||
| * @return the taskname | |||
| */ | |||
| String getClassname(); | |||
| /** | |||
| * Retrieve location of task library where task is contained. | |||
| * | |||
| * @return the location of task library | |||
| */ | |||
| URL getLocation(); | |||
| } | |||
| @@ -1,30 +0,0 @@ | |||
| /* | |||
| * 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.tasklet.Tasklet; | |||
| import org.apache.avalon.camelot.Loader; | |||
| /** | |||
| * Class used to load tasks et al from a source. | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface TaskletLoader | |||
| extends Loader | |||
| { | |||
| /** | |||
| * Load a tasklet with a particular classname. | |||
| * | |||
| * @param tasklet the tasklet classname | |||
| * @return the tasklet | |||
| * @exception Exception if an error occurs | |||
| */ | |||
| Tasklet loadTasklet( String tasklet ) | |||
| throws Exception; | |||
| } | |||
| @@ -1,20 +0,0 @@ | |||
| /* | |||
| * 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.avalon.camelot.Registry; | |||
| /** | |||
| * The registry for tasklets | |||
| * | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface TaskletRegistry | |||
| extends Registry | |||
| { | |||
| } | |||
| @@ -8,6 +8,7 @@ | |||
| package org.apache.ant.tasklet.engine; | |||
| import java.net.URL; | |||
| import org.apache.avalon.Loggable; | |||
| import org.apache.avalon.camelot.Deployer; | |||
| import org.apache.avalon.camelot.DeploymentException; | |||
| import org.apache.log.Logger; | |||
| @@ -18,13 +19,12 @@ import org.apache.log.Logger; | |||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| public interface TskDeployer | |||
| extends Deployer | |||
| extends Deployer, Loggable | |||
| { | |||
| void setLogger( Logger logger ); | |||
| void deployConverter( String name, String location, URL url ) | |||
| throws DeploymentException; | |||
| void deployTasklet( String name, String location, URL url ) | |||
| throws DeploymentException; | |||
| } | |||
| @@ -12,7 +12,6 @@ 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; | |||
| @@ -11,8 +11,9 @@ 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.avalon.camelot.DefaultLocator; | |||
| import org.apache.ant.convert.ConverterEngine; | |||
| import org.apache.ant.convert.DefaultConverterInfo; | |||
| import org.apache.ant.tasklet.AbstractTasklet; | |||
| import org.apache.ant.tasklet.engine.TaskletEngine; | |||
| import org.apache.avalon.ComponentManager; | |||
| @@ -106,12 +107,15 @@ public class RegisterConverter | |||
| else | |||
| { | |||
| final DefaultConverterInfo info = | |||
| new DefaultConverterInfo( m_sourceType, m_destinationType, m_classname, url ); | |||
| new DefaultConverterInfo( m_sourceType, m_destinationType ); | |||
| final DefaultLocator locator = new DefaultLocator( m_classname, url ); | |||
| try | |||
| { | |||
| m_engine.getConverterEngine(). | |||
| getConverterRegistry().register( m_classname, info ); | |||
| m_engine.getConverterEngine(). | |||
| getLocatorRegistry().register( m_classname, locator ); | |||
| } | |||
| catch( final RegistryException re ) | |||
| { | |||
| @@ -9,7 +9,7 @@ package org.apache.ant.tasks.core; | |||
| import java.net.URL; | |||
| import org.apache.ant.AntException; | |||
| import org.apache.ant.tasklet.engine.DefaultTaskletInfo; | |||
| import org.apache.avalon.camelot.DefaultLocator; | |||
| import org.apache.avalon.camelot.DeploymentException; | |||
| import org.apache.avalon.camelot.RegistryException; | |||
| @@ -36,8 +36,8 @@ public class RegisterTasklet | |||
| } | |||
| else | |||
| { | |||
| final DefaultTaskletInfo info = new DefaultTaskletInfo( classname, url ); | |||
| m_engine.getTaskletRegistry().register( name, info ); | |||
| final DefaultLocator locator = new DefaultLocator( classname, url ); | |||
| m_engine.getLocatorRegistry().register( name, locator ); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,11 +0,0 @@ | |||
| # TASK-LIB/taskdefs.properties | |||
| echo=org.apache.ant.tasks.core.Echo | |||
| prim-test=org.apache.ant.tasks.core.PrimitiveTypesTest | |||
| sub-elements-test=org.apache.ant.tasks.core.SubElementTest | |||
| conf-test=org.apache.ant.tasks.core.ConfigurationTest | |||
| content-test=org.apache.ant.tasks.core.ContentTest | |||
| property=org.apache.ant.tasks.core.Property | |||
| 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 | |||
| @@ -0,0 +1,36 @@ | |||
| <tasklib> | |||
| <task name="echo" classname="org.apache.ant.tasks.core.Echo" /> | |||
| <task name="prim-test" classname="org.apache.ant.tasks.core.PrimitiveTypesTest" /> | |||
| <task name="sub-elements-test" classname="org.apache.ant.tasks.core.SubElementTest" /> | |||
| <task name="conf-test" classname="org.apache.ant.tasks.core.ConfigurationTest" /> | |||
| <task name="content-test" classname="org.apache.ant.tasks.core.ContentTest" /> | |||
| <task name="property" classname="org.apache.ant.tasks.core.Property" /> | |||
| <task name="register-tasklet" classname="org.apache.ant.tasks.core.RegisterTasklet" /> | |||
| <task name="register-converter" classname="org.apache.ant.tasks.core.RegisterConverter" /> | |||
| <task name="ant-call" classname="org.apache.ant.tasks.core.AntCall" /> | |||
| <converter classname="org.apache.ant.convert.core.StringToLongConverter" | |||
| source="java.lang.String" | |||
| destination="java.lang.Long" /> | |||
| <converter classname="org.apache.ant.convert.core.StringToIntegerConverter" | |||
| source="java.lang.String" | |||
| destination="java.lang.Integer" /> | |||
| <converter classname="org.apache.ant.convert.core.StringToShortConverter" | |||
| source="java.lang.String" | |||
| destination="java.lang.Short" /> | |||
| <converter classname="org.apache.ant.convert.core.StringToByteConverter" | |||
| source="java.lang.String" | |||
| destination="java.lang.Byte" /> | |||
| <converter classname="org.apache.ant.convert.core.StringToDoubleConverter" | |||
| source="java.lang.String" | |||
| destination="java.lang.Double" /> | |||
| <converter classname="org.apache.ant.convert.core.StringToFloatConverter" | |||
| source="java.lang.String" | |||
| destination="java.lang.Float" /> | |||
| <converter classname="org.apache.ant.convert.core.StringToClassConverter" | |||
| source="java.lang.String" | |||
| destination="java.lang.Class" /> | |||
| <converter classname="org.apache.ant.convert.core.StringToURLConverter" | |||
| source="java.lang.String" | |||
| destination="java.net.URL" /> | |||
| </tasklib> | |||