Browse Source

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)


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274723 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 22 years ago
parent
commit
9f6981d2a2
3 changed files with 77 additions and 23 deletions
  1. +69
    -8
      src/main/org/apache/tools/ant/ComponentHelper.java
  2. +3
    -9
      src/main/org/apache/tools/ant/taskdefs/Typedef.java
  3. +5
    -6
      src/testcases/org/apache/tools/ant/ProjectTest.java

+ 69
- 8
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -92,12 +92,19 @@ import java.lang.reflect.Modifier;
* @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 @@ public class ComponentHelper {
*/
private Hashtable createdTasks = new Hashtable();


protected ComponentHelper next;
protected Project project;

@@ -301,15 +307,70 @@ public class ComponentHelper {
/**
* 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 @@ public class ComponentHelper {
* @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 @@ public class ComponentHelper {
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 class ComponentHelper {
}

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();


+ 3
- 9
src/main/org/apache/tools/ant/taskdefs/Typedef.java View File

@@ -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 @@ import org.apache.tools.ant.BuildException;
* 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);
}
}

+ 5
- 6
src/testcases/org/apache/tools/ant/ProjectTest.java View File

@@ -183,9 +183,9 @@ public class ProjectTest extends TestCase {
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 @@ public class ProjectTest extends TestCase {
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 class ProjectTest extends TestCase {
}

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 {


Loading…
Cancel
Save