git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268599 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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 <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 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; | |||
| } | |||
| @@ -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. | |||
| @@ -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 <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 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -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 <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| 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 ); | |||
| } | |||
| } | |||
| } | |||
| @@ -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 <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||
| */ | |||
| 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 ); | |||
| } | |||
| } | |||
| } | |||
| @@ -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 <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 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 ); | |||
| } | |||
| } | |||
| } | |||