peterreilly    2003/10/30 08:21:32

  Modified:    .        Tag: ANT_16_BRANCH build.xml WHATSNEW
               docs/manual/CoreTasks Tag: ANT_16_BRANCH typedef.html
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
                        Definer.java
               src/testcases/org/apache/tools/ant/taskdefs Tag:
                        ANT_16_BRANCH AntlibTest.java
  Added:       src/etc/testcases/taskdefs Tag: ANT_16_BRANCH
                        test2.antlib.xml
  Log:
  Merge bugzilla report 24024 from HEAD
  allow multiple xml resources of the same name to be loaded
  PR: 24024
  Obtained from: Jesse Glick
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.392.2.9 +7 -0      ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/ant/build.xml,v
  retrieving revision 1.392.2.8
  retrieving revision 1.392.2.9
  diff -u -r1.392.2.8 -r1.392.2.9
  --- build.xml 22 Oct 2003 09:28:21 -0000      1.392.2.8
  +++ build.xml 30 Oct 2003 16:21:31 -0000      1.392.2.9
  @@ -1338,6 +1338,13 @@
   
         <selector refid="conditional-patterns"/>
       </javac>
  +    
  +    <!-- Used by AntlibTest.testAntlibResource: -->
  +    <jar 
jarfile="${build.tests}/org/apache/tools/ant/taskdefs/test2-antlib.jar">
  +        <zipfileset dir="${tests.etc.dir}" 
fullpath="taskdefs/test.antlib.xml">
  +            <include name="taskdefs/test2.antlib.xml"/>
  +        </zipfileset>
  +    </jar>
     </target>
   
     <target name="dump-info" depends="dump-sys-properties,run-which"/>
  
  
  
  1.503.2.9 +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.503.2.8
  retrieving revision 1.503.2.9
  diff -u -r1.503.2.8 -r1.503.2.9
  --- WHATSNEW  29 Oct 2003 21:02:50 -0000      1.503.2.8
  +++ WHATSNEW  30 Oct 2003 16:21:31 -0000      1.503.2.9
  @@ -58,6 +58,9 @@
     by UNICODE escapes.
     Bugzilla report 23919.
   
  +* load all xml resources for typedef not just the first
  +  Bugzilla report 24024
  +
   Changes from Ant 1.6.B1 to Ant 1.6.B2
   =====================================
   
  
  
  
  No                   revision
  No                   revision
  1.10.2.3  +6 -1      ant/docs/manual/CoreTasks/typedef.html
  
  Index: typedef.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/typedef.html,v
  retrieving revision 1.10.2.2
  retrieving revision 1.10.2.3
  diff -u -r1.10.2.2 -r1.10.2.3
  --- typedef.html      14 Oct 2003 09:59:49 -0000      1.10.2.2
  +++ typedef.html      30 Oct 2003 16:21:32 -0000      1.10.2.3
  @@ -74,7 +74,12 @@
     </tr>
     <tr>
       <td valign="top">resource</td>
  -    <td valign="top">Name of the resouce to load definitions from.</td>
  +    <td valign="top">
  +    Name of the resource to load definitions from.
  +    If there is multiple resources of this name in the classpath, and the
  +    format is "properties", the first resource will be loaded, otherwise
  +    all the resources will be loaded.
  +    </td>
       <td valign="top" align="center">No</td>
     </tr>
     <tr>
  
  
  
  No                   revision
  No                   revision
  1.1.2.1   +0 -0      ant/src/etc/testcases/taskdefs/test2.antlib.xml
  
  Index: test2.antlib.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/test2.antlib.xml,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  
  No                   revision
  No                   revision
  1.44.2.1  +42 -19    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.44
  retrieving revision 1.44.2.1
  diff -u -r1.44 -r1.44.2.1
  --- Definer.java      22 Sep 2003 08:58:58 -0000      1.44
  +++ Definer.java      30 Oct 2003 16:21:32 -0000      1.44.2.1
  @@ -60,6 +60,7 @@
   import java.net.URL;
   import java.util.Enumeration;
   import java.util.Locale;
  +import java.util.NoSuchElementException;
   import java.util.Properties;
   
   import org.apache.tools.ant.AntTypeDefinition;
  @@ -217,26 +218,41 @@
                       + "together with file or resource.";
                   throw new BuildException(msg, getLocation());
               }
  -            URL url = null;
  +            Enumeration/*<URL>*/ urls = null;
               if (file != null) {
  -                url = fileToURL();
  -            }
  -            if (resource != null) {
  -                url = resourceToURL(al);
  +                final URL url = fileToURL();
  +                urls = new Enumeration() {
  +                    private boolean more = true;
  +                    public boolean hasMoreElements() {
  +                        return more;
  +                    }
  +                    public Object nextElement() throws 
NoSuchElementException {
  +                        if (more) {
  +                            more = false;
  +                            return url;
  +                        } else {
  +                            throw new NoSuchElementException();
  +                        }
  +                    }
  +                };
  +            } else {
  +                urls = resourceToURLs(al);
               }
   
  -            if (url == null) {
  -                return;
  -            }
  +            while (urls.hasMoreElements()) {
  +                URL url = (URL) urls.nextElement();
   
  -            if (url.toString().toLowerCase(Locale.US).endsWith(".xml")) {
  -                format = Format.XML;
  -            }
  -
  -            if (format == Format.PROPERTIES) {
  -                loadProperties(al, url);
  -            } else {
  -                loadAntlib(al, url);
  +                int format = this.format;
  +                if (url.toString().toLowerCase(Locale.US).endsWith(".xml")) {
  +                    format = Format.XML;
  +                }
  +
  +                if (format == Format.PROPERTIES) {
  +                    loadProperties(al, url);
  +                    break;
  +                } else {
  +                    loadAntlib(al, url);
  +                }
               }
           }
       }
  @@ -259,9 +275,16 @@
           }
       }
   
  -    private URL resourceToURL(ClassLoader classLoader) {
  -        URL ret = classLoader.getResource(resource);
  -        if (ret == null) {
  +    private Enumeration/*<URL>*/ resourceToURLs(ClassLoader classLoader) {
  +        Enumeration ret;
  +        try {
  +            ret = classLoader.getResources(resource);
  +        } catch (IOException e) {
  +            throw new BuildException(
  +                "Could not fetch resources named " + resource,
  +                e, getLocation());
  +        }
  +        if (!ret.hasMoreElements()) {
               if (onError != OnError.IGNORE) {
                   log("Could not load definitions from resource "
                       + resource + ". It could not be found.",
  
  
  
  No                   revision
  No                   revision
  1.3.2.1   +15 -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.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- AntlibTest.java   17 Sep 2003 16:17:56 -0000      1.3
  +++ AntlibTest.java   30 Oct 2003 16:21:32 -0000      1.3.2.1
  @@ -73,6 +73,15 @@
       public void testAntlibFile() {
           expectLog("antlib.file", "MyTask called");
       }
  +    
  +    /**
  +     * Confirms that all matching resources will be used, so that you
  +     * can collect several antlibs in one Definer call.
  +     * @see "http://issues.apache.org/bugzilla/show_bug.cgi?id=24024";
  +     */
  +    public void testAntlibResource() {
  +        expectLog("antlib.resource", "MyTask called-and-then-MyTask2 
called");
  +    }
   
       public void testNsCurrent() {
           expectLog("ns.current", "Echo2 inside a macroHello from x:p");
  @@ -81,6 +90,12 @@
       public static class MyTask extends Task {
           public void execute() {
               log("MyTask called");
  +        }
  +    }
  +
  +    public static class MyTask2 extends Task {
  +        public void execute() {
  +            log("MyTask2 called");
           }
       }
   
  
  
  

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

Reply via email to