ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From darr...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant Ant1CompatConfigurer.java Task.java
Date Mon, 01 Apr 2002 00:40:41 GMT
darrell     02/03/31 16:40:41

  Modified:    proposal/myrmidon build.xml
               proposal/myrmidon/src/ant1compat/org/apache/tools/ant
                        Task.java
  Added:       proposal/myrmidon/src/ant1compat/org/apache/tools/ant
                        Ant1CompatConfigurer.java
  Log:
  Better Ant1-style configuration in compatibility layer,
  as JUnit task relies on child elements being created before,
  but configured after, the parent.
  Build "test" target now passes when run through Myrmidon.
  
  Revision  Changes    Path
  1.99      +1 -1      jakarta-ant/proposal/myrmidon/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.xml,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- build.xml	31 Mar 2002 10:56:57 -0000	1.98
  +++ build.xml	1 Apr 2002 00:40:41 -0000	1.99
  @@ -616,7 +616,7 @@
               <formatter type="brief" usefile="false"/>
               <classpath>
                   <fileset dir="${test.working.dir}/dist/bin/lib" includes="**/*.jar"/>
  -                <fileset dir="${test.working.dir}/dist/lib" includes="**/*.jar, **/*.atl"
excludes="**/crimson.jar"/>
  +                <fileset dir="${test.working.dir}/dist/lib" includes="**/*.jar, **/*.atl"/>
               </classpath>
               <classpath location="${test.classes}"/>
   
  
  
  
  1.6       +11 -52    jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java
  
  Index: Task.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Task.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Task.java	30 Mar 2002 06:56:04 -0000	1.5
  +++ Task.java	1 Apr 2002 00:40:41 -0000	1.6
  @@ -22,7 +22,7 @@
    * all of the Myrmidon-specific adaptations.
    *
    * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
  - * @version $Revision: 1.5 $ $Date: 2002/03/30 06:56:04 $
  + * @version $Revision: 1.6 $ $Date: 2002/04/01 00:40:41 $
    */
   public class Task extends OriginalAnt1Task
       implements org.apache.myrmidon.api.Task, Configurable
  @@ -71,14 +71,15 @@
   
       /**
        * Uses the task Configuration to perform Ant1-style configuration
  -     * on the Ant1 task.
  +     * on the Ant1 task. This method configures *all* tasks the way Ant1
  +     * configures tasks inside a target.
  +     *
        * @param configuration The TaskModel for this Ant1 Task.
        * @throws ConfigurationException if the Configuration supplied is not valid
        */
       public void configure( Configuration configuration ) throws ConfigurationException
       {
           configure( this, configuration );
  -        this.init();
       }
   
       /**
  @@ -94,55 +95,13 @@
        */
       protected void configure( Object target, Configuration configuration ) throws ConfigurationException
       {
  -        IntrospectionHelper helper = IntrospectionHelper.getHelper( target.getClass() );
  -
  -        // Configure the id.
  -        String id = configuration.getAttribute( "id", null );
  -        if( id != null )
  -        {
  -            project.addReference( id, target );
  -        }
  -
  -        // Configure the attributes.
  -        final String[] attribs = configuration.getAttributeNames();
  -        for( int i = 0; i < attribs.length; i++ )
  -        {
  -            final String name = attribs[ i ];
  -            final String value =
  -                project.replaceProperties( configuration.getAttribute( name ) );
  -            try
  -            {
  -                helper.setAttribute( project, target,
  -                                     name.toLowerCase( Locale.US ), value );
  -            }
  -            catch( BuildException be )
  -            {
  -                // id attribute must be set externally
  -                if( !name.equals( "id" ) )
  -                {
  -                    throw be;
  -                }
  -            }
  -        }
  -
  -        // Configure the text content.
  -        String text = configuration.getValue( null );
  -        if( text != null )
  -        {
  -            helper.addText( project, target, text );
  -        }
  -
  -        // Configure the nested elements
  -        Configuration[] nestedConfigs = configuration.getChildren();
  -        for( int i = 0; i < nestedConfigs.length; i++ )
  -        {
  -            Configuration nestedConfig = nestedConfigs[ i ];
  -            String name = nestedConfig.getName();
  -            Object nestedElement = helper.createElement( project, target, name );
  -            configure( nestedElement, nestedConfig );
  -            helper.storeElement( project, target, nestedElement, name );
  -        }
  -
  +        //TODO Maybe provide different configuration order for tasks not in a target,
  +        // elements in a TaskContainer etc...
  +        Ant1CompatConfigurer configurer =
  +            new Ant1CompatConfigurer( target, configuration, project );
  +        configurer.createChildren();
  +        configurer.configure();
  +        this.init();
       }
   
       /**
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/ant1compat/org/apache/tools/ant/Ant1CompatConfigurer.java
  
  Index: Ant1CompatConfigurer.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.tools.ant;
  
  import java.util.Locale;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  /**
   * A helper class which uses reflection to configure any Object,
   * with the help of the Ant1 IntrospectionHelper.
   * This aims to mimic (to some extent) the Ant1-style configuration rules
   * implemented by ProjectHelperImpl.
   *
   * @author <a href="mailto:darrell@apache.org">Darrell DeBoer</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/01 00:40:41 $
   */
  class Ant1CompatConfigurer
  {
      private final Object m_configuredObject;
      private Configuration m_configuration;
      private final Project m_project;
      private final IntrospectionHelper m_helper;
  
      private Object[] m_childObjects;
      private Ant1CompatConfigurer[] m_childConfigurers;
      private String[] m_childNames;
  
      Ant1CompatConfigurer( Object configuredObject,
                            Configuration config,
                            Project project )
      {
          m_configuredObject = configuredObject;
          m_configuration = config;
          m_project = project;
          m_helper = IntrospectionHelper.getHelper( m_configuredObject.getClass() );
      }
  
      /**
       * Create all child elements, recursively.
       */
      void createChildren() throws ConfigurationException
      {
          Configuration[] childConfigs = m_configuration.getChildren();
  
          m_childObjects = new Object[ childConfigs.length ];
          m_childConfigurers = new Ant1CompatConfigurer[ childConfigs.length ];
          m_childNames = new String[ childConfigs.length ];
  
          for( int i = 0; i < childConfigs.length; i++ )
          {
              Configuration childConfig = childConfigs[ i ];
              String name = childConfig.getName();
              Object childObject =
                  m_helper.createElement( m_project, m_configuredObject, name );
              Ant1CompatConfigurer childConfigurer =
                  new Ant1CompatConfigurer( childObject, childConfig, m_project );
  
              m_childObjects[ i ] = childObject;
              m_childNames[ i ] = name;
              m_childConfigurers[ i ] = childConfigurer;
  
              // Recursively create children
              childConfigurer.createChildren();
          }
      }
  
      /**
       * Configure attributes and text, recursively.
       */
      void configure() throws ConfigurationException
      {
          // Configure the attributes.
          final String[] attribs = m_configuration.getAttributeNames();
          for( int i = 0; i < attribs.length; i++ )
          {
              final String name = attribs[ i ];
              final String value =
                  m_project.replaceProperties( m_configuration.getAttribute( name ) );
              try
              {
                  m_helper.setAttribute( m_project, m_configuredObject,
                                         name.toLowerCase( Locale.US ), value );
              }
              catch( BuildException be )
              {
                  // id attribute must be set externally
                  if( !name.equals( "id" ) )
                  {
                      throw be;
                  }
              }
          }
  
          // Configure the text content.
          String text = m_configuration.getValue( null );
          if( text != null )
          {
              m_helper.addText( m_project, m_configuredObject, text );
          }
  
          // Configure and add all children
          for( int i = 0; i < m_childConfigurers.length; i++ )
          {
              m_childConfigurers[ i ].configure();
  
              // Store child if neccessary (addConfigured)
              m_helper.storeElement( m_project, m_configuredObject,
                                     m_childObjects[ i ], m_childNames[ i ] );
          }
  
          // Set the reference, if id was specified.
          String id = m_configuration.getAttribute( "id", null );
          if( id != null )
          {
              m_project.addReference( id, m_configuredObject );
          }
  
      }
  }
  
  
  

--
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