ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <ddevie...@gmail.com>
Subject Re: How do I share data between custom Ant tasks?
Date Mon, 25 Oct 2010 17:43:35 GMT
On Mon, Oct 25, 2010 at 11:19 AM, Kevin Connor Arpe <kevinarpe@gmail.com> wrote:
> I wrote a StackOverflow.com post, but was unable to get help on this issue.

SO is great, but the official user and dev lists is the best place to
ask Ant questions.

> <?xml version="1.0" encoding="UTF-8"?>
> <project name="MyTask" basedir="." default="init">
>   <target name="init"
>           description="test the custom task"
>   >
>      <taskdef name="CustomTask1"
>               classname="AntCustomTask1"
>               classpath="C:\my_custom_ant_task_class_files"
>      />
>      <taskdef name="CustomTask2"
>               classname="AntCustomTask2"
>               classpath="C:\my_custom_ant_task_class_files"
>      />
>      <CustomTask1/>
>      <CustomTask2/>
>   </target>
> </project>
>
> Do all of the above and you will see "alloc" logged twice. I cannot
> get these two custom tasks to share the "big data".

Because each is loaded thru a different class loader, and there's a
different static member per "independent" class loader. If you are new
to Java, class loaders is a very interesting advanced topic to look
into btw :)

I don't remember the details, but it's likely your two independent
<taskdef> that force using separate class loaders. Using either a
single taskdef loading a .properties file, or using a classpathref
might use the same classloader instead. Also putting your tasks into
an AntLib in its own Jar with a proper antlib.xml manifest would also
likely use a single class loader.

But as Jeffrey wrote, you could have your tasks read/write properties
to communicate, or pass them a reference to a datatype instance as
well.

<mytype id="foo" ... > ... </mytype>
<mytask1 mytyperef="foo">...</mytask1>
<mytask2 >
  <mytype ref="foo" /> <!-- or is it idref? I don't recall the naming
convention -->
  ...
</mytask2>

Trouble is, reference-handling in task is not implicit, you have to
manually code it in, and there are many examples in the code. Note the
two ways references are passed to tasks typically, via a xyzref
attribute, or a nested xyz with only a ref (or idref?) attribute.

Hope this help. Sorry my Ant is getting very rusty. --DD

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


Mime
View raw message