I would agree with most of what Nicola says. I think
that XML ns is a "heavy" solution for name clashing
of names defined in a antlib. Moreover I do not
think that the antlib needs to define a qualified name.
The "prefix" attribute idea of the <property/> task could
be used - even with the current <typedef/> command.

<typedef resource="net/sf/antcontrib/antcontrib.properties"
         prefix="antcontrib"/>

To quote for the XML NS specification, XML NS
is used to to define elements and attribute "that are defined
for and used by multiple software modules."

Antlib's define ant types which are new elements, but the
attributes and nested elements of those elements are still
figured out by the ant "software module" using reflection on
the classes the tags map to.

Costin's idea of using "jmx:..." as a NS URI, seems to be a better
fit for using XML NS.

I think that another idea would be the use case of documenting
the build script. Something like the equalivant to javadoc for
ant scripts. Something like this should be in xml, but it does
not need to be processed as part of a build.

Something like the following:

<project default="t" xmlns:antdoc="http://ant.apache.org/antdoc";>
  
  <antdoc:comment>
    The target t is the default for this project
  </antdoc:comment>
    
  <target name="t">
    <antdoc:comment>This is simple test</antdoc:comment>
    <comment xmlns="http://ant.apache.org/antdoc";>
      <this>this is an anddoc comment</this>
    </comment>
    <echo message="hello world"/>
    <antdoc:comment>
      The following should be an ok ant task
      <echo message="a message within an ant doc comment"/>
    </antdoc:comment>
    <comment xmlns="http://ant.apache.org/antdoc";
             xmlns:ant="http://ant.apache.org";>
      <this>this is an antdoc element</this>
      <ant:echo ant:message="this is an ant echo command"
                antdoc:message="this is for antdoc"/>
    </comment>
  </target>
  
  <antdoc:ignore>
    <!-- These are test tasks and will not be shown in
         an ant doc report -->
    <target name="test">
      <echo>This is a test</echo>
    </target>
  </antdoc:ignore>
  
</project>

Attached is a  patch (cvs diff -u) to ProjectHelper2 to allow
the above. - the code is a quick hack - an idea may be to
allow NS URI handler plugins...

Cheers,
Peter
Nicola Ken Barozzi wrote:
> Costin Manolache wrote, On 03/05/2003 16.14:
>> Nicola Ken Barozzi wrote:
...
>>>I think that XML namespaces really make things much more difficult to
>>>write and understand. One thing I don't like in Jelly is just this
use
>>>of namespaces, where all scripts seem cluttered and simply difficult
to
>>>read.
> 
>> I agree - in most small build files, with few libraries and no
conflicting
>> names it is simpler to not use ns. 
> 
>> I don't think anyone is sugesting to make ns required for 1.6 ( we
need
>> to keep backward compat ). Even for antlibs, I think the ns should be
an
>> option.

>Ok, but namespaces are a "heavy" way of doing separation. ATM I don't 
>think that that it's good if they are not always used (and I don't like
>much to see them used).

>>>This is why I favor that Antlibs work similarly to java imports,
where
>>>there are no prefixes *except* when specified, and then I would *not*
>>>make prefixes free, but use the "standars" full name for that Antlib.
> 
>> Can you give an example ?

>Sure.

>Every antlib descriptor should contain not only the names of the tasks 
>but also the namespace of the antlib.
>When Ant loads the tasks, it does it with two names, so that the task 
>can be called with short or the fully qualified name.
>Example:
>
>   <antlib location="antcontrib.jar"/>
>
>   <!-- I can call it on both ways -->
>   <if/>
>   <antcontrib.if/>
>
>In the case that a library declares a task with the same name of one 
>already loaded, Ant should load the fully qualified name version and 
>change the short-name version to output an error about clashing names.




Index: ProjectHelper2.java
===================================================================
RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v
retrieving revision 1.19
diff -u -r1.19 ProjectHelper2.java
--- ProjectHelper2.java	3 May 2003 14:30:26 -0000	1.19
+++ ProjectHelper2.java	3 May 2003 23:49:10 -0000
@@ -90,6 +90,18 @@
  * @author Costin Manolache
  */
 public class ProjectHelper2 extends ProjectHelper {
+    private static String[] HANDLED_URIS = {
+        "", "http://ant.apache.org"};
+
+    private static boolean handleThisUri(String uri) {
+        for (int i = 0; i < HANDLED_URIS.length; ++i) {
+            if (uri.equals(HANDLED_URIS[i])) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
     /* Stateless */
 
     // singletons - since all state is in the context
@@ -378,8 +390,13 @@
          */
         public void startElement(String uri, String tag, String qname, Attributes attrs)
             throws SAXParseException {
-            AntHandler next
-                = currentHandler.onStartChild(uri, tag, qname, attrs, context);
+            AntHandler next = null;
+            if (!handleThisUri(uri))
+                next = new UnknownUriHandler(currentHandler);
+            else
+                next = currentHandler.onStartChild(
+                    uri, tag, qname, attrs, context);
+ 
             antHandlers.push(currentHandler);
             currentHandler = next;
             currentHandler.onStartElement(uri, tag, qname, attrs, context);
@@ -442,6 +459,24 @@
         }
     }
 
+    public static class UnknownUriHandler extends AntHandler {
+        private AntHandler parent;
+        public UnknownUriHandler(AntHandler parent) {
+            this.parent = parent;
+        }
+        public AntHandler onStartChild(String uri, String name, String qname,
+                                       Attributes attrs,
+                                       AntXMLContext context)
+            throws SAXParseException {
+            return parent.onStartChild(uri, name, qname, attrs, context);
+        }
+
+          public void characters(
+            char[] buf, int start, int count, AntXMLContext context)
+        {
+        }
+    }
+
     /**
      * Handler for the top level "project" element.
      */
@@ -783,8 +818,13 @@
                 = new RuntimeConfigurable(task, task.getTaskName());
 
             for (int i = 0; i < attrs.getLength(); i++) {
-                wrapper.setAttribute(attrs.getQName(i),
-                        attrs.getValue(i));
+                // Quick hack for NS support (need to add
+                // uri to wrapper.setattribute
+                // and need to do something like this for other attributes)
+                if (handleThisUri(attrs.getURI(i))) {
+                    wrapper.setAttribute(attrs.getLocalName(i),
+                                         attrs.getValue(i));
+                }
             }
 
             if (parentWrapper != null) {

Reply via email to