You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Alan Snyder <co...@cbfiddle.com> on 2020/09/13 16:45:44 UTC

inline use of antlib with namespace?

Given that I have installed an external ant task library in an appropriate location, I know of two ways to make the tasks accessible in a build script:

1. Add an xmlns attribute to some element, such as

   <project ... xmlns:resolver="antlib:org.apache.maven.resolver.ant" ... > 

2. Add a taskdef inline, such as

  <taskdef resource="org/apache/maven/resolver/ant/antlib.xml"/> 

The first method puts the tasks in a separate namespace. The second method adds the tasks to the current namespace.

What I would like is a method that can be used inline (like #2) and also puts the tasks in a separate namespace (like #1).

Is there a way to do this?

My motivation is to use the inline definition in an imported script, so that I don’t have to repeat the definition in a large number of project specific scripts.



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


Re: inline use of antlib with namespace?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2020-09-21, Alan Snyder wrote:

> I think you are understanding correctly.

> It sounds like what I want might require either an include statement (textual inclusion) or project inheritance.

If you wanted something like project inheritance, then the projects need
to be aware and use "their parent" in some way. To me this sounds more
intrusive than putting an xmlns:prefix="" with the antlib-URI at the
project level.

If setting up the classloader is a concern, then use an URI using a
scheme other than antlib and use taskdef assigning that URI. If you
ensure taskdef has been run before the task itself is used this should
work.

Stefan

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


Re: inline use of antlib with namespace?

Posted by Alan Snyder <co...@cbfiddle.com>.
I think you are understanding correctly.

It sounds like what I want might require either an include statement (textual inclusion) or project inheritance.

> On Sep 21, 2020, at 9:58 AM, Stefan Bodewig <bo...@apache.org> wrote:
> 
> On 2020-09-21, Alan Snyder wrote:
> 
>> If I have to include the xmlns attribute at each use of a task from the library, then this is not what I want.
> 
> Then either I don't understand what you want or you want something that
> is not possible with XML namespaces :-)
> 
> XML namespaces care for URIs, not for prefixes. You define mappings
> between prefixes and URIs via xmlns:prefix. The mappings are inherited
> from an element to all nested elements, but you can not define a mapping
> in an element and expect it to be applied to a sibling element.
> 
> This is all handeled by the XML parser and Ant doesn't change that in
> any way - it just is told which URI a certain element name is part of
> and uses that to find the task.
> 
> Stefan
> 
> ---------------------------------------------------------------------
> 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: inline use of antlib with namespace?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2020-09-21, Alan Snyder wrote:

> If I have to include the xmlns attribute at each use of a task from the library, then this is not what I want.

Then either I don't understand what you want or you want something that
is not possible with XML namespaces :-)

XML namespaces care for URIs, not for prefixes. You define mappings
between prefixes and URIs via xmlns:prefix. The mappings are inherited
from an element to all nested elements, but you can not define a mapping
in an element and expect it to be applied to a sibling element.

This is all handeled by the XML parser and Ant doesn't change that in
any way - it just is told which URI a certain element name is part of
and uses that to find the task.

Stefan

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


Re: inline use of antlib with namespace?

Posted by Alan Snyder <co...@cbfiddle.com>.
If I have to include the xmlns attribute at each use of a task from the library, then this is not what I want.

> On Sep 21, 2020, at 1:24 AM, Stefan Bodewig <bo...@apache.org> wrote:
> 
> On 2020-09-13, Alan Snyder wrote:
> 
>> Given that I have installed an external ant task library in an appropriate location, I know of two ways to make the tasks accessible in a build script:
> 
>> 1. Add an xmlns attribute to some element, such as
> 
>>   <project ... xmlns:resolver="antlib:org.apache.maven.resolver.ant" ... >
> 
>> 2. Add a taskdef inline, such as
> 
>>  <taskdef resource="org/apache/maven/resolver/ant/antlib.xml"/>
> 
>> The first method puts the tasks in a separate namespace. The second method adds the tasks to the current namespace.
> 
>> What I would like is a method that can be used inline (like #2) and also puts the tasks in a separate namespace (like #1).
> 
> I think
> 
>  <taskdef resource="org/apache/maven/resolver/ant/antlib.xml"
>           uri="some-uri" />
> 
> does just that. Say the antlib defines a task foo you'd use it as
> 
>  <myprefix:foo xmlns:myprefix="some-uri"/>
> 
> Stefan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org <ma...@ant.apache.org>
> For additional commands, e-mail: user-help@ant.apache.org <ma...@ant.apache.org>

Re: inline use of antlib with namespace?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2020-09-13, Alan Snyder wrote:

> Given that I have installed an external ant task library in an appropriate location, I know of two ways to make the tasks accessible in a build script:

> 1. Add an xmlns attribute to some element, such as

>    <project ... xmlns:resolver="antlib:org.apache.maven.resolver.ant" ... >

> 2. Add a taskdef inline, such as

>   <taskdef resource="org/apache/maven/resolver/ant/antlib.xml"/>

> The first method puts the tasks in a separate namespace. The second method adds the tasks to the current namespace.

> What I would like is a method that can be used inline (like #2) and also puts the tasks in a separate namespace (like #1).

I think

  <taskdef resource="org/apache/maven/resolver/ant/antlib.xml"
           uri="some-uri" />

does just that. Say the antlib defines a task foo you'd use it as

  <myprefix:foo xmlns:myprefix="some-uri"/>

Stefan

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


AW: inline use of antlib with namespace?

Posted by ap...@materne.de.
With the antlib-syntax (#1) you define the xmlns you want to use.
If you want to load the jar from a custom location, you can use the taskdef.
http://ant.apache.org/manual/Types/antlib.html#loadFromInside

Jan

-----Ursprüngliche Nachricht-----
Von: Alan Snyder <co...@cbfiddle.com> 
Gesendet: Sonntag, 13. September 2020 18:46
An: user@ant.apache.org
Betreff: inline use of antlib with namespace?

Given that I have installed an external ant task library in an appropriate location, I know of two ways to make the tasks accessible in a build script:

1. Add an xmlns attribute to some element, such as

   <project ... xmlns:resolver="antlib:org.apache.maven.resolver.ant" ... > 

2. Add a taskdef inline, such as

  <taskdef resource="org/apache/maven/resolver/ant/antlib.xml"/> 

The first method puts the tasks in a separate namespace. The second method adds the tasks to the current namespace.

What I would like is a method that can be used inline (like #2) and also puts the tasks in a separate namespace (like #1).

Is there a way to do this?

My motivation is to use the inline definition in an imported script, so that I don’t have to repeat the definition in a large number of project specific scripts.



---------------------------------------------------------------------
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