inline use of antlib with namespace?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

inline use of antlib with namespace?

Alan Snyder-2
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: inline use of antlib with namespace?

Jan Matèrne (jhm)
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 <[hidden email]>
Gesendet: Sonntag, 13. September 2020 18:46
An: [hidden email]
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: [hidden email] For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: inline use of antlib with namespace?

Stefan Bodewig
In reply to this post by Alan Snyder-2
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: inline use of antlib with namespace?

Alan Snyder-2
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 <[hidden email]> 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: [hidden email] <mailto:[hidden email]>
> For additional commands, e-mail: [hidden email] <mailto:[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: inline use of antlib with namespace?

Stefan Bodewig
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: inline use of antlib with namespace?

Alan Snyder-2
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 <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: inline use of antlib with namespace?

Stefan Bodewig
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: [hidden email]
For additional commands, e-mail: [hidden email]