peterreilly    2003/06/27 02:24:10

  Modified:    src/main/org/apache/tools/ant ComponentHelper.java
               src/main/org/apache/tools/ant/taskdefs Typedef.java
               src/testcases/org/apache/tools/ant ProjectTest.java
  Log:
  Get Project#getTaskDefinitions and Project#getDataTypeDefinitions
  to emulate old behaviour
    This fixs the <antstructure/> output.
  Provide ComponentHelper#getAntTypeTable to provide the full table
  Revert changes to ProjectTest
  Update Typedef.java (forgot this in previous commit)
  
  Revision  Changes    Path
  1.13      +69 -8     ant/src/main/org/apache/tools/ant/ComponentHelper.java
  
  Index: ComponentHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ComponentHelper.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ComponentHelper.java      26 Jun 2003 08:54:28 -0000      1.12
  +++ ComponentHelper.java      27 Jun 2003 09:24:10 -0000      1.13
  @@ -92,12 +92,19 @@
    * @since Ant1.6
    */
   public class ComponentHelper  {
  -    // Map from task names to implementing classes - not used anymore
  -    private Hashtable taskClassDefinitions = new Hashtable();
  -
       /** Map from compoennt name to anttypedefinition */
       private AntTypeTable antTypeTable;
   
  +    /** Map of tasks generated from antTypeTable */
  +    private Hashtable taskClassDefinitions = new Hashtable();
  +    /** flag to rebuild taskClassDefinitions */
  +    private boolean rebuildTaskClassDefinitions = true;
  +
  +    /** Map of types generated from antTypeTable */
  +    private Hashtable typeClassDefinitions = new Hashtable();
  +    /** flag to rebuild typeClassDefinitions */
  +    private boolean rebuildTypeClassDefinitions = true;
  +    
       /**
        * Map from task names to vectors of created tasks
        * (String to Vector of Task). This is used to invalidate tasks if
  @@ -105,7 +112,6 @@
        */
       private Hashtable createdTasks = new Hashtable();
   
  -
       protected ComponentHelper next;
       protected Project project;
   
  @@ -301,15 +307,70 @@
       /**
        * Returns the current task definition hashtable. The returned hashtable 
is
        * "live" and so should not be modified.
  -     * This table does not contain any information
        *
        * @return a map of from task name to implementing class
        *         (String to Class).
        */
       public Hashtable getTaskDefinitions() {
  +        synchronized(taskClassDefinitions) {
  +            synchronized (antTypeTable) {
  +                if (rebuildTaskClassDefinitions) {
  +                    taskClassDefinitions.clear();
  +                    for (Iterator i = antTypeTable.keySet().iterator();
  +                         i.hasNext();)
  +                    {
  +                        String name = (String) i.next();
  +                        Class clazz =
  +                            (Class) antTypeTable.getExposedClass(name);
  +                        if (clazz == null) {
  +                            continue;
  +                        }
  +                        if (Task.class.isAssignableFrom(clazz)) {
  +                            taskClassDefinitions.put(
  +                                name, antTypeTable.getTypeClass(name));
  +                        }
  +                    }
  +                    rebuildTaskClassDefinitions = false;
  +                }
  +            }
  +        }
           return taskClassDefinitions;
       }
       
  +
  +    /**
  +     * Returns the current type definition hashtable. The returned hashtable 
is
  +     * "live" and so should not be modified.
  +     *
  +     * @return a map of from type name to implementing class
  +     *         (String to Class).
  +     */
  +    public Hashtable getDataTypeDefinitions() {
  +        synchronized(typeClassDefinitions) {
  +            synchronized (antTypeTable) {
  +                if (rebuildTypeClassDefinitions) {
  +                    typeClassDefinitions.clear();
  +                    for (Iterator i = antTypeTable.keySet().iterator();
  +                         i.hasNext();)
  +                    {
  +                        String name = (String) i.next();
  +                        Class clazz =
  +                            (Class) antTypeTable.getExposedClass(name);
  +                        if (clazz == null) {
  +                            continue;
  +                        }
  +                        if (! Task.class.isAssignableFrom(clazz)) {
  +                            typeClassDefinitions.put(
  +                                name, antTypeTable.getTypeClass(name));
  +                        }
  +                    }
  +                    rebuildTypeClassDefinitions = false;
  +                }
  +            }
  +        }
  +        return typeClassDefinitions;
  +    }
  +    
       /**
        * Adds a new datatype definition.
        * Attempting to override an existing definition with an
  @@ -350,7 +411,7 @@
        * @return a map of from datatype name to implementing class
        *         (String to Class).
        */
  -    public Hashtable getDataTypeDefinitions() {
  +    public Hashtable getAntTypeTable() {
           return antTypeTable;
       }
   
  @@ -525,6 +586,8 @@
       private void updateDataTypeDefinition(AntTypeDefinition def) {
           String name = def.getName();
           synchronized (antTypeTable) {
  +            rebuildTaskClassDefinitions = true;
  +            rebuildTypeClassDefinitions = true;
               AntTypeDefinition old = antTypeTable.getDefinition(name);
               if (old != null) {
                   if (sameDefinition(def, old)) {
  @@ -682,8 +745,6 @@
           }
   
           public boolean contains(Object clazz) {
  -            // only used in unit test ProjectTest
  -            // needed ??? 
               for (Iterator i = values().iterator(); i.hasNext();) {
                   AntTypeDefinition def = (AntTypeDefinition) i.next();
                   Class c = def.getExposedClass();
  
  
  
  1.12      +3 -9      ant/src/main/org/apache/tools/ant/taskdefs/Typedef.java
  
  Index: Typedef.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Typedef.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Typedef.java      7 Mar 2003 11:23:02 -0000       1.11
  +++ Typedef.java      27 Jun 2003 09:24:10 -0000      1.12
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -54,7 +54,7 @@
   
   package org.apache.tools.ant.taskdefs;
   
  -import org.apache.tools.ant.BuildException;
  +
   
   /**
    *
  @@ -74,16 +74,10 @@
    * types are things likepaths or filesets that can be defined at
    * the project level and referenced via their ID attribute.</p>
    * <p>Custom data types usually need custom tasks to put them to good 
use.</p>
  - 
  + *  
    * @author Stefan Bodewig
    * @since Ant 1.4
    * @ant.task category="internal"
    */
   public class Typedef extends Definer {
  -    /**
  -     * implement abstract callback of parent class 
  -     */
  -    protected void addDefinition(String name, Class c) throws BuildException 
{
  -        getProject().addDataTypeDefinition(name, c);
  -    }
   }
  
  
  
  1.18      +5 -6      ant/src/testcases/org/apache/tools/ant/ProjectTest.java
  
  Index: ProjectTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/ProjectTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ProjectTest.java  26 Jun 2003 08:54:29 -0000      1.17
  +++ ProjectTest.java  27 Jun 2003 09:24:10 -0000      1.18
  @@ -183,9 +183,9 @@
           p.addBuildListener(mbl);
   
           p.addTaskDefinition("Ok", DummyTaskOk.class);
  -        assertEquals(DummyTaskOk.class, 
p.getDataTypeDefinitions().get("Ok"));
  +        assertEquals(DummyTaskOk.class, p.getTaskDefinitions().get("Ok"));
           p.addTaskDefinition("OkNonTask", DummyTaskOkNonTask.class);
  -        assertEquals(DummyTaskOkNonTask.class, 
p.getDataTypeDefinitions().get("OkNonTask"));
  +        assertEquals(DummyTaskOkNonTask.class, 
p.getTaskDefinitions().get("OkNonTask"));
           mbl.assertEmpty();
   
           assertTaskDefFails(DummyTaskPrivate.class,   DummyTaskPrivate.class  
 + " is not public");
  @@ -220,7 +220,7 @@
           mbl.addBuildEvent("return type of execute() should be void but was 
\"int\" in " + DummyTaskWithNonVoidExecute.class, Project.MSG_WARN);
           p.addTaskDefinition("NonVoidExecute", 
DummyTaskWithNonVoidExecute.class);
           mbl.assertEmpty();
  -        assertEquals(DummyTaskWithNonVoidExecute.class, 
p.getDataTypeDefinitions().get("NonVoidExecute"));
  +        assertEquals(DummyTaskWithNonVoidExecute.class, 
p.getTaskDefinitions().get("NonVoidExecute"));
       }
           
       public void testInputHandler() {
  @@ -233,12 +233,11 @@
       }
   
       public void testTaskDefinitionContainsKey() {
  -        assertTrue(p.getDataTypeDefinitions().containsKey("echo"));
  +        assertTrue(p.getTaskDefinitions().containsKey("echo"));
       }
   
       public void testTaskDefinitionContains() {
  -        assertTrue(p.getDataTypeDefinitions()
  -                   .contains(org.apache.tools.ant.taskdefs.Echo.class));
  +        
assertTrue(p.getTaskDefinitions().contains(org.apache.tools.ant.taskdefs.Echo.class));
       }
   
       private class DummyTaskPrivate extends Task {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to