diff --git a/src/etc/testcases/taskdefs/antlib.current-test.xml b/src/etc/testcases/taskdefs/antlib.current-test.xml
new file mode 100644
index 000000000..3efe95d5d
--- /dev/null
+++ b/src/etc/testcases/taskdefs/antlib.current-test.xml
@@ -0,0 +1,10 @@
+
+
+
+ Echo2 called
+
+
+ Echo2 inside a macro
+
+
+
diff --git a/src/etc/testcases/taskdefs/antlib.xml b/src/etc/testcases/taskdefs/antlib.xml
index b23023fa4..4e9514303 100644
--- a/src/etc/testcases/taskdefs/antlib.xml
+++ b/src/etc/testcases/taskdefs/antlib.xml
@@ -14,4 +14,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/main/org/apache/tools/ant/ComponentHelper.java b/src/main/org/apache/tools/ant/ComponentHelper.java
index faccb21cb..e7cc4d6c2 100644
--- a/src/main/org/apache/tools/ant/ComponentHelper.java
+++ b/src/main/org/apache/tools/ant/ComponentHelper.java
@@ -111,8 +111,8 @@ public class ComponentHelper {
* processing antlib
*/
private Stack antLibStack = new Stack();
- /** current antlib context */
- private AntTypeTable antLibCurrentTypeTable = null;
+ /** current antlib uri */
+ private String antLibCurrentUri = null;
/**
* Map from task names to vectors of created tasks
@@ -268,14 +268,7 @@ public class ComponentHelper {
public AntTypeDefinition getDefinition(String componentName) {
checkNamespace(componentName);
AntTypeDefinition ret = null;
- if (antLibCurrentTypeTable != null
- && ProjectHelper.ANT_CURRENT_URI.equals(
- ProjectHelper.extractUriFromComponentName(componentName))) {
- ret = antLibCurrentTypeTable.getDefinition(componentName);
- }
- if (ret == null) {
- ret = antTypeTable.getDefinition(componentName);
- }
+ ret = antTypeTable.getDefinition(componentName);
return ret;
}
@@ -690,22 +683,23 @@ public class ComponentHelper {
project.log(" +Datatype " + name + " " + def.getClassName(),
Project.MSG_DEBUG);
antTypeTable.put(name, def);
-
- if (antLibCurrentTypeTable != null && name.lastIndexOf(':') != -1) {
- String baseName = name.substring(name.lastIndexOf(':') + 1);
- antLibCurrentTypeTable.put(
- ProjectHelper.genComponentName(
- ProjectHelper.ANT_CURRENT_URI, baseName), def);
- }
}
}
/**
* Called at the start of processing an antlib
+ * @param uri the uri that is associated with this antlib
+ */
+ public void enterAntLib(String uri) {
+ antLibCurrentUri = uri;
+ antLibStack.push(uri);
+ }
+
+ /**
+ * @return the current antlib uri
*/
- public void enterAntLib() {
- antLibCurrentTypeTable = new AntTypeTable(project);
- antLibStack.push(antLibCurrentTypeTable);
+ public String getCurrentAntlibUri() {
+ return antLibCurrentUri;
}
/**
@@ -714,9 +708,9 @@ public class ComponentHelper {
public void exitAntLib() {
antLibStack.pop();
if (antLibStack.size() != 0) {
- antLibCurrentTypeTable = (AntTypeTable) antLibStack.peek();
+ antLibCurrentUri = (String) antLibStack.peek();
} else {
- antLibCurrentTypeTable = null;
+ antLibCurrentUri = null;
}
}
diff --git a/src/main/org/apache/tools/ant/UnknownElement.java b/src/main/org/apache/tools/ant/UnknownElement.java
index d2854e98f..2a76defac 100644
--- a/src/main/org/apache/tools/ant/UnknownElement.java
+++ b/src/main/org/apache/tools/ant/UnknownElement.java
@@ -125,12 +125,20 @@ public class UnknownElement extends Task {
return namespace;
}
- /** Set the namespace of the XML element associated with this component.
+ /**
+ * Set the namespace of the XML element associated with this component.
* This method is typically called by the XML processor.
+ * If the namespace is "ant:current", the component helper
+ * is used to get the current antlib uri.
*
* @param namespace URI used in the xmlns declaration.
*/
public void setNamespace(String namespace) {
+ if (namespace.equals(ProjectHelper.ANT_CURRENT_URI)) {
+ ComponentHelper helper = ComponentHelper.getComponentHelper(
+ getProject());
+ namespace = helper.getCurrentAntlibUri();
+ }
this.namespace = namespace;
}
diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
index 0efbdd7b4..772cbb69b 100644
--- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
+++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
@@ -926,8 +926,8 @@ public class ProjectHelper2 extends ProjectHelper {
/* UnknownElement is used for tasks and data types - with
delayed eval */
UnknownElement task = new UnknownElement(tag);
- task.setNamespace(uri);
task.setProject(context.getProject());
+ task.setNamespace(uri);
//XXX task.setTaskType(qname);
task.setQName(qname);
task.setTaskName(qname);
diff --git a/src/main/org/apache/tools/ant/taskdefs/Antlib.java b/src/main/org/apache/tools/ant/taskdefs/Antlib.java
index ce3780b59..0c805cc53 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Antlib.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Antlib.java
@@ -90,9 +90,11 @@ public class Antlib extends Task implements TaskContainer {
*
* @param project the current project
* @param antlibUrl the url to read the definitions from
+ * @param uri the uri that the antlib is to be placed in
* @return the ant lib task
*/
- public static Antlib createAntlib(Project project, URL antlibUrl) {
+ public static Antlib createAntlib(Project project, URL antlibUrl,
+ String uri) {
// Check if we can contact the URL
try {
antlibUrl.openConnection().connect();
@@ -100,22 +102,29 @@ public class Antlib extends Task implements TaskContainer {
throw new BuildException(
"Unable to find " + antlibUrl, ex);
}
- // Should be safe to parse
- ProjectHelper2 parser = new ProjectHelper2();
- UnknownElement ue =
- parser.parseUnknownElement(project, antlibUrl);
- // Check name is "antlib"
- if (!(ue.getTag().equals(TAG))) {
- throw new BuildException(
- "Unexpected tag " + ue.getTag() + " expecting "
- + TAG, ue.getLocation());
+ ComponentHelper helper =
+ ComponentHelper.getComponentHelper(project);
+ helper.enterAntLib(uri);
+ try {
+ // Should be safe to parse
+ ProjectHelper2 parser = new ProjectHelper2();
+ UnknownElement ue =
+ parser.parseUnknownElement(project, antlibUrl);
+ // Check name is "antlib"
+ if (!(ue.getTag().equals(TAG))) {
+ throw new BuildException(
+ "Unexpected tag " + ue.getTag() + " expecting "
+ + TAG, ue.getLocation());
+ }
+ Antlib antlib = new Antlib();
+ antlib.setProject(project);
+ antlib.setLocation(ue.getLocation());
+ antlib.init();
+ ue.configure(antlib);
+ return antlib;
+ } finally {
+ helper.exitAntLib();
}
- Antlib antlib = new Antlib();
- antlib.setProject(project);
- antlib.setLocation(ue.getLocation());
- antlib.init();
- ue.configure(antlib);
- return antlib;
}
@@ -166,28 +175,21 @@ public class Antlib extends Task implements TaskContainer {
* any tasks that derive from Definer.
*/
public void execute() {
- ComponentHelper helper =
- ComponentHelper.getComponentHelper(getProject());
- helper.enterAntLib();
- try {
- for (Iterator i = tasks.iterator(); i.hasNext();) {
- UnknownElement ue = (UnknownElement) i.next();
- ue.maybeConfigure();
- setLocation(ue.getLocation());
- Task t = ue.getTask();
- if (t == null) {
- continue;
- }
- if (t instanceof AntlibInterface) {
- AntlibInterface d = (AntlibInterface) t;
- d.setURI(uri);
- d.setAntlibClassLoader(getClassLoader());
- }
- t.init();
- t.execute();
+ for (Iterator i = tasks.iterator(); i.hasNext();) {
+ UnknownElement ue = (UnknownElement) i.next();
+ ue.maybeConfigure();
+ setLocation(ue.getLocation());
+ Task t = ue.getTask();
+ if (t == null) {
+ continue;
}
- } finally {
- helper.exitAntLib();
+ if (t instanceof AntlibInterface) {
+ AntlibInterface d = (AntlibInterface) t;
+ d.setURI(uri);
+ d.setAntlibClassLoader(getClassLoader());
+ }
+ t.init();
+ t.execute();
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/Definer.java b/src/main/org/apache/tools/ant/taskdefs/Definer.java
index e36cdc283..d0af369be 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Definer.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Definer.java
@@ -315,7 +315,7 @@ public abstract class Definer extends DefBase {
*/
private void loadAntlib(ClassLoader classLoader, URL url) {
try {
- Antlib antlib = Antlib.createAntlib(getProject(), url);
+ Antlib antlib = Antlib.createAntlib(getProject(), url, getUri());
antlib.setClassLoader(classLoader);
antlib.setURI(getUri());
antlib.perform();
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/AntlibTest.java b/src/testcases/org/apache/tools/ant/taskdefs/AntlibTest.java
index 87ac94777..7a912bba8 100644
--- a/src/testcases/org/apache/tools/ant/taskdefs/AntlibTest.java
+++ b/src/testcases/org/apache/tools/ant/taskdefs/AntlibTest.java
@@ -74,6 +74,10 @@ public class AntlibTest extends BuildFileTest {
expectLog("antlib.file", "MyTask called");
}
+ public void testNsCurrent() {
+ expectLog("ns.current", "Echo2 calledEcho2 inside a macro");
+ }
+
public static class MyTask extends Task {
public void execute() {
log("MyTask called");