ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer DefaultDeployerTest.java TestConverter1.java TestType1.java
Date Sat, 02 Feb 2002 12:51:59 GMT
adammurdoch    02/02/02 04:51:59

  Modified:    proposal/myrmidon build.xml
               proposal/myrmidon/src/java/org/apache/antlib/runtime
                        ConverterDef.java Resources.properties TypeDef.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer
                        DefaultDeployer.java Deployment.java
                        Resources.properties
               proposal/myrmidon/src/java/org/apache/myrmidon/framework
                        AbstractTypeDef.java Resources.properties
               proposal/myrmidon/src/java/org/apache/myrmidon/frontends
                        CLIMain.java
               proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/deployer
                        TypeDeployer.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer
                        DefaultConfigurerTest.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/deployer
                        ConverterDefinition.java GeneralTypeDefinition.java
                        TypeDefinition.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components
                        ComponentTestBase.java
               proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer
                        DefaultDeployerTest.java TestConverter1.java
                        TestType1.java
  Log:
  * Added TypeDefinition and sub-classes, which are passed to TypeDeployer to
    explicitly deploy a type.  These replace the multi-arg deployX() methods.
  
  * ConverterDef now sub-classes AbstractTypeDef.
  
  * Changed AbstractTypeDef to use TypeDefinition objects, and to configure
    them using the configurer.  Removed all setX() methods from AbstractTypeDef
    and sub-classes.
  
  * Added some units tests for DefaultDeployer.
  
  * Moved component set-up from DefaultConfigurerTest -> super class.
  
  Revision  Changes    Path
  1.44      +4 -2      jakarta-ant/proposal/myrmidon/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- build.xml	2 Feb 2002 03:29:07 -0000	1.43
  +++ build.xml	2 Feb 2002 12:51:58 -0000	1.44
  @@ -480,7 +480,7 @@
       </zip>
   
       <junit printsummary="on"
  -           fork="false">
  +           fork="true">
         <formatter type="brief" usefile="false"/>
         <classpath refid="project.class.path"/>
         <classpath location="${test.classes}"/>
  @@ -492,7 +492,9 @@
         <sysproperty key="test.ftp.uri" value="ftp://${vfs.user}:${vfs.password}@${vfs.host}/home/${vfs.user}/vfs"/>
   
         <batchtest>
  -        <fileset dir="${test.classes}" includes="**/*Test.class">
  +        <fileset dir="${test.classes}">
  +          <include name="**/*Test.class" unless="single.test"/>
  +          <include name="**/${single.test}Test.class" if="single.test"/>
             <exclude name="**/SmbFileSystemTest.class" unless="test.smb"/>
             <exclude name="**/FtpFileSystemTest.class" unless="test.ftp"/>
           </fileset>
  
  
  
  1.7       +6 -70     jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/ConverterDef.java
  
  Index: ConverterDef.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/ConverterDef.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ConverterDef.java	1 Feb 2002 00:37:58 -0000	1.6
  +++ ConverterDef.java	2 Feb 2002 12:51:58 -0000	1.7
  @@ -7,13 +7,9 @@
    */
   package org.apache.antlib.runtime;
   
  -import java.io.File;
  -import org.apache.avalon.excalibur.i18n.ResourceManager;
  -import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.myrmidon.api.AbstractTask;
  -import org.apache.myrmidon.api.TaskException;
  -import org.apache.myrmidon.interfaces.deployer.Deployer;
  -import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
  +import org.apache.myrmidon.framework.AbstractTypeDef;
  +import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
  +import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   
   /**
    * Task to define a converter.
  @@ -21,71 +17,11 @@
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    */
   public class ConverterDef
  -    extends AbstractTask
  +    extends AbstractTypeDef
   {
  -    private final static Resources REZ =
  -        ResourceManager.getPackageResources( ConverterDef.class );
   
  -    private String m_sourceType;
  -    private String m_destinationType;
  -    private File m_lib;
  -    private String m_classname;
  -
  -    public void setLib( final File lib )
  -    {
  -        m_lib = lib;
  -    }
  -
  -    public void setClassname( final String classname )
  -    {
  -        m_classname = classname;
  -    }
  -
  -    public void setSourceType( final String sourceType )
  +    protected TypeDefinition createTypeDefinition()
       {
  -        m_sourceType = sourceType;
  -    }
  -
  -    public void setDestinationType( final String destinationType )
  -    {
  -        m_destinationType = destinationType;
  -    }
  -
  -    public void execute()
  -        throws TaskException
  -    {
  -        if( null == m_classname )
  -        {
  -            final String message = REZ.getString( "converterdef.no-classname.error" );
  -            throw new TaskException( message );
  -        }
  -        else if( null == m_sourceType )
  -        {
  -            final String message = REZ.getString( "converterdef.no-source.error" );
  -            throw new TaskException( message );
  -        }
  -        else if( null == m_destinationType )
  -        {
  -            final String message = REZ.getString( "converterdef.no-destination.error" );
  -            throw new TaskException( message );
  -        }
  -        else if( null == m_lib )
  -        {
  -            final String message = REZ.getString( "converterdef.no-lib.error" );
  -            throw new TaskException( message );
  -        }
  -
  -        try
  -        {
  -            // Locate the deployer, then deploy the converter
  -            final Deployer deployer = (Deployer)getService( Deployer.class );
  -            final TypeDeployer typeDeployer = deployer.createDeployer( m_lib );
  -            typeDeployer.deployConverter( m_classname, m_sourceType, m_destinationType );
  -        }
  -        catch( final Exception e )
  -        {
  -            final String message = REZ.getString( "converterdef.no-register.error", m_classname );
  -            throw new TaskException( message, e );
  -        }
  +        return new ConverterDefinition();
       }
   }
  
  
  
  1.3       +0 -6      jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Resources.properties	25 Jan 2002 11:27:21 -0000	1.2
  +++ Resources.properties	2 Feb 2002 12:51:58 -0000	1.3
  @@ -1,9 +1,3 @@
  -converterdef.no-classname.error=Must specify classname parameter.
  -converterdef.no-source.error=Must specify the source-type parameter.
  -converterdef.no-destination.error=Must specify the destination-type parameter.
  -converterdef.no-lib.error=Must specify the lib parameter.
  -converterdef.no-register.error=Failed to register converter {0}.
  -
   facility.no-create.error=Failed to create aspect handler of type {0}.
   facility.multi-element.error=Expected one sub-element to configure facility.
   facility.no-namespace.error=Must specify namespace parameter.
  
  
  
  1.5       +4 -8      jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/TypeDef.java
  
  Index: TypeDef.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/TypeDef.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TypeDef.java	1 Feb 2002 00:37:58 -0000	1.4
  +++ TypeDef.java	2 Feb 2002 12:51:58 -0000	1.5
  @@ -8,6 +8,8 @@
   package org.apache.antlib.runtime;
   
   import org.apache.myrmidon.framework.AbstractTypeDef;
  +import org.apache.myrmidon.interfaces.deployer.GeneralTypeDefinition;
  +import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   
   /**
    * Task to define a type.
  @@ -17,15 +19,9 @@
   public class TypeDef
       extends AbstractTypeDef
   {
  -    private String m_type;
   
  -    public void setType( final String type )
  +    protected TypeDefinition createTypeDefinition()
       {
  -        m_type = type;
  -    }
  -
  -    protected String getRoleShorthand()
  -    {
  -        return m_type;
  +        return new GeneralTypeDefinition();
       }
   }
  
  
  
  1.16      +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java
  
  Index: DefaultDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/DefaultDeployer.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DefaultDeployer.java	1 Feb 2002 00:37:58 -0000	1.15
  +++ DefaultDeployer.java	2 Feb 2002 12:51:58 -0000	1.16
  @@ -110,7 +110,7 @@
           }
           catch( Exception e )
           {
  -            final String message = REZ.getString( "deploy-from-classloader.error" );
  +            final String message = REZ.getString( "deploy-from-classloader.error", loader );
               throw new DeploymentException( message, e );
           }
       }
  
  
  
  1.13      +48 -28    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Deployment.java
  
  Index: Deployment.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Deployment.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Deployment.java	1 Feb 2002 00:37:58 -0000	1.12
  +++ Deployment.java	2 Feb 2002 12:51:58 -0000	1.13
  @@ -27,7 +27,9 @@
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.myrmidon.converter.Converter;
   import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
  +import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
   import org.apache.myrmidon.interfaces.deployer.DeploymentException;
  +import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
   import org.apache.myrmidon.interfaces.role.RoleManager;
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
  @@ -178,44 +180,62 @@
       /**
        * Deploys a single type from the type library.
        */
  -    public void deployType( String roleShorthand, String typeName, String className )
  +    public void deployType( final TypeDefinition typeDef )
           throws DeploymentException
       {
  -        try
  +        final String typeName = typeDef.getName();
  +        final String roleShorthand = typeDef.getRoleShorthand();
  +
  +        final String className = typeDef.getClassname();
  +        if( null == className )
           {
  -            handleType( roleShorthand, typeName, className );
  +            final String message = REZ.getString( "typedef.no-classname.error" );
  +            throw new DeploymentException( message );
           }
  -        catch( Exception e )
  -        {
  -            final String message = REZ.getString( "deploy-type.error", roleShorthand, typeName );
  -            throw new DeploymentException( message, e );
  -        }
  -    }
   
  -    /**
  -     * Deploys a converter from the type library.  The converter definition
  -     * is read from the type library descriptor.
  -     */
  -    public void deployConverter( String className )
  -        throws DeploymentException
  -    {
  -        // TODO - implement this
  -        throw new DeploymentException( "Not implemented." );
  -    }
  -
  -    /**
  -     * Deploys a converter from the type library.
  -     */
  -    public void deployConverter( String className, String srcClass, String destClass )
  -        throws DeploymentException
  -    {
           try
           {
  -            handleConverter( className, srcClass, destClass );
  +            if( typeDef instanceof ConverterDefinition )
  +            {
  +                // Validate the definition
  +                final ConverterDefinition converterDef = (ConverterDefinition)typeDef;
  +                final String srcClass = converterDef.getSourceType();
  +                final String destClass = converterDef.getDestinationType();
  +                if( null == srcClass )
  +                {
  +                    final String message = REZ.getString( "converterdef.no-source.error" );
  +                    throw new DeploymentException( message );
  +                }
  +                if( null == destClass )
  +                {
  +                    final String message = REZ.getString( "converterdef.no-destination.error" );
  +                    throw new DeploymentException( message );
  +                }
  +
  +                // Deploy the converter
  +                handleConverter( className, srcClass, destClass );
  +            }
  +            else
  +            {
  +                // Validate the definition
  +                if( null == roleShorthand )
  +                {
  +                    final String message = REZ.getString( "typedef.no-role.error" );
  +                    throw new DeploymentException( message );
  +                }
  +                else if( null == typeName )
  +                {
  +                    final String message = REZ.getString( "typedef.no-name.error" );
  +                    throw new DeploymentException( message );
  +                }
  +
  +                // Deploy general-purpose type
  +                handleType( roleShorthand, typeName, className );
  +            }
           }
           catch( Exception e )
           {
  -            final String message = REZ.getString( "deploy-converter.error", srcClass, destClass );
  +            final String message = REZ.getString( "deploy-type.error", roleShorthand, typeName );
               throw new DeploymentException( message, e );
           }
       }
  
  
  
  1.6       +6 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/deployer/Resources.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Resources.properties	1 Feb 2002 00:37:58 -0000	1.5
  +++ Resources.properties	2 Feb 2002 12:51:58 -0000	1.6
  @@ -1,4 +1,4 @@
  -register-converter.notice=Registered converter that converts from {1} to {2}.
  +register-converter.notice=Registered converter that converts from {0} to {1}.
   register-type.notice=Registered type {0}/{1}.
   register-role.notice=Registered role {0} with shorthand name {1}.
   url-deploy-types.notice=Registering types from "{0}".
  @@ -12,6 +12,11 @@
   unknown-role4name.error=Unknown role "{0}".
   no-file.error=Could not find type library "{0}".
   file-is-dir.error=Type library "{0}" is a directory.
  +typedef.no-classname.error=Must specify the classname parameter.
  +typedef.no-name.error=Must specify name parameter.
  +typedef.no-role.error=Must specify type parameter.
  +converterdef.no-source.error=Must specify the source-type parameter.
  +converterdef.no-destination.error=Must specify the destination-type parameter.
   
   available-extensions.notice=The list of available extensions for type library includes; {0}
   required-extensions.notice=The list of required extensions for type library includes; {0}
  
  
  
  1.14      +45 -26    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractTypeDef.java
  
  Index: AbstractTypeDef.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/AbstractTypeDef.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AbstractTypeDef.java	1 Feb 2002 00:37:59 -0000	1.13
  +++ AbstractTypeDef.java	2 Feb 2002 12:51:59 -0000	1.14
  @@ -10,10 +10,13 @@
   import java.io.File;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.myrmidon.api.AbstractTask;
  +import org.apache.avalon.framework.configuration.Configurable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.interfaces.deployer.Deployer;
   import org.apache.myrmidon.interfaces.deployer.DeploymentException;
  +import org.apache.myrmidon.interfaces.deployer.TypeDefinition;
   import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
   
   /**
  @@ -24,53 +27,66 @@
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    */
   public abstract class AbstractTypeDef
  -    extends AbstractTask
  +    extends AbstractContainerTask
  +    implements Configurable
   {
       private final static Resources REZ =
           ResourceManager.getPackageResources( AbstractTypeDef.class );
   
  +    // TODO - replace lib with class-path
       private File m_lib;
  -    private String m_name;
  -    private String m_className;
  +    private TypeDefinition m_typeDef;
   
  -    public void setLib( final File lib )
  +    /**
  +     * Configures this task.
  +     */
  +    public void configure( Configuration configuration ) throws ConfigurationException
       {
  -        //In the future this would be replaced by ClassPath sub-element
  -        m_lib = lib;
  -    }
  +        m_typeDef = createTypeDefinition();
   
  -    public void setName( final String name )
  -    {
  -        m_name = name;
  -    }
  +        // Configure attributes
  +        final String[] attrs = configuration.getAttributeNames();
  +        for( int i = 0; i < attrs.length; i++ )
  +        {
  +            final String name = attrs[ i ];
  +            final String value = configuration.getAttribute( name );
  +            if( name.equalsIgnoreCase( "lib" ) )
  +            {
  +                m_lib = (File)convert( File.class, value );
  +            }
  +            else
  +            {
  +                configure( m_typeDef, name, value );
  +            }
  +        }
   
  -    public void setClassname( final String className )
  -    {
  -        m_className = className;
  +        // Configure nested elements
  +        final Configuration[] elements = configuration.getChildren();
  +        for( int i = 0; i < elements.length; i++ )
  +        {
  +            Configuration element = elements[ i ];
  +            configure( m_typeDef, element );
  +        }
       }
   
  +    /**
  +     * Executes the task.
  +     */
       public void execute()
           throws TaskException
       {
  -        if( null == m_name )
  -        {
  -            final String message = REZ.getString( "typedef.no-name.error" );
  -            throw new TaskException( message );
  -        }
  -        else if( null == m_className )
  +        if( null == m_lib )
           {
  -            final String message = REZ.getString( "typedef.no-classname.error" );
  +            final String message = REZ.getString( "typedef.no-lib.error" );
               throw new TaskException( message );
           }
   
  -        final String shorthand = getRoleShorthand();
  -
           try
           {
               // Locate the deployer, and use it to deploy the type
               final Deployer deployer = (Deployer)getService( Deployer.class );
               final TypeDeployer typeDeployer = deployer.createDeployer( m_lib );
  -            typeDeployer.deployType( shorthand, m_name, m_className );
  +            typeDeployer.deployType( m_typeDef );
           }
           catch( DeploymentException e )
           {
  @@ -78,5 +94,8 @@
           }
       }
   
  -    protected abstract String getRoleShorthand();
  +    /**
  +     * Creates the definition for the type to be deployed.
  +     */
  +    protected abstract TypeDefinition createTypeDefinition();
   }
  
  
  
  1.5       +1 -4      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/Resources.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Resources.properties	25 Jan 2002 11:21:57 -0000	1.4
  +++ Resources.properties	2 Feb 2002 12:51:59 -0000	1.5
  @@ -3,10 +3,7 @@
   container.bad-config.error=Error converting value.
   container.no-factory.error=Could not locate the type factory for type "{0}".
   
  -typedef.no-name.error=Must specify name parameter.
  -typedef.no-classname.error=Must specify classname parameter.
  -typedef.no-register.error=Failed to register type.
  -typedef.bad-classloader.error=Failed to build classLoader due to: {0}.
  +typedef.no-lib.error=Must specify the lib parameter.
   
   condition.no-resolve.error=Error resolving {0}.
   
  
  
  
  1.21      +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java
  
  Index: CLIMain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/frontends/CLIMain.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- CLIMain.java	2 Feb 2002 05:50:22 -0000	1.20
  +++ CLIMain.java	2 Feb 2002 12:51:59 -0000	1.21
  @@ -338,7 +338,7 @@
           if( getLogger().isInfoEnabled() )
           {
               final String message = REZ.getString( "buildfile.notice", buildFile );
  -            getLogger().warn( message );
  +            getLogger().info( message );
           }
   
           if( getLogger().isInfoEnabled() )
  
  
  
  1.2       +11 -17    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/deployer/TypeDeployer.java
  
  Index: TypeDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/deployer/TypeDeployer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TypeDeployer.java	1 Feb 2002 00:37:59 -0000	1.1
  +++ TypeDeployer.java	2 Feb 2002 12:51:59 -0000	1.2
  @@ -11,7 +11,7 @@
    * A deployer for a type library.  Allows individual elements from a type
    * library to be deployed.
    *
  - * @author Adam Murdoch
  + * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    */
   public interface TypeDeployer
   {
  @@ -26,29 +26,23 @@
        * read from the type library descriptor.
        *
        * @param roleShorthand
  -     *          The <em>shorthand</em> for the role.
  +     *      The shorthand name for the role.
  +     *
        * @param typeName
  -     *          The type name.
  +     *      The type name.
  +     *
  +     * @throws DeploymentException
  +     *      If the type cannot be deployed.
        */
       void deployType( String roleShorthand, String typeName )
           throws DeploymentException;
   
       /**
        * Deploys a single type from the type library.
  +     *
  +     * @param typeDef
  +     *      The type definition.
        */
  -    void deployType( String roleShorthand, String typeName, String className )
  -        throws DeploymentException;
  -
  -    /**
  -     * Deploys a converter from the type library.  The converter definition
  -     * is read from the type library descriptor.
  -     */
  -    void deployConverter( String className )
  -        throws DeploymentException;
  -
  -    /**
  -     * Deploys a converter from the type library.
  -     */
  -    void deployConverter( String className, String srcClass, String destClass )
  +    void deployType( TypeDefinition typeDef )
           throws DeploymentException;
   }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/deployer/ConverterDefinition.java
  
  Index: ConverterDefinition.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.txt file.
   */
  package org.apache.myrmidon.interfaces.deployer;
  
  /**
   * A converter definition.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class ConverterDefinition
      extends TypeDefinition
  {
      private String m_sourceType;
      private String m_destinationType;
  
      /**
       * Returns the type's role.
       */
      public String getRoleShorthand()
      {
          return "converter";
      }
  
      /**
       * Returns the type's name.
       */
      public String getName()
      {
          return getClassname();
      }
  
      /**
       * Returns the converter's source type.
       */
      public String getSourceType()
      {
          return m_sourceType;
      }
  
      /**
       * Sets the converter's source type.
       */
      public void setSourceType( final String sourceType )
      {
          m_sourceType = sourceType;
      }
  
      /**
       * Returns the converter's destination type.
       */
      public String getDestinationType()
      {
          return m_destinationType;
      }
  
      /**
       * Sets the converter's destination type.
       */
      public void setDestinationType( final String destinationType )
      {
          m_destinationType = destinationType;
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/deployer/GeneralTypeDefinition.java
  
  Index: GeneralTypeDefinition.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.txt file.
   */
  package org.apache.myrmidon.interfaces.deployer;
  
  /**
   * A general-purpose type definition.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class GeneralTypeDefinition
      extends TypeDefinition
  {
      private String m_name;
      private String m_roleShorthand;
  
      /**
       * Returns the type's role.
       */
      public String getRoleShorthand()
      {
          return m_roleShorthand;
      }
  
      /**
       * Sets the type's role.
       */
      public void setType( String roleShorthand )
      {
          m_roleShorthand = roleShorthand;
      }
  
      /**
       * Returns the type's name.
       */
      public String getName()
      {
          return m_name;
      }
  
      /**
       * Sets the type's name.
       */
      public void setName( String name )
      {
          m_name = name;
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/interfaces/deployer/TypeDefinition.java
  
  Index: TypeDefinition.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.txt file.
   */
  package org.apache.myrmidon.interfaces.deployer;
  
  /**
   * A basic type definition.  This class is used to build a type definition,
   * from a typelib descriptor, or via introspection.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public abstract class TypeDefinition
  {
      private String m_className;
  
      /**
       * Returns the type's name.
       */
      public abstract String getName();
  
      /**
       * Returns the type's role.
       */
      public abstract String getRoleShorthand();
  
      /**
       * Returns the type's implementation class name.
       */
      public String getClassname()
      {
          return m_className;
      }
  
      /**
       * Sets the type's implementation class name.
       */
      public void setClassname( final String className )
      {
          m_className = className;
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/ComponentTestBase.java
  
  Index: ComponentTestBase.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.txt file.
   */
  package org.apache.myrmidon.components;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import junit.framework.TestCase;
  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.component.DefaultComponentManager;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.LogKitLogger;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.log.Hierarchy;
  import org.apache.log.LogTarget;
  import org.apache.log.Priority;
  import org.apache.log.format.PatternFormatter;
  import org.apache.log.output.io.StreamTarget;
  import org.apache.myrmidon.components.configurer.DefaultConfigurer;
  import org.apache.myrmidon.components.converter.DefaultConverterRegistry;
  import org.apache.myrmidon.components.converter.DefaultMasterConverter;
  import org.apache.myrmidon.components.deployer.DefaultDeployer;
  import org.apache.myrmidon.components.extensions.DefaultExtensionManager;
  import org.apache.myrmidon.components.role.DefaultRoleManager;
  import org.apache.myrmidon.components.type.DefaultTypeManager;
  import org.apache.myrmidon.interfaces.configurer.Configurer;
  import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
  import org.apache.myrmidon.interfaces.converter.MasterConverter;
  import org.apache.myrmidon.interfaces.deployer.Deployer;
  import org.apache.myrmidon.interfaces.extensions.ExtensionManager;
  import org.apache.myrmidon.interfaces.role.RoleManager;
  import org.apache.myrmidon.interfaces.type.TypeManager;
  
  /**
   * A base class for tests for the default components.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class ComponentTestBase extends TestCase
  {
      private DefaultComponentManager m_componentManager;
      private Logger m_logger;
  
      private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}";
  
      public ComponentTestBase( String s )
      {
          super( s );
      }
  
      /**
       * Returns the component manager containing the components to test.
       */
      protected ComponentManager getComponentManager()
      {
          return m_componentManager;
      }
  
      /**
       * Returns the type manager.
       */
      protected TypeManager getTypeManager() throws ComponentException
      {
          return (TypeManager)getComponentManager().lookup( TypeManager.ROLE );
      }
  
      /**
       * Setup the test case - prepares the set of components.
       */
      protected void setUp() throws Exception
      {
          // Setup a logger
          final Priority priority = Priority.DEBUG;
          final org.apache.log.Logger targetLogger = Hierarchy.getDefaultHierarchy().getLoggerFor( "myrmidon" );
  
          final PatternFormatter formatter = new PatternFormatter( PATTERN );
          final StreamTarget target = new StreamTarget( System.out, formatter );
          targetLogger.setLogTargets( new LogTarget[]{target} );
          targetLogger.setPriority( priority );
  
          m_logger = new LogKitLogger( targetLogger );
  
          // Create the components
          m_componentManager = new DefaultComponentManager();
          List components = new ArrayList();
  
          Component component = new DefaultMasterConverter();
          m_componentManager.put( MasterConverter.ROLE, component );
          components.add( component );
  
          component = new DefaultConverterRegistry();
          m_componentManager.put( ConverterRegistry.ROLE, component );
          components.add( component );
  
          component = new DefaultTypeManager();
          m_componentManager.put( TypeManager.ROLE, component );
          components.add( component );
  
          component = new DefaultConfigurer();
          m_componentManager.put( Configurer.ROLE, component );
          components.add( component );
  
          component = new DefaultDeployer();
          m_componentManager.put( Deployer.ROLE, component );
          components.add( component );
  
          component = new DefaultExtensionManager();
          m_componentManager.put( ExtensionManager.ROLE, component );
          components.add( component );
  
          component = new DefaultRoleManager();
          m_componentManager.put( RoleManager.ROLE, component );
          components.add( component );
  
          // Log enable the components
          for( Iterator iterator = components.iterator(); iterator.hasNext(); )
          {
              Object obj = iterator.next();
              if( obj instanceof LogEnabled )
              {
                  final LogEnabled logEnabled = (LogEnabled)obj;
                  logEnabled.enableLogging( m_logger );
              }
          }
  
          // Compose the components
          for( Iterator iterator = components.iterator(); iterator.hasNext(); )
          {
              Object obj = iterator.next();
              if( obj instanceof Composable )
              {
                  final Composable composable = (Composable)obj;
                  composable.compose( m_componentManager );
              }
          }
      }
  
      /**
       * Asserts that an exception contains the expected message.
       *
       * TODO - should take the expected exception, rather than the message,
       * to check the entire cause chain.
       */
      protected void assertSameMessage( final String msg, final Throwable exc )
      {
          assertEquals( msg, exc.getMessage() );
      }
  
      /**
       * Compares 2 objects for equality, nulls are equal.  Used by the test
       * classes' equals() methods.
       */
      public static boolean equals( final Object o1, final Object o2 )
      {
          if( o1 == null && o2 == null )
          {
              return true;
          }
          if( o1 == null || o2 == null )
          {
              return false;
          }
          return o1.equals( o2 );
      }
  }
  
  
  
  1.9       +17 -127   jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java
  
  Index: DefaultConfigurerTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/configurer/DefaultConfigurerTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultConfigurerTest.java	1 Feb 2002 06:46:49 -0000	1.8
  +++ DefaultConfigurerTest.java	2 Feb 2002 12:51:59 -0000	1.9
  @@ -8,36 +8,16 @@
   package org.apache.myrmidon.components.configurer;
   
   import java.io.File;
  -import java.util.ArrayList;
  -import java.util.Iterator;
  -import java.util.List;
   import junit.framework.AssertionFailedError;
  -import junit.framework.TestCase;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.component.DefaultComponentManager;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
  -import org.apache.avalon.framework.logger.LogEnabled;
  -import org.apache.avalon.framework.logger.LogKitLogger;
  -import org.apache.avalon.framework.logger.Logger;
  -import org.apache.log.Hierarchy;
  -import org.apache.log.LogTarget;
  -import org.apache.log.Priority;
  -import org.apache.log.format.PatternFormatter;
  -import org.apache.log.output.io.StreamTarget;
   import org.apache.myrmidon.api.TaskContext;
  -import org.apache.myrmidon.components.converter.DefaultConverterRegistry;
  -import org.apache.myrmidon.components.converter.DefaultMasterConverter;
  -import org.apache.myrmidon.components.type.DefaultTypeManager;
  +import org.apache.myrmidon.components.ComponentTestBase;
   import org.apache.myrmidon.components.workspace.DefaultTaskContext;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
  -import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
  -import org.apache.myrmidon.interfaces.converter.MasterConverter;
   import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
  -import org.apache.myrmidon.interfaces.type.TypeManager;
   
   /**
    * Test cases for the default configurer and related classes.
  @@ -45,19 +25,14 @@
    * @author Adam Murdoch
    */
   public class DefaultConfigurerTest
  -    extends TestCase
  +    extends ComponentTestBase
   {
       private final static Resources REZ =
           ResourceManager.getPackageResources( DefaultConfigurerTest.class );
   
  -    private DefaultComponentManager m_componentManager;
       private Configurer m_configurer;
  -    private TypeManager m_typeManager;
  -    private Logger m_logger;
       private DefaultTaskContext m_context;
   
  -    private final static String PATTERN = "[%8.8{category}] %{message}\\n%{throwable}";
  -
       public DefaultConfigurerTest( String name )
       {
           super( name );
  @@ -66,78 +41,18 @@
       /**
        * Setup the test case - prepares a set of components, including the
        * configurer.
  -     *
  -     * TODO - refactor to a sub-class, so this setup can be reused.
        */
       protected void setUp() throws Exception
       {
  -        final Priority priority = Priority.DEBUG;
  -        final org.apache.log.Logger targetLogger = Hierarchy.getDefaultHierarchy().getLoggerFor( "myrmidon" );
  -
  -        final PatternFormatter formatter = new PatternFormatter( PATTERN );
  -        final StreamTarget target = new StreamTarget( System.out, formatter );
  -        targetLogger.setLogTargets( new LogTarget[]{target} );
  -
  -        targetLogger.setPriority( priority );
  -
  -        // Create the logger
  -        m_logger = new LogKitLogger( targetLogger );
  -
  -        // Create the components
  -        m_componentManager = new DefaultComponentManager();
  -        List components = new ArrayList();
  +        super.setUp();
   
  -        Component component = new DefaultMasterConverter();
  -        m_componentManager.put( MasterConverter.ROLE, component );
  -        components.add( component );
  -
  -        component = new DefaultConverterRegistry();
  -        m_componentManager.put( ConverterRegistry.ROLE, component );
  -        components.add( component );
  -
  -        component = new DefaultTypeManager();
  -        m_componentManager.put( TypeManager.ROLE, component );
  -        components.add( component );
  -
  -        component = new DefaultConfigurer();
  -        m_componentManager.put( Configurer.ROLE, component );
  -        components.add( component );
  +        // Find the configurer
  +        m_configurer = (Configurer)getComponentManager().lookup( Configurer.ROLE );
   
           // Setup a context
  -        m_context = new DefaultTaskContext();
  -        components.add( m_context );
  -
  -        // Log enable the components
  -        for( Iterator iterator = components.iterator(); iterator.hasNext(); )
  -        {
  -            Object obj = iterator.next();
  -            if( obj instanceof LogEnabled )
  -            {
  -                final LogEnabled logEnabled = (LogEnabled)obj;
  -                logEnabled.enableLogging( m_logger );
  -            }
  -        }
  -
  -        // Compose the components
  -        for( Iterator iterator = components.iterator(); iterator.hasNext(); )
  -        {
  -            Object obj = iterator.next();
  -            if( obj instanceof Composable )
  -            {
  -                final Composable composable = (Composable)obj;
  -                composable.compose( m_componentManager );
  -            }
  -        }
  -
  -        // Configure the context
  +        m_context = new DefaultTaskContext( getComponentManager() );
           final File baseDir = new File( "." ).getAbsoluteFile();
           m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir );
  -
  -        // Find the configurer
  -        m_configurer = (Configurer)m_componentManager.lookup( Configurer.ROLE );
  -
  -        // Find the typeManager
  -        m_typeManager = (TypeManager)m_componentManager.lookup( TypeManager.ROLE );
       }
   
       /**
  @@ -366,7 +281,8 @@
       }
   
       /**
  -     * Tests reference resolution via a nested element.
  +     * Tests whether an object with a non-iterface typed adder causes an
  +     * exception.
        */
       public void testNonInterfaceTypedAdder()
           throws Exception
  @@ -380,6 +296,7 @@
           {
               // Configure the object
               m_configurer.configure( test, config, m_context );
  +            fail();
           }
           catch( final ConfigurationException ce )
           {
  @@ -391,7 +308,7 @@
       }
   
       /**
  -     * Tests whether a object with multiple typed adders causes an exception.
  +     * Tests whether an object with multiple typed adders causes an exception.
        */
       public void testMultipleTypedAdder()
           throws Exception
  @@ -405,6 +322,7 @@
           {
               // Configure the object
               m_configurer.configure( test, config, m_context );
  +            fail();
           }
           catch( final ConfigurationException ce )
           {
  @@ -415,7 +333,7 @@
       }
   
       /**
  -     * Tests to see if typed adder works.
  +     * Tests to see if typed adder works, with iterface types.
        */
       public void testTypedAdder()
           throws Exception
  @@ -431,8 +349,8 @@
           final DefaultTypeFactory factory = new DefaultTypeFactory( loader );
           factory.addNameClassMapping( "my-type1", MyType1.class.getName() );
           factory.addNameClassMapping( "my-type2", MyType2.class.getName() );
  -        m_typeManager.registerType( MyRole1.class, "my-type1", factory );
  -        m_typeManager.registerType( MyRole1.class, "my-type2", factory );
  +        getTypeManager().registerType( MyRole1.class, "my-type1", factory );
  +        getTypeManager().registerType( MyRole1.class, "my-type2", factory );
   
           final ConfigTest6 test = new ConfigTest6();
   
  @@ -446,7 +364,7 @@
       }
   
       /**
  -     * Tests to see if typed adder works.
  +     * Tests to see if typed adder works, with Configuration type.
        */
       public void testTypedConfigAdder()
           throws Exception
  @@ -470,7 +388,7 @@
       }
   
       /**
  -     * Tests to see if typed adder works.
  +     * Tests to see if typed adder works, with Configuration objects.
        */
       public void testConfigAdder()
           throws Exception
  @@ -494,7 +412,7 @@
       }
   
       /**
  -     * Tests to see if typed adder works.
  +     * Tests to check that Configurable is handled properly.
        */
       public void testConfigable()
           throws Exception
  @@ -647,33 +565,5 @@
           expected.setProp2( new ConfigTest1() );
           expected.addProp3( new ConfigTest1() );
           assertEquals( expected, test );
  -    }
  -
  -    /**
  -     * Asserts that an exception contains the expected message.
  -     *
  -     * TODO - should take the expected exception, rather than the message,
  -     * to check the entire cause chain.
  -     */
  -    protected void assertSameMessage( final String msg, final Throwable exc )
  -    {
  -        assertEquals( msg, exc.getMessage() );
  -    }
  -
  -    /**
  -     * Compares 2 objects for equality, nulls are equal.  Used by the test
  -     * classes' equals() methods.
  -     */
  -    public static boolean equals( final Object o1, final Object o2 )
  -    {
  -        if( o1 == null && o2 == null )
  -        {
  -            return true;
  -        }
  -        if( o1 == null || o2 == null )
  -        {
  -            return false;
  -        }
  -        return o1.equals( o2 );
       }
   }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/DefaultDeployerTest.java
  
  Index: DefaultDeployerTest.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.txt file.
   */
  package org.apache.myrmidon.components.deployer;
  
  import org.apache.myrmidon.components.ComponentTestBase;
  import org.apache.myrmidon.framework.DataType;
  import org.apache.myrmidon.interfaces.converter.MasterConverter;
  import org.apache.myrmidon.interfaces.deployer.ConverterDefinition;
  import org.apache.myrmidon.interfaces.deployer.Deployer;
  import org.apache.myrmidon.interfaces.deployer.GeneralTypeDefinition;
  import org.apache.myrmidon.interfaces.deployer.TypeDeployer;
  import org.apache.myrmidon.interfaces.role.RoleManager;
  import org.apache.myrmidon.interfaces.type.TypeFactory;
  
  /**
   * Test cases for the default deployer.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class DefaultDeployerTest
      extends ComponentTestBase
  {
      private Deployer m_deployer;
  
      public DefaultDeployerTest( String s )
      {
          super( s );
      }
  
      /**
       * Setup the test case - prepares the set of components, including the
       * deployer.
       */
      protected void setUp() throws Exception
      {
          super.setUp();
          m_deployer = (Deployer)getComponentManager().lookup( Deployer.ROLE );
      }
  
      /**
       * Tests deployment of a single type from a ClassLoader.
       */
      public void testSingleType() throws Exception
      {
          // Determine the shorthand for the DataType role
          final RoleManager roleManager = (RoleManager)getComponentManager().lookup( RoleManager.ROLE );
          roleManager.addNameRoleMapping( "data-type", DataType.ROLE );
  
          // Create the type definition
          final GeneralTypeDefinition typeDef = new GeneralTypeDefinition();
          typeDef.setType( "data-type" );
          typeDef.setName( "test-type1" );
          typeDef.setClassname( TestType1.class.getName() );
  
          // Deploy the type
          final ClassLoader classLoader = getClass().getClassLoader();
          final TypeDeployer typeDeployer = m_deployer.createDeployer( classLoader );
          typeDeployer.deployType( typeDef );
  
          // Create an instance
          final TypeFactory typeFactory = getTypeManager().getFactory( DataType.class );
          Object obj = typeFactory.create( "test-type1" );
  
          // Check the type
          assertTrue( obj instanceof TestType1 );
      }
  
      /**
       * Tests deployment of a single converter from a ClassLoader.
       */
      public void testSingleConverter() throws Exception
      {
          // Create the type definition
          final ConverterDefinition typeDef = new ConverterDefinition();
          typeDef.setClassname( TestConverter1.class.getName() );
          typeDef.setSourceType( "java.lang.String" );
          typeDef.setDestinationType( TestType1.class.getName() );
  
          // Deploy the type
          final ClassLoader classLoader = getClass().getClassLoader();
          final TypeDeployer typeDeployer = m_deployer.createDeployer( classLoader );
          typeDeployer.deployType( typeDef );
  
          // Try to convert from string to test type
          final MasterConverter converter = (MasterConverter)getComponentManager().lookup( MasterConverter.ROLE );
          Object obj = converter.convert( TestType1.class, "some-string", null );
  
          // Check the type
          assertTrue( obj instanceof TestType1 );
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/TestConverter1.java
  
  Index: TestConverter1.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.txt file.
   */
  package org.apache.myrmidon.components.deployer;
  
  import org.apache.myrmidon.converter.Converter;
  import org.apache.myrmidon.converter.ConverterException;
  import org.apache.avalon.framework.context.Context;
  
  /**
   * A test converter.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class TestConverter1
      implements Converter
  {
      /**
       * Convert original to destination type.
       */
      public Object convert( Class destination, Object original, Context context )
          throws ConverterException
      {
          return new TestType1();
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/testcases/org/apache/myrmidon/components/deployer/TestType1.java
  
  Index: TestType1.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.txt file.
   */
  package org.apache.myrmidon.components.deployer;
  
  import org.apache.myrmidon.framework.DataType;
  
  /**
   * A test data-type.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   */
  public class TestType1
      implements DataType
  {
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message