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/java/org/apache/myrmidon/components/embeddor MyrmidonEmbeddor.java
Date Tue, 29 May 2001 09:56:03 GMT
donaldp     01/05/29 02:56:02

  Modified:    proposal/myrmidon/src/java/org/apache/ant Main.java
               proposal/myrmidon/src/java/org/apache/ant/modules/core
                        AbstractResourceRegisterer.java
                        RegisterConverter.java RegisterTasklib.java
               proposal/myrmidon/src/java/org/apache/myrmidon/api
                        AbstractTask.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        MyrmidonEmbeddor.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultTskDeployer.java TskDeployer.java
  Removed:     proposal/myrmidon/src/java/org/apache/ant/tasklet/engine
                        DefaultTskDeployer.java TskDeployer.java
  Log:
  Moved TskDeployer into separate directory.
  
  Revision  Changes    Path
  1.23      +0 -5      jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/Main.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Main.java	2001/05/29 09:12:14	1.22
  +++ Main.java	2001/05/29 09:55:50	1.23
  @@ -26,11 +26,6 @@
   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.activity.Disposable;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.camelot.CamelotUtil;
  -import org.apache.avalon.framework.camelot.Deployer;
  -import org.apache.avalon.framework.camelot.DeploymentException;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.log.Hierarchy;
  
  
  
  1.6       +11 -11    jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/AbstractResourceRegisterer.java
  
  Index: AbstractResourceRegisterer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/ant/modules/core/AbstractResourceRegisterer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractResourceRegisterer.java	2001/05/29 06:00:47	1.5
  +++ AbstractResourceRegisterer.java	2001/05/29 09:55:54	1.6
  @@ -11,21 +11,21 @@
   import java.net.MalformedURLException;
   import java.net.URL;
   import org.apache.ant.AntException;
  -import org.apache.myrmidon.api.AbstractTask;
  -import org.apache.ant.tasklet.engine.TskDeployer;
  -import org.apache.myrmidon.components.executor.Executor;
   import org.apache.ant.tasklet.engine.DataTypeEngine;
  -import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.camelot.RegistryException;
   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.camelot.RegistryException;
  +import org.apache.myrmidon.api.AbstractTask;
  +import org.apache.myrmidon.components.deployer.TskDeployer;
  +import org.apache.myrmidon.components.executor.Executor;
   
   /**
    * Method to register a single tasklet.
    *
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
  -public abstract class AbstractResourceRegisterer 
  +public abstract class AbstractResourceRegisterer
       extends AbstractTask
       implements Composable
   {
  @@ -43,7 +43,7 @@
               lookup( "org.apache.myrmidon.components.executor.Executor" );
   
           m_tskDeployer = (TskDeployer)componentManager.
  -            lookup( "org.apache.ant.tasklet.engine.TskDeployer" );
  +            lookup( "org.apache.myrmidon.components.deployer.TskDeployer" );
   
           m_dataTypeEngine = (DataTypeEngine)componentManager.
               lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" );
  @@ -53,12 +53,12 @@
       {
           m_lib = lib;
       }
  -    
  +
       public void setName( final String name )
       {
           m_name = name;
       }
  -    
  +
       public void setClassname( final String classname )
       {
           m_classname = classname;
  @@ -73,10 +73,10 @@
           }
           else if( null == m_lib && null == m_classname )
           {
  -            throw new AntException( "Must specify classname if you don't specify " + 
  +            throw new AntException( "Must specify classname if you don't specify " +
                                       "lib parameter" );
           }
  -        
  +
           final URL url = getURL( m_lib );
   
           try
  
  
  
  1.6       +2 -2      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RegisterConverter.java	2001/05/28 12:57:13	1.5
  +++ RegisterConverter.java	2001/05/29 09:55:54	1.6
  @@ -14,7 +14,7 @@
   import org.apache.ant.convert.engine.ConverterEngine;
   import org.apache.ant.convert.engine.DefaultConverterInfo;
   import org.apache.myrmidon.api.AbstractTask;
  -import org.apache.ant.tasklet.engine.TskDeployer;
  +import org.apache.myrmidon.components.deployer.TskDeployer;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.Composable;
  @@ -42,7 +42,7 @@
           throws ComponentException
       {
           m_tskDeployer = (TskDeployer)componentManager.
  -            lookup( "org.apache.ant.tasklet.engine.TskDeployer" );
  +            lookup( "org.apache.myrmidon.components.deployer.TskDeployer" );
   
           m_converterEngine = (ConverterEngine)componentManager.
               lookup( "org.apache.ant.convert.engine.ConverterEngine" );
  
  
  
  1.5       +7 -7      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RegisterTasklib.java	2001/05/28 12:57:13	1.4
  +++ RegisterTasklib.java	2001/05/29 09:55:54	1.5
  @@ -11,25 +11,25 @@
   import java.net.MalformedURLException;
   import java.net.URL;
   import org.apache.ant.AntException;
  -import org.apache.myrmidon.api.AbstractTask;
  -import org.apache.ant.tasklet.engine.TskDeployer;
  -import org.apache.avalon.framework.component.ComponentManager;
  +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.avalon.framework.camelot.DeploymentException;
  +import org.apache.myrmidon.api.AbstractTask;
  +import org.apache.myrmidon.components.deployer.TskDeployer;
   
   /**
    * Method to register a tasklib.
    *
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
  -public class RegisterTasklib 
  +public class RegisterTasklib
       extends AbstractTask
       implements Composable
   {
       protected String              m_lib;
       protected TskDeployer         m_tskDeployer;
  -    
  +
       public void compose( final ComponentManager componentManager )
           throws ComponentException
       {
  @@ -49,7 +49,7 @@
           {
               throw new AntException( "Must specify lib parameter" );
           }
  -        
  +
           URL url = null;
   
           final File lib = getContext().resolveFile( m_lib );
  
  
  
  1.2       +11 -1     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java
  
  Index: AbstractTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractTask.java	2001/05/28 07:36:53	1.1
  +++ AbstractTask.java	2001/05/29 09:55:58	1.2
  @@ -7,7 +7,6 @@
    */
   package org.apache.myrmidon.api;
   
  -import org.apache.ant.AntException;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.context.Context;
  @@ -45,6 +44,17 @@
           throws Exception
       {
       }
  +
  +    /**
  +     * Execute task. 
  +     * This method is called to perform actual work associated with task.
  +     * It is called after Task has been Configured and Initialized and before
  +     * beig Disposed (If task implements appropriate interfaces).
  +     *
  +     * @exception Exception if an error occurs
  +     */
  +    public abstract void execute()
  +        throws Exception;
   
       /**
        * This will be called after execute() method.
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultTskDeployer.java
  
  Index: DefaultTskDeployer.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 java.io.File;
  import java.io.IOException;
  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.ant.tasklet.engine.DataTypeEngine;
  import org.apache.ant.convert.engine.ConverterEngine;
  import org.apache.ant.convert.engine.ConverterRegistry;
  import org.apache.ant.convert.engine.DefaultConverterInfo;
  import org.apache.avalon.framework.camelot.AbstractDeployer;
  import org.apache.avalon.framework.camelot.DefaultLocator;
  import org.apache.avalon.framework.camelot.DefaultRegistry;
  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.myrmidon.components.executor.Executor;
  
  /**
   * This class deploys a .tsk file into a registry.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultTskDeployer
      extends AbstractDeployer
      implements Composable, TskDeployer, Loggable
  {
      private final static String   TSKDEF_FILE     = "TASK-LIB/taskdefs.xml";
  
      private Registry              m_dataTypeRegistry;
      private Registry              m_taskRegistry;
      private Registry              m_converterRegistry;
      private ConverterRegistry     m_converterInfoRegistry;
  
      /**
       * Default constructor.
       */
      public DefaultTskDeployer()
      {
          super();
          m_autoUndeploy = true;
          m_type = "Task";
      }
  
      /**
       * Retrieve relevent services needed to deploy.
       *
       * @param componentManager the ComponentManager
       * @exception ComponentException if an error occurs
       */
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          //UGLY HACK alert !!!
          final Executor executor = (Executor)componentManager.
              lookup( "org.apache.myrmidon.components.executor.Executor" );
          m_taskRegistry = executor.getRegistry();
  
          final ConverterEngine converterEngine = (ConverterEngine)componentManager.
              lookup( "org.apache.ant.convert.engine.ConverterEngine" );
  
          m_converterInfoRegistry = converterEngine.getInfoRegistry();
          m_converterRegistry = converterEngine.getRegistry();
  
          final DataTypeEngine dataTypeEngine = (DataTypeEngine)componentManager.
              lookup( "org.apache.ant.tasklet.engine.DataTypeEngine" );
  
          m_dataTypeRegistry = dataTypeEngine.getRegistry();
      }
  
      /**
       * Deploy a file.
       * Eventually this should be cached for performance reasons.
       *
       * @param location the location
       * @param file the file
       * @exception DeploymentException if an error occurs
       */
      protected void deployFromFile( final String location, final File file )
          throws DeploymentException
      {
          final ZipFile zipFile = DeployerUtil.getZipFileFor( file );
  
          URL url = null;
  
          try
          {
              try { url = file.toURL(); }
              catch( final MalformedURLException mue )
              {
                  throw new DeploymentException( "Unable to form url", mue );
              }
              loadResources( zipFile, location, url );
          }
          finally
          {
              try { zipFile.close(); }
              catch( final IOException ioe ) {}
          }
      }
  
      private void loadResources( final ZipFile zipFile, final String location, final URL
url )
          throws DeploymentException
      {
          final Configuration taskdefs = DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE
);
  
          try
          {
              final Configuration[] tasks = taskdefs.getChildren( "task" );
              for( int i = 0; i < tasks.length; i++ )
              {
                  handleTask( tasks[ i ], url );
              }
  
              final Configuration[] converters = taskdefs.getChildren( "converter" );
              for( int i = 0; i < converters.length; i++ )
              {
                  handleConverter( converters[ i ], url );
              }
  
              final Configuration[] datatypes = taskdefs.getChildren( "datatype" );
              for( int i = 0; i < datatypes.length; i++ )
              {
                  handleDataType( datatypes[ i ], url );
              }
          }
          catch( final ConfigurationException ce )
          {
              throw new DeploymentException( "Malformed taskdefs.xml", ce );
          }
      }
  
      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
);
  
          try
          {
              final Configuration[] converters = taskdefs.getChildren( "converter" );
              for( int i = 0; i < converters.length; i++ )
              {
                  if( converters[ i ].getAttribute( "classname" ).equals( name ) )
                  {
                      handleConverter( converters[ i ], url );
                      break;
                  }
              }
          }
          catch( final ConfigurationException ce )
          {
              throw new DeploymentException( "Malformed taskdefs.xml", ce );
          }
      }
  
      public void deployDataType( final String name, final String location, final URL url
)
          throws DeploymentException
      {
          checkDeployment( location, url );
          final ZipFile zipFile = DeployerUtil.getZipFileFor( getFileFor( url ) );
          final Configuration datatypedefs =
              DeployerUtil.loadConfiguration( zipFile, TSKDEF_FILE );
  
          try
          {
              final Configuration[] datatypes = datatypedefs.getChildren( "datatype" );
              for( int i = 0; i < datatypes.length; i++ )
              {
                  if( datatypes[ i ].getAttribute( "name" ).equals( name ) )
                  {
                      handleDataType( datatypes[ i ], url );
                      break;
                  }
              }
          }
          catch( final ConfigurationException ce )
          {
              throw new DeploymentException( "Malformed taskdefs.xml", ce );
          }
      }
  
      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
);
  
          try
          {
              final Configuration[] tasks = taskdefs.getChildren( "task" );
              for( int i = 0; i < tasks.length; i++ )
              {
                  if( tasks[ i ].getAttribute( "name" ).equals( name ) )
                  {
                      handleTask( tasks[ i ], url );
                      break;
                  }
              }
          }
          catch( final ConfigurationException ce )
          {
              throw new DeploymentException( "Malformed taskdefs.xml", ce );
          }
      }
  
      private void handleConverter( final Configuration converter, final URL url )
          throws DeploymentException, ConfigurationException
      {
          final String name = converter.getAttribute( "classname" );
          final String source = converter.getAttribute( "source" );
          final String destination = converter.getAttribute( "destination" );
  
          final DefaultConverterInfo info = new DefaultConverterInfo( source, destination
);
  
          try { m_converterInfoRegistry.register( name, info ); }
          catch( final RegistryException re )
          {
              throw new DeploymentException( "Error registering converter info " +
                                             name + " due to " + re,
                                             re );
          }
  
          final DefaultLocator locator = new DefaultLocator( name, url );
  
          try { m_converterRegistry.register( name, locator ); }
          catch( final RegistryException re )
          {
              throw new DeploymentException( "Error registering converter locator " +
                                             name + " due to " + re,
                                             re );
          }
  
          getLogger().debug( "Registered converter " + name + " that converts from " +
                             source + " to " + destination );
      }
  
      private void handleTask( final Configuration task, final URL url )
          throws DeploymentException, ConfigurationException
      {
          final String name = task.getAttribute( "name" );
          final String classname = task.getAttribute( "classname" );
  
          final DefaultLocator info = new DefaultLocator( classname, url );
  
          try { m_taskRegistry.register( name, info ); }
          catch( final RegistryException re )
          {
              throw new DeploymentException( "Error registering " + name + " due to " + re,
                                             re );
          }
  
          getLogger().debug( "Registered task " + name + " as " + classname );
      }
  
      private void handleDataType( final Configuration datatype, final URL url )
          throws DeploymentException, ConfigurationException
      {
          final String name = datatype.getAttribute( "name" );
          final String classname = datatype.getAttribute( "classname" );
  
          final DefaultLocator info = new DefaultLocator( classname, url );
  
          try { m_dataTypeRegistry.register( name, info ); }
          catch( final RegistryException re )
          {
              throw new DeploymentException( "Error registering " + name + " due to " + re,
                                             re );
          }
  
          getLogger().debug( "Registered datatype " + name + " as " + classname );
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/TskDeployer.java
  
  Index: TskDeployer.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 java.net.URL;
  import org.apache.avalon.framework.camelot.Deployer;
  import org.apache.avalon.framework.camelot.DeploymentException;
  import org.apache.avalon.framework.logger.Loggable;
  import org.apache.log.Logger;
  
  /**
   * This class deploys a .tsk file into a registry.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface TskDeployer
      extends Deployer
  {
      void deployConverter( String name, String location, URL url )
          throws DeploymentException;
  
      void deployDataType( String name, String location, URL url )
          throws DeploymentException;
  
      void deployTask( String name, String location, URL url )
          throws DeploymentException;
  }
  
  
  
  
  1.6       +10 -5     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MyrmidonEmbeddor.java	2001/05/29 09:13:33	1.5
  +++ MyrmidonEmbeddor.java	2001/05/29 09:56:01	1.6
  @@ -11,7 +11,6 @@
   import org.apache.ant.AntException;
   import org.apache.ant.convert.engine.ConverterEngine;
   import org.apache.ant.tasklet.engine.DataTypeEngine;
  -import org.apache.ant.tasklet.engine.TskDeployer;
   import org.apache.avalon.excalibur.io.FileUtil;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.camelot.CamelotUtil;
  @@ -29,6 +28,7 @@
   import org.apache.myrmidon.components.configurer.Configurer;
   import org.apache.myrmidon.components.executor.Executor;
   import org.apache.myrmidon.components.manager.ProjectManager;
  +import org.apache.myrmidon.components.deployer.TskDeployer;
   
   /**
    * Default implementation of Ant runtime.
  @@ -178,7 +178,7 @@
           defaults.setParameter( "ant.comp.builder",
                                  "org.apache.myrmidon.components.builder.DefaultProjectBuilder"
);
           defaults.setParameter( "ant.comp.deployer",
  -                               "org.apache.ant.tasklet.engine.DefaultTskDeployer" );
  +                               "org.apache.myrmidon.components.deployer.DefaultTskDeployer"
);
           defaults.setParameter( "ant.comp.configurer",
                                  "org.apache.myrmidon.components.configurer.DefaultConfigurer"
);
   
  @@ -194,15 +194,20 @@
       {
           final DefaultComponentManager componentManager = new DefaultComponentManager();
   
  -        componentManager.put( "org.apache.myrmidon.components.manager.ProjectManager",
m_projectEngine );
           componentManager.put( "org.apache.ant.convert.engine.ConverterEngine",
                                 m_converterEngine );
           componentManager.put( "org.apache.ant.convert.Converter", m_converterEngine );
           componentManager.put( "org.apache.ant.tasklet.engine.DataTypeEngine", m_dataTypeEngine
);
  -        componentManager.put( "org.apache.myrmidon.components.builder.ProjectBuilder",
m_builder );
  -        componentManager.put( "org.apache.ant.tasklet.engine.TskDeployer", m_deployer );
           componentManager.put( "org.apache.avalon.framework.camelot.Factory", m_factory
);
   
  +        //Following components required when Myrmidon is used as build tool
  +        componentManager.put( "org.apache.myrmidon.components.manager.ProjectManager",
m_projectEngine );
  +        componentManager.put( "org.apache.myrmidon.components.builder.ProjectBuilder",
m_builder );
  +
  +        //Following components required when Myrmidon allows user deployment of tasks etal.
  +        componentManager.put( "org.apache.myrmidon.components.deployer.TskDeployer", m_deployer
);
  +
  +        //Following components required when allowing Container tasks
           componentManager.put( "org.apache.myrmidon.components.configurer.Configurer", m_configurer
);
           componentManager.put( "org.apache.myrmidon.components.executor.Executor", m_executor
);
   
  
  
  

Mime
View raw message