git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269087 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -10,7 +10,6 @@ package org.apache.ant.modules.core; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
| import java.net.URL; | import java.net.URL; | ||||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||||
| import org.apache.avalon.framework.component.ComponentException; | import org.apache.avalon.framework.component.ComponentException; | ||||
| import org.apache.avalon.framework.component.ComponentManager; | import org.apache.avalon.framework.component.ComponentManager; | ||||
| import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
| @@ -18,6 +17,7 @@ import org.apache.myrmidon.api.AbstractTask; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.components.converter.ConverterInfo; | import org.apache.myrmidon.components.converter.ConverterInfo; | ||||
| import org.apache.myrmidon.components.converter.ConverterRegistry; | import org.apache.myrmidon.components.converter.ConverterRegistry; | ||||
| import org.apache.myrmidon.components.deployer.DeploymentException; | |||||
| import org.apache.myrmidon.components.deployer.TskDeployer; | import org.apache.myrmidon.components.deployer.TskDeployer; | ||||
| import org.apache.myrmidon.components.type.DefaultComponentFactory; | import org.apache.myrmidon.components.type.DefaultComponentFactory; | ||||
| import org.apache.myrmidon.components.type.TypeManager; | import org.apache.myrmidon.components.type.TypeManager; | ||||
| @@ -8,8 +8,9 @@ | |||||
| package org.apache.ant.modules.core; | package org.apache.ant.modules.core; | ||||
| import java.net.URL; | import java.net.URL; | ||||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||||
| import org.apache.myrmidon.api.DataType; | |||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.components.deployer.DeploymentException; | |||||
| import org.apache.myrmidon.components.type.DefaultComponentFactory; | import org.apache.myrmidon.components.type.DefaultComponentFactory; | ||||
| /** | /** | ||||
| @@ -35,10 +36,10 @@ public class RegisterDataType | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| final DefaultComponentFactory factory = | |||||
| final DefaultComponentFactory factory = | |||||
| new DefaultComponentFactory( new URL[] { url } ); | new DefaultComponentFactory( new URL[] { url } ); | ||||
| factory.addNameClassMapping( name, className ); | factory.addNameClassMapping( name, className ); | ||||
| try { getTypeManager().registerType( "org.apache.ant.tasklet.DataType", name, factory ); } | |||||
| try { getTypeManager().registerType( DataType.ROLE, name, factory ); } | |||||
| catch( final Exception e ) | catch( final Exception e ) | ||||
| { | { | ||||
| throw new TaskException( "Failed registering " + name + " from " + url, e ); | throw new TaskException( "Failed registering " + name + " from " + url, e ); | ||||
| @@ -8,9 +8,9 @@ | |||||
| package org.apache.ant.modules.core; | package org.apache.ant.modules.core; | ||||
| import java.net.URL; | import java.net.URL; | ||||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||||
| import org.apache.myrmidon.api.Task; | import org.apache.myrmidon.api.Task; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.components.deployer.DeploymentException; | |||||
| import org.apache.myrmidon.components.type.DefaultComponentFactory; | import org.apache.myrmidon.components.type.DefaultComponentFactory; | ||||
| /** | /** | ||||
| @@ -36,7 +36,7 @@ public class RegisterTasklet | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| final DefaultComponentFactory factory = | |||||
| final DefaultComponentFactory factory = | |||||
| new DefaultComponentFactory( new URL[] { url } ); | new DefaultComponentFactory( new URL[] { url } ); | ||||
| factory.addNameClassMapping( name, className ); | factory.addNameClassMapping( name, className ); | ||||
| try { getTypeManager().registerType( Task.ROLE, name, factory ); } | try { getTypeManager().registerType( Task.ROLE, name, factory ); } | ||||
| @@ -10,12 +10,12 @@ package org.apache.ant.modules.core; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
| import java.net.URL; | import java.net.URL; | ||||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||||
| import org.apache.avalon.framework.component.ComponentException; | import org.apache.avalon.framework.component.ComponentException; | ||||
| import org.apache.avalon.framework.component.ComponentManager; | import org.apache.avalon.framework.component.ComponentManager; | ||||
| import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.api.AbstractTask; | import org.apache.myrmidon.api.AbstractTask; | ||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.components.deployer.DeploymentException; | |||||
| import org.apache.myrmidon.components.deployer.TskDeployer; | import org.apache.myrmidon.components.deployer.TskDeployer; | ||||
| /** | /** | ||||
| @@ -12,7 +12,7 @@ package org.apache.myrmidon; | |||||
| * | * | ||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| interface Constants | |||||
| public interface Constants | |||||
| { | { | ||||
| //Constants to indicate the build of Ant/Myrmidon | //Constants to indicate the build of Ant/Myrmidon | ||||
| String BUILD_DATE = "@@DATE@@"; | String BUILD_DATE = "@@DATE@@"; | ||||
| @@ -9,28 +9,23 @@ package org.apache.myrmidon.components.deployer; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.io.InputStream; | |||||
| import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
| import java.net.URL; | import java.net.URL; | ||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.zip.ZipEntry; | import java.util.zip.ZipEntry; | ||||
| import java.util.zip.ZipException; | import java.util.zip.ZipException; | ||||
| import java.util.zip.ZipFile; | import java.util.zip.ZipFile; | ||||
| import org.apache.avalon.framework.camelot.AbstractDeployer; | |||||
| import org.apache.avalon.framework.camelot.DefaultLocator; | |||||
| import org.apache.avalon.framework.camelot.DeployerUtil; | |||||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||||
| import org.apache.avalon.framework.camelot.Loader; | |||||
| import org.apache.avalon.framework.camelot.Registry; | |||||
| import org.apache.avalon.framework.camelot.RegistryException; | |||||
| import org.apache.avalon.framework.component.Component; | import org.apache.avalon.framework.component.Component; | ||||
| import org.apache.avalon.framework.component.ComponentException; | import org.apache.avalon.framework.component.ComponentException; | ||||
| import org.apache.avalon.framework.component.ComponentManager; | import org.apache.avalon.framework.component.ComponentManager; | ||||
| import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
| import org.apache.avalon.framework.configuration.Configuration; | import org.apache.avalon.framework.configuration.Configuration; | ||||
| import org.apache.avalon.framework.configuration.ConfigurationException; | import org.apache.avalon.framework.configuration.ConfigurationException; | ||||
| import org.apache.avalon.framework.logger.Loggable; | |||||
| import org.apache.log.Logger; | |||||
| import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; | |||||
| import org.apache.avalon.framework.logger.AbstractLoggable; | |||||
| import org.apache.myrmidon.api.Task; | import org.apache.myrmidon.api.Task; | ||||
| import org.apache.myrmidon.api.DataType; | |||||
| import org.apache.myrmidon.components.converter.ConverterInfo; | import org.apache.myrmidon.components.converter.ConverterInfo; | ||||
| import org.apache.myrmidon.components.converter.ConverterRegistry; | import org.apache.myrmidon.components.converter.ConverterRegistry; | ||||
| import org.apache.myrmidon.components.executor.Executor; | import org.apache.myrmidon.components.executor.Executor; | ||||
| @@ -38,6 +33,7 @@ import org.apache.myrmidon.components.type.ComponentFactory; | |||||
| import org.apache.myrmidon.components.type.DefaultComponentFactory; | import org.apache.myrmidon.components.type.DefaultComponentFactory; | ||||
| import org.apache.myrmidon.components.type.TypeManager; | import org.apache.myrmidon.components.type.TypeManager; | ||||
| import org.apache.myrmidon.converter.Converter; | import org.apache.myrmidon.converter.Converter; | ||||
| import org.xml.sax.SAXException; | |||||
| /** | /** | ||||
| * This class deploys a .tsk file into a registry. | * This class deploys a .tsk file into a registry. | ||||
| @@ -45,21 +41,22 @@ import org.apache.myrmidon.converter.Converter; | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public class DefaultTskDeployer | public class DefaultTskDeployer | ||||
| extends AbstractDeployer | |||||
| implements Composable, TskDeployer, Loggable | |||||
| extends AbstractLoggable | |||||
| implements Composable, TskDeployer | |||||
| { | { | ||||
| private final static String TSKDEF_FILE = "TASK-LIB/taskdefs.xml"; | private final static String TSKDEF_FILE = "TASK-LIB/taskdefs.xml"; | ||||
| private ConverterRegistry m_converterInfoRegistry; | |||||
| private TypeManager m_typeManager; | |||||
| private DefaultConfigurationBuilder m_configurationBuilder; | |||||
| private ConverterRegistry m_converterInfoRegistry; | |||||
| private TypeManager m_typeManager; | |||||
| /** | /** | ||||
| * Default constructor. | * Default constructor. | ||||
| */ | */ | ||||
| public DefaultTskDeployer() | public DefaultTskDeployer() | ||||
| { | { | ||||
| m_autoUndeploy = true; | |||||
| m_type = "Task"; | |||||
| //m_autoUndeploy = true; | |||||
| //m_type = "Task"; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -75,6 +72,16 @@ public class DefaultTskDeployer | |||||
| m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE ); | ||||
| } | } | ||||
| public void deploy( final String location, final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| //checkDeployment( location, url ); | |||||
| final File file = getFileFor( url ); | |||||
| getLogger().info( "Deploying AntLib file (" + file + ") as " + location ); | |||||
| deployFromFile( location, file ); | |||||
| } | |||||
| /** | /** | ||||
| * Deploy a file. | * Deploy a file. | ||||
| * Eventually this should be cached for performance reasons. | * Eventually this should be cached for performance reasons. | ||||
| @@ -86,7 +93,7 @@ public class DefaultTskDeployer | |||||
| protected void deployFromFile( final String location, final File file ) | protected void deployFromFile( final String location, final File file ) | ||||
| throws DeploymentException | throws DeploymentException | ||||
| { | { | ||||
| final ZipFile zipFile = DeployerUtil.getZipFileFor( file ); | |||||
| final ZipFile zipFile = getZipFileFor( file ); | |||||
| URL url = null; | URL url = null; | ||||
| @@ -109,7 +116,7 @@ public class DefaultTskDeployer | |||||
| private void loadResources( final ZipFile zipFile, final String location, final URL url ) | private void loadResources( final ZipFile zipFile, final String location, final URL url ) | ||||
| throws DeploymentException | throws DeploymentException | ||||
| { | { | ||||
| final Configuration taskdefs = DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE ); | |||||
| final Configuration taskdefs = loadConfiguration( zipFile, TSKDEF_FILE ); | |||||
| final DefaultComponentFactory factory = | final DefaultComponentFactory factory = | ||||
| new DefaultComponentFactory( new URL[] { url } ); | new DefaultComponentFactory( new URL[] { url } ); | ||||
| @@ -147,9 +154,9 @@ public class DefaultTskDeployer | |||||
| public void deployConverter( String name, String location, URL url ) | public void deployConverter( String name, String location, URL url ) | ||||
| throws DeploymentException | throws DeploymentException | ||||
| { | { | ||||
| checkDeployment( location, url ); | |||||
| final ZipFile zipFile = DeployerUtil.getZipFileFor( getFileFor( url ) ); | |||||
| final Configuration taskdefs = DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE ); | |||||
| //checkDeployment( location, url ); | |||||
| final ZipFile zipFile = getZipFileFor( getFileFor( url ) ); | |||||
| final Configuration taskdefs = loadConfiguration( zipFile, TSKDEF_FILE ); | |||||
| try | try | ||||
| { | { | ||||
| @@ -178,10 +185,10 @@ public class DefaultTskDeployer | |||||
| public void deployDataType( final String name, final String location, final URL url ) | public void deployDataType( final String name, final String location, final URL url ) | ||||
| throws DeploymentException | throws DeploymentException | ||||
| { | { | ||||
| checkDeployment( location, url ); | |||||
| final ZipFile zipFile = DeployerUtil.getZipFileFor( getFileFor( url ) ); | |||||
| //checkDeployment( location, url ); | |||||
| final ZipFile zipFile = getZipFileFor( getFileFor( url ) ); | |||||
| final Configuration datatypedefs = | final Configuration datatypedefs = | ||||
| DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE ); | |||||
| loadConfiguration( zipFile, TSKDEF_FILE ); | |||||
| try | try | ||||
| { | { | ||||
| @@ -210,9 +217,9 @@ public class DefaultTskDeployer | |||||
| public void deployTask( final String name, final String location, final URL url ) | public void deployTask( final String name, final String location, final URL url ) | ||||
| throws DeploymentException | throws DeploymentException | ||||
| { | { | ||||
| checkDeployment( location, url ); | |||||
| final ZipFile zipFile = DeployerUtil.getZipFileFor( getFileFor( url ) ); | |||||
| final Configuration taskdefs = DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE ); | |||||
| //checkDeployment( location, url ); | |||||
| final ZipFile zipFile = getZipFileFor( getFileFor( url ) ); | |||||
| final Configuration taskdefs = loadConfiguration( zipFile, TSKDEF_FILE ); | |||||
| try | try | ||||
| { | { | ||||
| @@ -238,6 +245,106 @@ public class DefaultTskDeployer | |||||
| } | } | ||||
| } | } | ||||
| private DefaultConfigurationBuilder getBuilder() | |||||
| { | |||||
| if( null == m_configurationBuilder ) | |||||
| { | |||||
| m_configurationBuilder = new DefaultConfigurationBuilder(); | |||||
| } | |||||
| return m_configurationBuilder; | |||||
| } | |||||
| /** | |||||
| * Retrieve zip file for file. | |||||
| * | |||||
| * @param file the file | |||||
| * @return the zipFile | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| private 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 ); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Utility method to load configuration from zip. | |||||
| * | |||||
| * @param zipFile the zip file | |||||
| * @param filename the property filename | |||||
| * @return the Configuration | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| private Configuration loadConfiguration( final ZipFile zipFile, final String filename ) | |||||
| throws DeploymentException | |||||
| { | |||||
| return buildConfiguration( loadResourceStream( zipFile, filename ) ); | |||||
| } | |||||
| /** | |||||
| * Build a configuration tree based on input stream. | |||||
| * | |||||
| * @param input the InputStream | |||||
| * @return the Configuration tree | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| private Configuration buildConfiguration( final InputStream input ) | |||||
| throws DeploymentException | |||||
| { | |||||
| try { return getBuilder().build( input ); } | |||||
| catch( final SAXException se ) | |||||
| { | |||||
| throw new DeploymentException( "Malformed configuration data", se ); | |||||
| } | |||||
| catch( final ConfigurationException ce ) | |||||
| { | |||||
| throw new DeploymentException( "Error building configuration", ce ); | |||||
| } | |||||
| catch( final IOException ioe ) | |||||
| { | |||||
| throw new DeploymentException( "Error reading configuration", ioe ); | |||||
| } | |||||
| } | |||||
| private File getFileFor( final URL url ) | |||||
| throws DeploymentException | |||||
| { | |||||
| File file = null; | |||||
| if( url.getProtocol().equals( "file" ) ) | |||||
| { | |||||
| file = new File( url.getFile() ); | |||||
| } | |||||
| else | |||||
| { | |||||
| throw new DeploymentException( "Currently unable to deploy non-local " + | |||||
| "archives (" + url + ")" ); | |||||
| } | |||||
| file = file.getAbsoluteFile(); | |||||
| if( !file.exists() ) | |||||
| { | |||||
| throw new DeploymentException( "Could not find application archive at " + | |||||
| file ); | |||||
| } | |||||
| if( file.isDirectory() ) | |||||
| { | |||||
| throw new DeploymentException( "Could not find application archive at " + | |||||
| file + " as it is a directory." ); | |||||
| } | |||||
| return file; | |||||
| } | |||||
| private void handleConverter( final Configuration converter, | private void handleConverter( final Configuration converter, | ||||
| final URL url, | final URL url, | ||||
| final DefaultComponentFactory factory ) | final DefaultComponentFactory factory ) | ||||
| @@ -281,8 +388,37 @@ public class DefaultTskDeployer | |||||
| final String className = datatype.getAttribute( "classname" ); | final String className = datatype.getAttribute( "classname" ); | ||||
| factory.addNameClassMapping( name, className ); | factory.addNameClassMapping( name, className ); | ||||
| m_typeManager.registerType( "org.apache.ant.tasklet.DataType", name, factory ); | |||||
| m_typeManager.registerType( DataType.ROLE, name, factory ); | |||||
| getLogger().debug( "Registered datatype " + name + " as " + className ); | getLogger().debug( "Registered datatype " + name + " as " + className ); | ||||
| } | } | ||||
| /** | |||||
| * Load a resource from a zip file. | |||||
| * | |||||
| * @param zipFile the ZipFile | |||||
| * @param filename the filename | |||||
| * @return the InputStream | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| private InputStream loadResourceStream( 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() ); | |||||
| } | |||||
| try { return zipFile.getInputStream( entry ); } | |||||
| catch( final IOException ioe ) | |||||
| { | |||||
| throw new DeploymentException( "Error reading " + filename + | |||||
| " from " + zipFile.getName(), | |||||
| ioe ); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,40 @@ | |||||
| /* | |||||
| * 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.myrmidon.components.deployer; | |||||
| import org.apache.avalon.framework.CascadingException; | |||||
| /** | |||||
| * Exception to indicate error deploying. | |||||
| * | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | |||||
| */ | |||||
| public final class DeploymentException | |||||
| extends CascadingException | |||||
| { | |||||
| /** | |||||
| * Construct a new <code>DeploymentException</code> instance. | |||||
| * | |||||
| * @param message The detail message for this exception. | |||||
| */ | |||||
| public DeploymentException( final String message ) | |||||
| { | |||||
| this( message, null ); | |||||
| } | |||||
| /** | |||||
| * Construct a new <code>DeploymentException</code> instance. | |||||
| * | |||||
| * @param message The detail message for this exception. | |||||
| * @param throwable the root cause of the exception | |||||
| */ | |||||
| public DeploymentException( final String message, final Throwable throwable ) | |||||
| { | |||||
| super( message, throwable ); | |||||
| } | |||||
| } | |||||
| @@ -8,8 +8,7 @@ | |||||
| package org.apache.myrmidon.components.deployer; | package org.apache.myrmidon.components.deployer; | ||||
| import java.net.URL; | import java.net.URL; | ||||
| import org.apache.avalon.framework.camelot.Deployer; | |||||
| import org.apache.avalon.framework.camelot.DeploymentException; | |||||
| import org.apache.avalon.framework.component.Component; | |||||
| /** | /** | ||||
| * This class deploys a .tsk file into a registry. | * This class deploys a .tsk file into a registry. | ||||
| @@ -17,10 +16,20 @@ import org.apache.avalon.framework.camelot.DeploymentException; | |||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public interface TskDeployer | public interface TskDeployer | ||||
| extends Deployer | |||||
| extends Component | |||||
| { | { | ||||
| String ROLE = "org.apache.myrmidon.components.deployer.TskDeployer"; | String ROLE = "org.apache.myrmidon.components.deployer.TskDeployer"; | ||||
| /** | |||||
| * Deploy a resource indicate by url to location. | |||||
| * | |||||
| * @param location the location to deploy to | |||||
| * @param url the url of deployment | |||||
| * @exception DeploymentException if an error occurs | |||||
| */ | |||||
| void deploy( String location, URL url ) | |||||
| throws DeploymentException; | |||||
| void deployConverter( String name, String location, URL url ) | void deployConverter( String name, String location, URL url ) | ||||
| throws DeploymentException; | throws DeploymentException; | ||||
| @@ -7,15 +7,13 @@ | |||||
| */ | */ | ||||
| package org.apache.myrmidon.components.embeddor; | package org.apache.myrmidon.components.embeddor; | ||||
| import org.apache.avalon.excalibur.io.ExtensionFileFilter; | |||||
| import java.io.File; | import java.io.File; | ||||
| import java.io.FilenameFilter; | |||||
| import org.apache.myrmidon.components.converter.MasterConverter; | import org.apache.myrmidon.components.converter.MasterConverter; | ||||
| import org.apache.myrmidon.components.converter.ConverterRegistry; | import org.apache.myrmidon.components.converter.ConverterRegistry; | ||||
| import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
| import org.apache.avalon.framework.activity.Initializable; | import org.apache.avalon.framework.activity.Initializable; | ||||
| import org.apache.avalon.framework.camelot.CamelotUtil; | |||||
| import org.apache.avalon.framework.camelot.DefaultFactory; | |||||
| import org.apache.avalon.framework.camelot.Deployer; | |||||
| import org.apache.avalon.framework.camelot.Factory; | |||||
| import org.apache.avalon.framework.component.Component; | import org.apache.avalon.framework.component.Component; | ||||
| import org.apache.avalon.framework.component.Composable; | import org.apache.avalon.framework.component.Composable; | ||||
| import org.apache.avalon.framework.component.DefaultComponentManager; | import org.apache.avalon.framework.component.DefaultComponentManager; | ||||
| @@ -26,6 +24,7 @@ import org.apache.myrmidon.api.JavaVersion; | |||||
| import org.apache.myrmidon.components.builder.ProjectBuilder; | import org.apache.myrmidon.components.builder.ProjectBuilder; | ||||
| import org.apache.myrmidon.components.configurer.Configurer; | import org.apache.myrmidon.components.configurer.Configurer; | ||||
| import org.apache.myrmidon.components.deployer.TskDeployer; | import org.apache.myrmidon.components.deployer.TskDeployer; | ||||
| import org.apache.myrmidon.components.deployer.DeploymentException; | |||||
| import org.apache.myrmidon.components.executor.Executor; | import org.apache.myrmidon.components.executor.Executor; | ||||
| import org.apache.myrmidon.components.manager.ProjectManager; | import org.apache.myrmidon.components.manager.ProjectManager; | ||||
| import org.apache.myrmidon.components.type.TypeManager; | import org.apache.myrmidon.components.type.TypeManager; | ||||
| @@ -119,7 +118,8 @@ public class MyrmidonEmbeddor | |||||
| public void start() | public void start() | ||||
| throws Exception | throws Exception | ||||
| { | { | ||||
| CamelotUtil.deployFromDirectory( m_deployer, m_taskLibDir, ".tsk" ); | |||||
| final ExtensionFileFilter filter = new ExtensionFileFilter( ".tsk" ); | |||||
| deployFromDirectory( m_deployer, m_taskLibDir, filter ); | |||||
| } | } | ||||
| public void stop() | public void stop() | ||||
| @@ -228,7 +228,7 @@ public class MyrmidonEmbeddor | |||||
| component = getParameter( ConverterRegistry.ROLE ); | component = getParameter( ConverterRegistry.ROLE ); | ||||
| m_converterRegistry = (ConverterRegistry)createComponent( component, ConverterRegistry.class ); | m_converterRegistry = (ConverterRegistry)createComponent( component, ConverterRegistry.class ); | ||||
| component = getParameter( "org.apache.myrmidon.components.converter.MasterConverter" ); | |||||
| component = getParameter( MasterConverter.ROLE ); | |||||
| m_converter = (MasterConverter)createComponent( component, MasterConverter.class ); | m_converter = (MasterConverter)createComponent( component, MasterConverter.class ); | ||||
| component = getParameter( Configurer.ROLE ); | component = getParameter( Configurer.ROLE ); | ||||
| @@ -422,4 +422,47 @@ public class MyrmidonEmbeddor | |||||
| " (" + component + ")" ); | " (" + component + ")" ); | ||||
| } | } | ||||
| } | } | ||||
| private void deployFromDirectory( final TskDeployer deployer, | |||||
| final File directory, | |||||
| final FilenameFilter filter ) | |||||
| throws DeploymentException | |||||
| { | |||||
| final File[] files = directory.listFiles( filter ); | |||||
| if( null != files ) | |||||
| { | |||||
| deployFiles( deployer, files ); | |||||
| } | |||||
| } | |||||
| private void deployFiles( final TskDeployer deployer, final File[] files ) | |||||
| throws DeploymentException | |||||
| { | |||||
| for( int i = 0; i < files.length; i++ ) | |||||
| { | |||||
| final String filename = files[ i ].getName(); | |||||
| int index = filename.lastIndexOf( '.' ); | |||||
| if( -1 == index ) index = filename.length(); | |||||
| final String name = filename.substring( 0, index ); | |||||
| try | |||||
| { | |||||
| final File file = files[ i ].getCanonicalFile(); | |||||
| deployer.deploy( name, file.toURL() ); | |||||
| } | |||||
| catch( final DeploymentException de ) | |||||
| { | |||||
| throw de; | |||||
| } | |||||
| catch( final Exception e ) | |||||
| { | |||||
| throw new DeploymentException( "Unable to retrieve filename for file " + | |||||
| files[ i ], e ); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -5,7 +5,7 @@ | |||||
| * version 1.1, a copy of which has been included with this distribution in | * version 1.1, a copy of which has been included with this distribution in | ||||
| * the LICENSE file. | * the LICENSE file. | ||||
| */ | */ | ||||
| package org.apache.myrmidon; | |||||
| package org.apache.myrmidon.frontends; | |||||
| import java.io.BufferedReader; | import java.io.BufferedReader; | ||||
| import java.io.File; | import java.io.File; | ||||
| @@ -32,6 +32,7 @@ import org.apache.log.Hierarchy; | |||||
| import org.apache.log.LogTarget; | import org.apache.log.LogTarget; | ||||
| import org.apache.log.Logger; | import org.apache.log.Logger; | ||||
| import org.apache.log.Priority; | import org.apache.log.Priority; | ||||
| import org.apache.myrmidon.Constants; | |||||
| import org.apache.myrmidon.api.DefaultTaskContext; | import org.apache.myrmidon.api.DefaultTaskContext; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| @@ -50,7 +51,7 @@ import org.apache.myrmidon.listeners.ProjectListener; | |||||
| * | * | ||||
| * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | * @author <a href="mailto:donaldp@apache.org">Peter Donald</a> | ||||
| */ | */ | ||||
| public class Main | |||||
| public class CLIMain | |||||
| extends AbstractLoggable | extends AbstractLoggable | ||||
| { | { | ||||
| //defines for the Command Line options | //defines for the Command Line options | ||||
| @@ -98,7 +99,7 @@ public class Main | |||||
| */ | */ | ||||
| public static void main( final String[] args ) | public static void main( final String[] args ) | ||||
| { | { | ||||
| final Main main = new Main(); | |||||
| final CLIMain main = new CLIMain(); | |||||
| try { main.execute( args ); } | try { main.execute( args ); } | ||||
| catch( final Throwable throwable ) | catch( final Throwable throwable ) | ||||
| @@ -225,8 +226,8 @@ public class Main | |||||
| case VERSION_OPT: System.out.println( Constants.BUILD_DESCRIPTION ); return false; | case VERSION_OPT: System.out.println( Constants.BUILD_DESCRIPTION ); return false; | ||||
| case HOME_DIR_OPT: m_parameters.setParameter( "myrmidon.home", option.getArgument() ); break; | case HOME_DIR_OPT: m_parameters.setParameter( "myrmidon.home", option.getArgument() ); break; | ||||
| case TASKLIB_DIR_OPT: | |||||
| m_parameters.setParameter( "myrmidon.lib.path", option.getArgument() ); | |||||
| case TASKLIB_DIR_OPT: | |||||
| m_parameters.setParameter( "myrmidon.lib.path", option.getArgument() ); | |||||
| break; | break; | ||||
| case LOG_LEVEL_OPT: m_parameters.setParameter( "log.level", option.getArgument() ); break; | case LOG_LEVEL_OPT: m_parameters.setParameter( "log.level", option.getArgument() ); break; | ||||
| @@ -323,7 +324,7 @@ public class Main | |||||
| { | { | ||||
| //actually do the build ... | //actually do the build ... | ||||
| final TaskContext context = new DefaultTaskContext(); | final TaskContext context = new DefaultTaskContext(); | ||||
| //Add CLI m_defines | //Add CLI m_defines | ||||
| addToContext( context, m_defines ); | addToContext( context, m_defines ); | ||||
| @@ -45,7 +45,7 @@ public final class Main | |||||
| final URLClassLoader classLoader = new URLClassLoader( urls ); | final URLClassLoader classLoader = new URLClassLoader( urls ); | ||||
| //load class and retrieve appropriate main method. | //load class and retrieve appropriate main method. | ||||
| final Class clazz = classLoader.loadClass( "org.apache.myrmidon.Main" ); | |||||
| final Class clazz = classLoader.loadClass( "org.apache.myrmidon.frontends.CLIMain" ); | |||||
| final Method method = clazz.getMethod( "main", new Class[] { args.getClass() } ); | final Method method = clazz.getMethod( "main", new Class[] { args.getClass() } ); | ||||
| Thread.currentThread().setContextClassLoader( classLoader ); | Thread.currentThread().setContextClassLoader( classLoader ); | ||||
| @@ -1,4 +1,3 @@ | |||||
| Manifest-Version: 1.0 | Manifest-Version: 1.0 | ||||
| Main-Class: org.apache.myrmidon.Main | |||||
| Class-Path: avalonapi.jar | |||||
| Main-Class: org.apache.myrmidon.frontends.CLIMain | |||||
| Created-By: Apache Ant Project | Created-By: Apache Ant Project | ||||