You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dominique Devienne <DD...@lgc.com> on 2004/01/14 15:56:21 UTC

My experience with namespaces in Ant 1.6 (WAS: RE: antlib: cannot find ?)

> From: Peter Reilly [mailto:peter.reilly@corvil.com]
> >
> >     <lucene:index index="${index.base.dir}/index">
> >       <fileset dir="${files.dir}"/>
> 
> This should be <lucene:fileset dir="${files.dir}"/>

2 remarks:

1) Using a namespace prefix on all nested elements can quickly become
   tedious for large tasks, with lots of nested elements. One way to
   remove the tedious is to change the default namespace for a given
   element and it's children:

   <index index="${index.base.dir}/index"
          xmlns ="antlib:org.apache.lucene.ant">
     <fileset dir="${files.dir}"/>
   </index>

2) All task containers are exceptions to the rule that nested elements
   need to be in the same namespace than the task itself. For example:

    <ac:outofdate>
      <ac:sourcefiles>
        <ac:pathelement location="new-build.xml" />
        <ac:pathelement location="config/build2dependencies.xsl" />
        <ac:pathelement location="config/dependencies.xsd" />
        <ac:pathelement location="config/dependencies.xsl" />
      </ac:sourcefiles>
      <ac:targetfiles>
        <ac:pathelement location="build/dependencies-ns.xml" />
        <ac:pathelement location="build/dependencies.xml" />
        <ac:pathelement location="build/dependencies.html" />
      </ac:targetfiles>
      <ac:sequential>
        <!-- Extract dependencies.xml from build.xml -->
        <style in="${ant.file}"
               out="build/dependencies-ns.xml"
               style="config/build2dependencies.xsl"
               processor="trax" />

        <!-- Post-process the XSL-generated file -->
        <bm:sed from="build/dependencies-ns.xml"
                to="build/dependencies.xml">
          ...
        </bm:sed>

        <!-- Schema-validate the extracted dependencies.xml -->
        <bm:schemavalid file="build/dependencies.xml"
            externalNoNamespaceSchema="config/dependencies.xsd" />
        <echo message="build/dependencies.xml is schema-valid" />

        <!-- Generate dev-friendly HTML of dependencies.xml -->
        <style in="build/dependencies.xml"
               out="build/dependencies.html"
               style="config/dependencies.xsl"
               processor="trax" />
        ...
      </ac:sequential>
    </ac:outofdate>

   See how Ant-Contrib's <outofdate> tasks nested elements must be
   in the Ant-Contrib namespace, but how the nested elements of the
   <sequential> belong to the Ant namespace, and another custom one.

   Other task with nested containers include <macrodef>, <if>, etc...

As a final note, I'd warn of a bug in Ant 1.6 (already fixed in CVS)
that prevents to declare the default namespace of the root <project>
element to be the Ant default namespace. The work around is simply
to not declare the root default namespace to the Ant namespace.

I hope this will help build writer going the namespace route. --DD

> 
> It was decided in the 1.6.beta series that nested elements found by
> reflection on the task object should be in the same namespace
> as the task.
> 
> Peter
> 
> >     </lucene:index>

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


Re: My experience with namespaces in Ant 1.6 (WAS: RE: antlib: cannot find ?)

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 14, 2004, at 9:56 AM, Dominique Devienne wrote:
> 1) Using a namespace prefix on all nested elements can quickly become
>    tedious for large tasks, with lots of nested elements. One way to
>    remove the tedious is to change the default namespace for a given
>    element and it's children:
>
>    <index index="${index.base.dir}/index"
>           xmlns ="antlib:org.apache.lucene.ant">
>      <fileset dir="${files.dir}"/>
>    </index>

Yup, I did that :))

Good point though.  Perhaps you could paste your info on to the wiki 
page for namespaces?

	Erik


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