You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by CJ <z....@googlemail.com> on 2007/08/30 14:27:40 UTC

Accessing build script's prefix-to-namespace uri mappings from a task.

Hi,

Hopefully someone can help me or point me in the right direction here.

I have a custom Ant task which I want to use to invoke another command
which isn't known at compilation time. It uses an approach very similar
to Ant itself, in that it builds the command from RuntimeConfigurables/
UnknownElements. This all works but for running commands which have a
prefix (such as my other custom commands).

I want to be able to translate the prefix to a namespace uri that I can
make the correct UnkownElement.setNamespace( uri ) call.

For clarity, this is a simplified form of what I want to do. (I realize
the example doesn't make a great deal of practical sense in this form;
this is just for illustrative purposes, please humor me :) ).

<project name="example"
         xmlns:myprefix="http://some.uri"
         >
    <taskdef resource="some/path/task.properties"
             uri="http://some.uri"
             classpath="mylib.jar"
             />     <!-- Supplying 'mytaskname' and 'taskrunner' -->
    
    <!-- Regular execution; example -->
    <myprefix:mytaskname ... />
    
    <!-- Task runner; what I want to do -->
    <myprefix:taskrunner>
        <atask name="myprefix:mytaskname">
            ...
        </atask>
    </myprefix:taskrunner>
</project>

Taskrunner is what I'm trying to get working, so it executes the task
just as Ant would when parsing the xml form above it. I am parsing the
'myprefix' from the task name (atask's name attribute), but I don't
know how to get the namespace 'http://some.uri' programmatically at
this point.

Is there a way to access the namespace mappings defined in the build
script that invokes taskrunner?

(I'm currently using Ant 1.7.0)

Thanks in advance.



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


Re: Accessing build script's prefix-to-namespace uri mappings from a task.

Posted by Peter Reilly <pe...@gmail.com>.
On 9/3/07, Steve Loughran <st...@apache.org> wrote:
> CJ wrote:
> > Hi,
> >
> > Hopefully someone can help me or point me in the right direction here.
> >
> > I have a custom Ant task which I want to use to invoke another command
> > which isn't known at compilation time. It uses an approach very similar
> > to Ant itself, in that it builds the command from RuntimeConfigurables/
> > UnknownElements. This all works but for running commands which have a
> > prefix (such as my other custom commands).
> >
> > I want to be able to translate the prefix to a namespace uri that I can
> > make the correct UnkownElement.setNamespace( uri ) call.
> >
> > For clarity, this is a simplified form of what I want to do. (I realize
> > the example doesn't make a great deal of practical sense in this form;
> > this is just for illustrative purposes, please humor me :) ).
> >
> > <project name="example"
> >          xmlns:myprefix="http://some.uri"
> >          >
> >     <taskdef resource="some/path/task.properties"
> >              uri="http://some.uri"
> >              classpath="mylib.jar"
> >              />     <!-- Supplying 'mytaskname' and 'taskrunner' -->
> >
> >     <!-- Regular execution; example -->
> >     <myprefix:mytaskname ... />
> >
> >     <!-- Task runner; what I want to do -->
> >     <myprefix:taskrunner>
> >         <atask name="myprefix:mytaskname">
> >             ...
> >         </atask>
> >     </myprefix:taskrunner>
> > </project>
> >
> > Taskrunner is what I'm trying to get working, so it executes the task
> > just as Ant would when parsing the xml form above it. I am parsing the
> > 'myprefix' from the task name (atask's name attribute), but I don't
> > know how to get the namespace 'http://some.uri' programmatically at
> > this point.
> >
>
> There's nothing in ant to do this yet, though you could probably write a
> task (which we would gladly accept, esp if it came with docs and tests :),
>
This is something that needs to be in ant-core. At the moment the prefix
namespace mapping is not retained.
It can be a little complicated,
as UEs can get copied and modified - macrodef for exmple.
Peter.


> --
> Steve Loughran                  http://www.1060.org/blogxter/publish/5
> Author: Ant in Action           http://antbook.org/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


Re: Accessing build script's prefix-to-namespace uri mappings from a task.

Posted by Steve Loughran <st...@apache.org>.
CJ wrote:
> Hi,
> 
> Hopefully someone can help me or point me in the right direction here.
> 
> I have a custom Ant task which I want to use to invoke another command
> which isn't known at compilation time. It uses an approach very similar
> to Ant itself, in that it builds the command from RuntimeConfigurables/
> UnknownElements. This all works but for running commands which have a
> prefix (such as my other custom commands).
> 
> I want to be able to translate the prefix to a namespace uri that I can
> make the correct UnkownElement.setNamespace( uri ) call.
> 
> For clarity, this is a simplified form of what I want to do. (I realize
> the example doesn't make a great deal of practical sense in this form;
> this is just for illustrative purposes, please humor me :) ).
> 
> <project name="example"
>          xmlns:myprefix="http://some.uri"
>          >
>     <taskdef resource="some/path/task.properties"
>              uri="http://some.uri"
>              classpath="mylib.jar"
>              />     <!-- Supplying 'mytaskname' and 'taskrunner' -->
>     
>     <!-- Regular execution; example -->
>     <myprefix:mytaskname ... />
>     
>     <!-- Task runner; what I want to do -->
>     <myprefix:taskrunner>
>         <atask name="myprefix:mytaskname">
>             ...
>         </atask>
>     </myprefix:taskrunner>
> </project>
> 
> Taskrunner is what I'm trying to get working, so it executes the task
> just as Ant would when parsing the xml form above it. I am parsing the
> 'myprefix' from the task name (atask's name attribute), but I don't
> know how to get the namespace 'http://some.uri' programmatically at
> this point.
> 

There's nothing in ant to do this yet, though you could probably write a 
task (which we would gladly accept, esp if it came with docs and tests :),

-- 
Steve Loughran                  http://www.1060.org/blogxter/publish/5
Author: Ant in Action           http://antbook.org/

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