diff --git a/proposal/myrmidon/src/java/org/apache/ant/modules/core/AbstractResourceRegisterer.java b/proposal/myrmidon/src/java/org/apache/ant/modules/core/AbstractResourceRegisterer.java new file mode 100644 index 000000000..a42b4ee30 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/ant/modules/core/AbstractResourceRegisterer.java @@ -0,0 +1,101 @@ +/* + * 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.modules.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.ComponentManagerException; +import org.apache.avalon.Composer; +import org.apache.avalon.camelot.RegistryException; + +/** + * Method to register a single tasklet. + * + * @author Peter Donald + */ +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 ComponentManagerException + { + 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 = getContext().resolveFile( 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; +} diff --git a/proposal/myrmidon/src/java/org/apache/ant/modules/core/README b/proposal/myrmidon/src/java/org/apache/ant/modules/core/README new file mode 100644 index 000000000..e45d2fbfb --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/ant/modules/core/README @@ -0,0 +1,2 @@ +This package is required for operation. No task within this directory is allowed to +require parameters other than strings for converter. \ No newline at end of file diff --git a/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java new file mode 100644 index 000000000..9cfbe8254 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java @@ -0,0 +1,140 @@ +/* + * 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.modules.core; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import org.apache.ant.AntException; +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; +import org.apache.avalon.ComponentManagerException; +import org.apache.avalon.Composer; +import org.apache.avalon.camelot.DefaultLocator; +import org.apache.avalon.camelot.DeploymentException; +import org.apache.avalon.camelot.RegistryException; + +/** + * Method to register a single converter. + * + * @author Peter Donald + */ +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 ComponentManagerException + { + 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 ); + final DefaultLocator locator = new DefaultLocator( m_classname, url ); + + try + { + m_engine.getConverterEngine().getInfoRegistry().register( m_classname, info ); + m_engine.getConverterEngine().getRegistry().register( m_classname, locator ); + } + catch( final RegistryException re ) + { + throw new AntException( "Error registering resource", re ); + } + } + } + + protected URL getURL( final String libName ) + { + if( null != libName ) + { + final File lib = getContext().resolveFile( libName ); + try { return lib.toURL(); } + catch( final MalformedURLException mue ) + { + throw new AntException( "Malformed task-lib parameter " + m_lib, mue ); + } + } + else + { + return null; + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java new file mode 100644 index 000000000..dcf325bea --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java @@ -0,0 +1,43 @@ +/* + * 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.modules.core; + +import java.net.URL; +import org.apache.ant.AntException; +import org.apache.avalon.camelot.DefaultLocator; +import org.apache.avalon.camelot.DeploymentException; +import org.apache.avalon.camelot.RegistryException; + +/** + * Method to register a single datatype. + * + * @author Peter Donald + */ +public class RegisterDataType + extends AbstractResourceRegisterer +{ + protected void registerResource( final String name, + final String classname, + final URL url ) + throws AntException, RegistryException + { + if( null == classname ) + { + try { m_engine.getTskDeployer().deployDataType( name, url.toString(), url ); } + catch( final DeploymentException de ) + { + throw new AntException( "Failed deploying " + name + " from " + url, de ); + } + } + else + { + final DefaultLocator locator = new DefaultLocator( classname, url ); + m_engine.getDataTypeEngine().getRegistry().register( name, locator ); + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java new file mode 100644 index 000000000..3f276fddd --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java @@ -0,0 +1,43 @@ +/* + * 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.modules.core; + +import java.net.URL; +import org.apache.ant.AntException; +import org.apache.avalon.camelot.DefaultLocator; +import org.apache.avalon.camelot.DeploymentException; +import org.apache.avalon.camelot.RegistryException; + +/** + * Method to register a single tasklet. + * + * @author Peter Donald + */ +public class RegisterTasklet + extends AbstractResourceRegisterer +{ + protected void registerResource( final String name, + final String classname, + final URL url ) + throws AntException, RegistryException + { + if( null == classname ) + { + try { m_engine.getTskDeployer().deployTasklet( name, url.toString(), url ); } + catch( final DeploymentException de ) + { + throw new AntException( "Failed deploying " + name + " from " + url, de ); + } + } + else + { + final DefaultLocator locator = new DefaultLocator( classname, url ); + m_engine.getRegistry().register( name, locator ); + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklib.java b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklib.java new file mode 100644 index 000000000..0fedc8da9 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklib.java @@ -0,0 +1,71 @@ +/* + * 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.modules.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.ComponentManagerException; +import org.apache.avalon.Composer; +import org.apache.avalon.camelot.DeploymentException; + +/** + * Method to register a tasklib. + * + * @author Peter Donald + */ +public class RegisterTasklib + extends AbstractTasklet + implements Composer +{ + protected String m_lib; + protected TaskletEngine m_engine; + + public void compose( final ComponentManager componentManager ) + throws ComponentManagerException + { + 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 = getContext().resolveFile( 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 ); + } + } +}