ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/manifest myrmidon-manifest.mf
Date Sun, 03 Jun 2001 05:03:17 GMT
donaldp     01/06/02 22:03:17

  Modified:    proposal/myrmidon/lib avalon-framework.jar
               proposal/myrmidon/src/java/org/apache/ant/modules/core
                        RegisterConverter.java RegisterDataType.java
                        RegisterTasklet.java RegisterTasklib.java
               proposal/myrmidon/src/java/org/apache/myrmidon
                        Constants.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultTskDeployer.java TskDeployer.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        MyrmidonEmbeddor.java
               proposal/myrmidon/src/java/org/apache/myrmidon/launcher
                        Main.java
               proposal/myrmidon/src/manifest myrmidon-manifest.mf
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DeploymentException.java
               proposal/myrmidon/src/java/org/apache/myrmidon/frontends
                        CLIMain.java
  Removed:     proposal/myrmidon/lib avalon-container.jar
               proposal/myrmidon/src/java/org/apache/myrmidon Main.java
  Log:
  Update myrmidon to remove dependencies on camelot part of Avalon (which is still alpha and
not released).
  
  Revision  Changes    Path
  1.2       +130 -108  jakarta-ant/proposal/myrmidon/lib/avalon-framework.jar
  
  	<<Binary file>>
  
  
  1.11      +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java
  
  Index: RegisterConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterConverter.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RegisterConverter.java	2001/06/02 14:28:41	1.10
  +++ RegisterConverter.java	2001/06/03 05:03:14	1.11
  @@ -10,7 +10,6 @@
   import java.io.File;
   import java.net.MalformedURLException;
   import java.net.URL;
  -import org.apache.avalon.framework.camelot.DeploymentException;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  @@ -18,6 +17,7 @@
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.components.converter.ConverterInfo;
   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.type.DefaultComponentFactory;
   import org.apache.myrmidon.components.type.TypeManager;
  
  
  
  1.7       +4 -3      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java
  
  Index: RegisterDataType.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterDataType.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- RegisterDataType.java	2001/06/02 08:26:53	1.6
  +++ RegisterDataType.java	2001/06/03 05:03:14	1.7
  @@ -8,8 +8,9 @@
   package org.apache.ant.modules.core;
   
   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.components.deployer.DeploymentException;
   import org.apache.myrmidon.components.type.DefaultComponentFactory;
   
   /**
  @@ -35,10 +36,10 @@
           }
           else
           {
  -            final DefaultComponentFactory factory = 
  +            final DefaultComponentFactory factory =
                   new DefaultComponentFactory( new URL[] { url } );
               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 )
               {
                   throw new TaskException( "Failed registering " + name + " from " + url,
e );
  
  
  
  1.8       +2 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java
  
  Index: RegisterTasklet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklet.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RegisterTasklet.java	2001/06/02 08:26:53	1.7
  +++ RegisterTasklet.java	2001/06/03 05:03:14	1.8
  @@ -8,9 +8,9 @@
   package org.apache.ant.modules.core;
   
   import java.net.URL;
  -import org.apache.avalon.framework.camelot.DeploymentException;
   import org.apache.myrmidon.api.Task;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.components.deployer.DeploymentException;
   import org.apache.myrmidon.components.type.DefaultComponentFactory;
   
   /**
  @@ -36,7 +36,7 @@
           }
           else
           {
  -            final DefaultComponentFactory factory = 
  +            final DefaultComponentFactory factory =
                   new DefaultComponentFactory( new URL[] { url } );
               factory.addNameClassMapping( name, className );
               try { getTypeManager().registerType( Task.ROLE, name, factory ); }
  
  
  
  1.9       +2 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklib.java
  
  Index: RegisterTasklib.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/RegisterTasklib.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RegisterTasklib.java	2001/05/31 17:19:46	1.8
  +++ RegisterTasklib.java	2001/06/03 05:03:14	1.9
  @@ -10,12 +10,12 @@
   import java.io.File;
   import java.net.MalformedURLException;
   import java.net.URL;
  -import org.apache.avalon.framework.camelot.DeploymentException;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
  -import org.apache.myrmidon.api.TaskException;
   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;
   
   /**
  
  
  
  1.3       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/Constants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Constants.java	2001/05/29 15:24:11	1.2
  +++ Constants.java	2001/06/03 05:03:15	1.3
  @@ -12,7 +12,7 @@
    * 
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
  -interface Constants
  +public interface Constants
   {
       //Constants to indicate the build of Ant/Myrmidon
       String  BUILD_DATE         = "@@DATE@@";
  
  
  
  1.8       +163 -27   jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java
  
  Index: DefaultTskDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultTskDeployer.java	2001/06/02 14:28:42	1.7
  +++ DefaultTskDeployer.java	2001/06/03 05:03:15	1.8
  @@ -9,28 +9,23 @@
   
   import java.io.File;
   import java.io.IOException;
  +import java.io.InputStream;
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.Iterator;
   import java.util.zip.ZipEntry;
   import java.util.zip.ZipException;
   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.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.configuration.Configuration;
   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.DataType;
   import org.apache.myrmidon.components.converter.ConverterInfo;
   import org.apache.myrmidon.components.converter.ConverterRegistry;
   import org.apache.myrmidon.components.executor.Executor;
  @@ -38,6 +33,7 @@
   import org.apache.myrmidon.components.type.DefaultComponentFactory;
   import org.apache.myrmidon.components.type.TypeManager;
   import org.apache.myrmidon.converter.Converter;
  +import org.xml.sax.SAXException;
   
   /**
    * This class deploys a .tsk file into a registry.
  @@ -45,21 +41,22 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   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 ConverterRegistry     m_converterInfoRegistry;
  -    private TypeManager           m_typeManager;
  +    private DefaultConfigurationBuilder  m_configurationBuilder;
  +    private ConverterRegistry            m_converterInfoRegistry;
  +    private TypeManager                  m_typeManager;
   
       /**
        * Default constructor.
        */
       public DefaultTskDeployer()
       {
  -        m_autoUndeploy = true;
  -        m_type = "Task";
  +        //m_autoUndeploy = true;
  +        //m_type = "Task";
       }
   
       /**
  @@ -75,6 +72,16 @@
           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.
        * Eventually this should be cached for performance reasons.
  @@ -86,7 +93,7 @@
       protected void deployFromFile( final String location, final File file )
           throws DeploymentException
       {
  -        final ZipFile zipFile = DeployerUtil.getZipFileFor( file );
  +        final ZipFile zipFile = getZipFileFor( file );
   
           URL url = null;
   
  @@ -109,7 +116,7 @@
       private void loadResources( final ZipFile zipFile, final String location, final URL
url )
           throws DeploymentException
       {
  -        final Configuration taskdefs = DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE
);
  +        final Configuration taskdefs = loadConfiguration( zipFile, TSKDEF_FILE );
   
           final DefaultComponentFactory factory =
               new DefaultComponentFactory( new URL[] { url } );
  @@ -147,9 +154,9 @@
       public void deployConverter( String name, String location, URL url )
           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
           {
  @@ -178,10 +185,10 @@
       public void deployDataType( final String name, final String location, final URL url
)
           throws DeploymentException
       {
  -        checkDeployment( location, url );
  -        final ZipFile zipFile = DeployerUtil.getZipFileFor( getFileFor( url ) );
  +        //checkDeployment( location, url );
  +        final ZipFile zipFile = getZipFileFor( getFileFor( url ) );
           final Configuration datatypedefs =
  -            DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE );
  +            loadConfiguration( zipFile, TSKDEF_FILE );
   
           try
           {
  @@ -210,9 +217,9 @@
       public void deployTask( final String name, final String location, final URL url )
           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
           {
  @@ -238,6 +245,106 @@
           }
       }
   
  +    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,
                                     final URL url,
                                     final DefaultComponentFactory factory )
  @@ -281,8 +388,37 @@
           final String className = datatype.getAttribute( "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 );
  +    }
  +
  +
  +    /**
  +     * 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 );
  +        }
       }
   }
  
  
  
  1.3       +12 -3     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/TskDeployer.java
  
  Index: TskDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/TskDeployer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TskDeployer.java	2001/05/31 17:20:03	1.2
  +++ TskDeployer.java	2001/06/03 05:03:16	1.3
  @@ -8,8 +8,7 @@
   package org.apache.myrmidon.components.deployer;
   
   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.
  @@ -17,9 +16,19 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public interface TskDeployer
  -    extends Deployer
  +    extends Component
   {
       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 )
           throws DeploymentException;
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DeploymentException.java
  
  Index: DeploymentException.java
  ===================================================================
  /*
   * 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 );
      }
  }
  
  
  
  1.16      +49 -6     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java
  
  Index: MyrmidonEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- MyrmidonEmbeddor.java	2001/06/02 14:28:43	1.15
  +++ MyrmidonEmbeddor.java	2001/06/03 05:03:16	1.16
  @@ -7,15 +7,13 @@
    */
   package org.apache.myrmidon.components.embeddor;
   
  +import org.apache.avalon.excalibur.io.ExtensionFileFilter;
   import java.io.File;
  +import java.io.FilenameFilter;
   import org.apache.myrmidon.components.converter.MasterConverter;
   import org.apache.myrmidon.components.converter.ConverterRegistry;
   import org.apache.avalon.excalibur.io.FileUtil;
   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.Composable;
   import org.apache.avalon.framework.component.DefaultComponentManager;
  @@ -26,6 +24,7 @@
   import org.apache.myrmidon.components.builder.ProjectBuilder;
   import org.apache.myrmidon.components.configurer.Configurer;
   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.manager.ProjectManager;
   import org.apache.myrmidon.components.type.TypeManager;
  @@ -119,7 +118,8 @@
       public void start()
           throws Exception
       {
  -        CamelotUtil.deployFromDirectory( m_deployer, m_taskLibDir, ".tsk" );
  +        final ExtensionFileFilter filter = new ExtensionFileFilter( ".tsk" );
  +        deployFromDirectory( m_deployer, m_taskLibDir, filter );
       }
   
       public void stop()
  @@ -228,7 +228,7 @@
           component = getParameter( ConverterRegistry.ROLE );
           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
);
   
           component = getParameter( Configurer.ROLE );
  @@ -420,6 +420,49 @@
           {
               throw new Exception( "Could not find the class for " + clazz +
                                    " (" + 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 );
  +            }
           }
       }
   }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java
  
  Index: CLIMain.java
  ===================================================================
  /*
   * 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.frontends;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import org.apache.avalon.excalibur.cli.CLArgsParser;
  import org.apache.avalon.excalibur.cli.CLOption;
  import org.apache.avalon.excalibur.cli.CLOptionDescriptor;
  import org.apache.avalon.excalibur.cli.CLUtil;
  import org.apache.avalon.excalibur.io.ExtensionFileFilter;
  import org.apache.avalon.framework.ExceptionUtil;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.log.Hierarchy;
  import org.apache.log.LogTarget;
  import org.apache.log.Logger;
  import org.apache.log.Priority;
  import org.apache.myrmidon.Constants;
  import org.apache.myrmidon.api.DefaultTaskContext;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.components.builder.ProjectBuilder;
  import org.apache.myrmidon.components.embeddor.Embeddor;
  import org.apache.myrmidon.components.embeddor.MyrmidonEmbeddor;
  import org.apache.myrmidon.components.manager.LogTargetToListenerAdapter;
  import org.apache.myrmidon.components.manager.ProjectManager;
  import org.apache.myrmidon.components.model.Project;
  import org.apache.myrmidon.listeners.ProjectListener;
  
  /**
   * The class to kick the tires and light the fires.
   * Starts myrmidon, loads ProjectBuilder, builds project then uses ProjectManager
   * to run project.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class CLIMain
      extends AbstractLoggable
  {
      //defines for the Command Line options
      private static final int       HELP_OPT                  = 'h';
      private static final int       QUIET_OPT                 = 'q';
      private static final int       VERBOSE_OPT               = 'v';
      private static final int       FILE_OPT                  = 'f';
      private static final int       LOG_LEVEL_OPT             = 'l';
      private static final int       DEFINE_OPT                = 'D';
      private static final int       VERSION_OPT               = 1;
      private static final int       LISTENER_OPT              = 2;
      private static final int       TASKLIB_DIR_OPT           = 5;
      private static final int       INCREMENTAL_OPT           = 6;
      private static final int       HOME_DIR_OPT              = 7;
  
      //incompatable options for info options
      private static final int[]     INFO_OPT_INCOMPAT         = new int[]
      {
          HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT,
          LOG_LEVEL_OPT, VERSION_OPT, LISTENER_OPT,
          DEFINE_OPT //TASKLIB_DIR_OPT, HOME_DIR_OPT
      };
  
      //incompatable options for other logging options
      private static final int[]     LOG_OPT_INCOMPAT          = new int[]
      {
          QUIET_OPT, VERBOSE_OPT, LOG_LEVEL_OPT
      };
  
      private ProjectListener      m_listener;
  
      ///Parameters for run of myrmidon
      private Parameters           m_parameters  = new Parameters();
  
      ///List of targets supplied on command line to execute
      private ArrayList            m_targets     = new ArrayList();
  
      ///List of user supplied defines
      private HashMap              m_defines     = new HashMap();
  
      /**
       * Main entry point called to run standard Myrmidon.
       *
       * @param args the args
       */
      public static void main( final String[] args )
      {
          final CLIMain main = new CLIMain();
  
          try { main.execute( args ); }
          catch( final Throwable throwable )
          {
              System.err.println( "Error: " + ExceptionUtil.printStackTrace( throwable ) );
              System.exit( -1 );
          }
  
          System.exit( 0 );
      }
  
      /**
       * Display usage report.
       *
       */
      private void usage( final CLOptionDescriptor[] options )
      {
          System.out.println( "java " + getClass().getName() + " [options]" );
          System.out.println( "\tAvailable options:");
          System.out.println( CLUtil.describeOptions( options ) );
      }
  
      /**
       * Initialise the options for command line parser.
       */
      private CLOptionDescriptor[] createCLOptions()
      {
          //TODO: localise
          final CLOptionDescriptor[] options = new CLOptionDescriptor[ 11 ];
  
          options[0] =
              new CLOptionDescriptor( "help",
                                      CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                      HELP_OPT,
                                      "display this help message",
                                      INFO_OPT_INCOMPAT );
  
          options[1] =
              new CLOptionDescriptor( "file",
                                      CLOptionDescriptor.ARGUMENT_REQUIRED,
                                      FILE_OPT,
                                      "the build file." );
  
          options[2] =
              new CLOptionDescriptor( "log-level",
                                      CLOptionDescriptor.ARGUMENT_REQUIRED,
                                      LOG_LEVEL_OPT,
                                      "the verbosity level at which to log messages. " +
                                      "(DEBUG|INFO|WARN|ERROR|FATAL_ERROR)",
                                      LOG_OPT_INCOMPAT );
  
          options[3] =
              new CLOptionDescriptor( "quiet",
                                      CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                      QUIET_OPT,
                                      "equivelent to --log-level=FATAL_ERROR",
                                      LOG_OPT_INCOMPAT );
  
          options[4] =
              new CLOptionDescriptor( "verbose",
                                      CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                      VERBOSE_OPT,
                                      "equivelent to --log-level=INFO",
                                      LOG_OPT_INCOMPAT );
  
          options[5] =
              new CLOptionDescriptor( "listener",
                                      CLOptionDescriptor.ARGUMENT_REQUIRED,
                                      LISTENER_OPT,
                                      "the listener for log events." );
  
          options[6] =
              new CLOptionDescriptor( "version",
                                      CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                      VERSION_OPT,
                                      "display version",
                                      INFO_OPT_INCOMPAT );
  
          options[7] =
              new CLOptionDescriptor( "task-lib-dir",
                                      CLOptionDescriptor.ARGUMENT_REQUIRED,
                                      TASKLIB_DIR_OPT,
                                      "the task lib directory to scan for .tsk files." );
          options[8] =
              new CLOptionDescriptor( "incremental",
                                      CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                      INCREMENTAL_OPT,
                                      "Run in incremental mode" );
          options[9] =
              new CLOptionDescriptor( "myrmidon-home",
                                      CLOptionDescriptor.ARGUMENT_REQUIRED,
                                      HOME_DIR_OPT,
                                      "Specify myrmidon home directory" );
          options[10] =
              new CLOptionDescriptor( "define",
                                      CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
                                      DEFINE_OPT,
                                      "Define a variable (ie -Dfoo=var)",
                                      new int[ 0 ] );
          return options;
      }
  
      private boolean parseCommandLineOptions( final String[] args )
      {
          final CLOptionDescriptor[] options = createCLOptions();
          final CLArgsParser parser = new CLArgsParser( args, options );
  
          if( null != parser.getErrorString() )
          {
              System.err.println( "Error: " + parser.getErrorString() );
              return false;
          }
  
          final List clOptions = parser.getArguments();
          final int size = clOptions.size();
  
          for( int i = 0; i < size; i++ )
          {
              final CLOption option = (CLOption)clOptions.get( i );
  
              switch( option.getId() )
              {
              case HELP_OPT: usage( options ); 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 TASKLIB_DIR_OPT:
                  m_parameters.setParameter( "myrmidon.lib.path", option.getArgument() );
                  break;
  
              case LOG_LEVEL_OPT: m_parameters.setParameter( "log.level", option.getArgument()
); break;
              case VERBOSE_OPT: m_parameters.setParameter( "log.level", "INFO" ); break;
              case QUIET_OPT: m_parameters.setParameter( "log.level", "ERROR" ); break;
  
              case INCREMENTAL_OPT: m_parameters.setParameter( "incremental", "true" ); break;
  
              case FILE_OPT: m_parameters.setParameter( "filename", option.getArgument() );
break;
              case LISTENER_OPT: m_parameters.setParameter( "listener", option.getArgument()
); break;
  
              case DEFINE_OPT:
                  m_defines.put( option.getArgument( 0 ), option.getArgument( 1 ) );
                  break;
  
              case 0: m_targets.add( option.getArgument() ); break;
              }
          }
  
          return true;
      }
  
      private void setupDefaultParameters()
      {
          //System property set up by launcher
          m_parameters.setParameter( "myrmidon.home", System.getProperty( "myrmidon.home",
"." ) );
  
          m_parameters.setParameter( "filename", "build.ant" );
          m_parameters.setParameter( "log.level", "WARN" );
          m_parameters.setParameter( "listener", "org.apache.myrmidon.listeners.DefaultProjectListener"
);
          m_parameters.setParameter( "incremental", "false" );
      }
  
      private void execute( final String[] args )
          throws Exception
      {
          setupDefaultParameters();
  
          if( !parseCommandLineOptions( args ) )
          {
              return;
          }
  
          //handle logging...
          final String logLevel = m_parameters.getParameter( "log.level", null );
          setLogger( createLogger( logLevel ) );
  
          final String home = m_parameters.getParameter( "myrmidon.home", null );
          final File homeDir = (new File( home )).getAbsoluteFile();
          if( !homeDir.isDirectory() )
          {
              throw new Exception( "myrmidon-home (" + homeDir + ") is not a directory" );
          }
  
          final String filename = m_parameters.getParameter( "filename", null );
          final File buildFile = (new File( filename )).getCanonicalFile();
          if( !buildFile.isFile() )
          {
              throw new Exception( "File " + buildFile + " is not a file or doesn't exist"
);
          }
  
          //handle listener..
          final String listenerName = m_parameters.getParameter( "listener", null );
          final ProjectListener listener = createListener( listenerName );
  
          final LogTarget target = new LogTargetToListenerAdapter( listener );
          getLogger().setLogTargets( new LogTarget[] { target } );
  
          getLogger().warn( "Ant Build File: " + buildFile );
          getLogger().info( "Ant Home Directory: " + homeDir );
          //getLogger().info( "Ant Bin Directory: " + m_binDir );
          //getLogger().debug( "Ant Lib Directory: " + m_libDir );
          //getLogger().debug( "Ant Task Lib Directory: " + m_taskLibDir );
  
          final Embeddor embeddor = new MyrmidonEmbeddor();
          setupLogger( embeddor );
          embeddor.parameterize( m_parameters );
          embeddor.initialize();
          embeddor.start();
  
          final ProjectBuilder builder = embeddor.getProjectBuilder();
  
          //create the project
          final Project project = builder.build( buildFile );
  
          final ProjectManager manager = embeddor.getProjectManager();
          manager.addProjectListener( listener );
  
          BufferedReader reader = null;
  
          //loop over build if we are in incremental mode..
          final boolean incremental = m_parameters.getParameterAsBoolean( "incremental", false
);
          while( true )
          {
              //actually do the build ...
              final TaskContext context = new DefaultTaskContext();
  
              //Add CLI m_defines
              addToContext( context, m_defines );
  
              //Add system properties second so that they overide user-defined properties
              addToContext( context, System.getProperties() );
  
              context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory()
);
              context.setProperty( Project.PROJECT_FILE, buildFile );
              //context.setProperty( Project.PROJECT, project.getName() );
  
              doBuild( manager, project, context, m_targets );
  
              if( !incremental ) break;
  
              System.out.println( "Continue ? (Enter no to stop)" );
  
              if( null == reader )
              {
                  reader = new BufferedReader( new InputStreamReader( System.in ) );
              }
  
              String line = reader.readLine();
  
              if( line.equalsIgnoreCase( "no" ) ) break;
  
          }
  
          embeddor.stop();
          embeddor.dispose();
      }
  
      /**
       * Actually do the build.
       *
       * @param manager the manager
       * @param project the project
       * @param targets the targets to build as passed by CLI
       */
      private void doBuild( final ProjectManager manager,
                            final Project project,
                            final TaskContext context,
                            final ArrayList targets )
      {
          try
          {
              final int targetCount = targets.size();
  
              //if we didn't specify a target on CLI then choose default
              if( 0 == targetCount )
              {
                  manager.executeTarget( project, project.getDefaultTargetName(), context
);
              }
              else
              {
                  for( int i = 0; i < targetCount; i++ )
                  {
                      manager.executeTarget( project, (String)targets.get( i ), context );
                  }
              }
          }
          catch( final TaskException ae )
          {
              getLogger().error( "BUILD FAILED" );
              getLogger().error( "Reason:\n" + ExceptionUtil.printStackTrace( ae, 5, true
) );
          }
      }
  
      /**
       * Create Logger of appropriate log-level.
       *
       * @param logLevel the log-level
       * @return the logger
       * @exception Exception if an error occurs
       */
      private Logger createLogger( final String logLevel )
          throws Exception
      {
          final String logLevelCapitalized = logLevel.toUpperCase();
          final Priority priority = Priority.getPriorityForName( logLevelCapitalized );
  
          if( !priority.getName().equals( logLevelCapitalized ) )
          {
              throw new Exception( "Unknown log level - " + logLevel );
          }
  
          final Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor( "myrmidon" );
  
          logger.setPriority( priority );
  
          return logger;
      }
  
      /**
       * Setup project listener.
       *
       * @param listener the classname of project listener
       */
      private ProjectListener createListener( final String listener )
          throws Exception
      {
          try { return (ProjectListener)Class.forName( listener ).newInstance(); }
          catch( final Throwable t )
          {
              throw new Exception( "Error creating the listener " + listener +
                                   " due to " + ExceptionUtil.printStackTrace( t, 5, true
) );
          }
      }
  
      /**
       * Helper method to add values to a context
       *
       * @param context the context
       * @param map the map of names->values
       */
      private void addToContext( final TaskContext context, final Map map )
          throws Exception
      {
          final Iterator keys = map.keySet().iterator();
  
          while( keys.hasNext() )
          {
              final String key = (String)keys.next();
              final Object value = map.get( key );
              context.setProperty( key, value );
          }
      }
  }
  
  
  
  
  1.5       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/launcher/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/launcher/Main.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Main.java	2001/05/31 09:25:21	1.4
  +++ Main.java	2001/06/03 05:03:16	1.5
  @@ -45,7 +45,7 @@
               final URLClassLoader classLoader = new URLClassLoader( urls );
   
               //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()
} );
   
               Thread.currentThread().setContextClassLoader( classLoader );
  
  
  
  1.3       +1 -2      jakarta-ant/proposal/myrmidon/src/manifest/myrmidon-manifest.mf
  
  Index: myrmidon-manifest.mf
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/manifest/myrmidon-manifest.mf,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- myrmidon-manifest.mf	2001/05/29 10:47:58	1.2
  +++ myrmidon-manifest.mf	2001/06/03 05:03:17	1.3
  @@ -1,4 +1,3 @@
   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
  
  
  

Mime
View raw message