ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs AntlibTest.java
Date Wed, 10 Sep 2003 10:37:14 GMT
peterreilly    2003/09/10 03:37:14

  Modified:    src/etc/testcases/taskdefs antlib.xml
               src/main/org/apache/tools/ant ComponentHelper.java
                        UnknownElement.java
               src/main/org/apache/tools/ant/helper ProjectHelper2.java
               src/main/org/apache/tools/ant/taskdefs Antlib.java
                        Definer.java
               src/testcases/org/apache/tools/ant/taskdefs AntlibTest.java
  Added:       src/etc/testcases/taskdefs antlib.current-test.xml
  Log:
  Change design for storing the current antlib uri
  Allows deferred execution to work - for example
  ant script in macro def.
  Bugzilla report : 23029 from Yannick Menager
  
  Revision  Changes    Path
  1.2       +4 -0      ant/src/etc/testcases/taskdefs/antlib.xml
  
  Index: antlib.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/antlib.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- antlib.xml	24 Jul 2003 13:48:45 -0000	1.1
  +++ antlib.xml	10 Sep 2003 10:37:13 -0000	1.2
  @@ -14,4 +14,8 @@
       <mytask/>
     </target>
   
  +  <target name="ns.current">
  +    <typedef file="antlib.current-test.xml" uri="abc"/>
  +    <x:useecho2 xmlns:x="abc"/>
  +  </target>
   </project>
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/antlib.current-test.xml
  
  Index: antlib.current-test.xml
  ===================================================================
  <?xml version="1.0"?>
  <antlib xmlns:c="ant:current">
    <typedef name="echo2" classname="org.apache.tools.ant.taskdefs.Echo"/>
    <c:echo2>Echo2 called</c:echo2>
    <macrodef name="useecho2">
      <sequential>
        <c:echo2>Echo2 inside a macro</c:echo2>
      </sequential>
    </macrodef>
  </antlib>
  
  
  
  1.28      +16 -22    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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ComponentHelper.java	9 Sep 2003 16:52:03 -0000	1.27
  +++ ComponentHelper.java	10 Sep 2003 10:37:13 -0000	1.28
  @@ -111,8 +111,8 @@
        *   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 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 @@
               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 void exitAntLib() {
           antLibStack.pop();
           if (antLibStack.size() != 0) {
  -            antLibCurrentTypeTable = (AntTypeTable) antLibStack.peek();
  +            antLibCurrentUri = (String) antLibStack.peek();
           } else {
  -            antLibCurrentTypeTable = null;
  +            antLibCurrentUri = null;
           }
       }
   
  
  
  
  1.63      +9 -1      ant/src/main/org/apache/tools/ant/UnknownElement.java
  
  Index: UnknownElement.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/UnknownElement.java,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- UnknownElement.java	15 Aug 2003 15:04:29 -0000	1.62
  +++ UnknownElement.java	10 Sep 2003 10:37:13 -0000	1.63
  @@ -125,12 +125,20 @@
           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;
       }
   
  
  
  
  1.31      +1 -1      ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  
  Index: ProjectHelper2.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- ProjectHelper2.java	13 Aug 2003 14:06:19 -0000	1.30
  +++ ProjectHelper2.java	10 Sep 2003 10:37:13 -0000	1.31
  @@ -926,8 +926,8 @@
               /* 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);
  
  
  
  1.8       +39 -37    ant/src/main/org/apache/tools/ant/taskdefs/Antlib.java
  
  Index: Antlib.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Antlib.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Antlib.java	22 Aug 2003 15:25:44 -0000	1.7
  +++ Antlib.java	10 Sep 2003 10:37:14 -0000	1.8
  @@ -90,9 +90,11 @@
        *
        * @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 @@
               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 @@
        * 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();
           }
       }
   
  
  
  
  1.43      +1 -1      ant/src/main/org/apache/tools/ant/taskdefs/Definer.java
  
  Index: Definer.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- Definer.java	22 Aug 2003 15:25:44 -0000	1.42
  +++ Definer.java	10 Sep 2003 10:37:14 -0000	1.43
  @@ -315,7 +315,7 @@
        */
       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();
  
  
  
  1.2       +4 -0      ant/src/testcases/org/apache/tools/ant/taskdefs/AntlibTest.java
  
  Index: AntlibTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/AntlibTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AntlibTest.java	24 Jul 2003 13:48:45 -0000	1.1
  +++ AntlibTest.java	10 Sep 2003 10:37:14 -0000	1.2
  @@ -74,6 +74,10 @@
           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");
  
  
  

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


Mime
View raw message