You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mikhail Fedotov <mi...@kittown.com> on 2006/05/16 12:23:25 UTC

Task adapter

Hi all,

I have two existing tasks. I want to modify the first task so that it 
runs the second one as part
of its work.

I have code which creates ant build file with parameters for the second 
task and then uses
new instance of AntScenario to run that file. The question is, can I do 
the same thing without
creating any extra files ? Can I just create an instance of the second 
task while executing the
first one, call needed setter methods and execute it ?

Thanks,
Mikhail

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


Re: Task adapter

Posted by Mikhail Fedotov <mi...@kittown.com>.
Steve Loughran wrote:
> or you cp -r to some intermediate place, strip out the junk you dont 
> want <delete> then do another cp -r of the stuff you like. Nasty, but 
> roughly what I do with some of my deployments where I want almost but 
> not everything on the classpath to get redistributed. Rather than 
> declare what I want, I ask for everything that the m2 tasks give me 
> and then strip out stuff like the servlet api, junit, and other stuff 
> that creeps in.
Good idea, but probably not for our tasks - too much stuff to move, too 
much time spent copying it from one network share to another. That's why 
we prefer to use hard links in overwriting mode instead of actual copying.

Mikhail

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


Re: Task adapter

Posted by Steve Loughran <st...@apache.org>.
Mikhail Fedotov wrote:
.
>> otherwise, I'd try creating a good cp -r command, possibly with <apply>.
> We tried that (without "-r"), it does not work, some jvms tend to 
> produce core dumps when they see a lot of "cp"s. We need to run ok even 
> on those. And we can't
> use "-r" as we need to exclude some stuff...
> 
> Thanks for ideas, I'll try to extend FileSet and use hacked version of 
> copy procedure.
> 

or you cp -r to some intermediate place, strip out the junk you dont 
want <delete> then do another cp -r of the stuff you like. Nasty, but 
roughly what I do with some of my deployments where I want almost but 
not everything on the classpath to get redistributed. Rather than 
declare what I want, I ask for everything that the m2 tasks give me and 
then strip out stuff like the servlet api, junit, and other stuff that 
creeps in.

-steve

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


Re: Task adapter

Posted by Mikhail Fedotov <mi...@kittown.com>.
Steve Loughran wrote:
>> I need an alternative to standard copy task . The standard one does 
>> not preserve permissions on unix systems, can not be told to create 
>> hardlinks if possible instead of copying,
>> etc etc, and I need all that. I'm planning to get standard copy task 
>> and modify it to produce system-dependent script (for windows and for 
>> linux) and then pass the script to shellscript
>> task from ant-contrib.
> windows? permissions? Cygwin or real NTFS metadata + ACLs?
No, we don't need that. On windows all additional functionality is 
turned off, but on linux/*nix it is strictly mandatory. We already have 
some spaghetti-style version of such copy task.
The code essentially repeats the whole shellscript task, exec task, and 
Execute class used by them... I'm redesigning it into something more 
manageable.
>>
>> The problem is that I have a lot of filesets, and each of them must 
>> be copied to its own directory. This way I'm getting a lot of 
>> instances of modified copy task,
>> which in turn create many instances of shellscipt task, which do a 
>> lot of shell/system calls. This last bit makes the whole system very 
>> fragile, according to our experience.
> slow too. you are execing a lot.
I can group such copy requests into reasonable number of scripts. This 
is already done, but in a very ugly way.  The problem seems to disappear 
when hundreds of "cp"s
are run from the shell started from Java instead of being run directly 
from Java via individual system calls.
> otherwise, I'd try creating a good cp -r command, possibly with <apply>.
We tried that (without "-r"), it does not work, some jvms tend to 
produce core dumps when they see a lot of "cp"s. We need to run ok even 
on those. And we can't
use "-r" as we need to exclude some stuff...

Thanks for ideas, I'll try to extend FileSet and use hacked version of 
copy procedure.

Mikhail

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


Re: Task adapter

Posted by Steve Loughran <st...@apache.org>.
Mikhail Fedotov wrote:
> Steve Loughran wrote:
>> The alternative is creating and binding by hand:
>>
>> MyTask task=new MyTask();
>> task.setProject(getProject());
>> task.setName(getName());
>> task.setLocation(getLocation());
>> task.init();
>>
>> This is how everything in Ant1.7 does it, though there we cheated add 
>> added Task.bindToOwner(Task owner) to do the repetitive work of 
>> propagating project, name and location.
> Thanks! I'll use that.
> 
> A bit more info about that I'm doing.
> 
> I need an alternative to standard copy task . The standard one does not 
> preserve permissions on unix systems, can not be told to create 
> hardlinks if possible instead of copying,
> etc etc, and I need all that. I'm planning to get standard copy task and 
> modify it to produce system-dependent script (for windows and for linux) 
> and then pass the script to shellscript
> task from ant-contrib.

windows? permissions? Cygwin or real NTFS metadata + ACLs?

> 
> The problem is that I have a lot of filesets, and each of them must be 
> copied to its own directory. This way I'm getting a lot of instances of 
> modified copy task,
> which in turn create many instances of shellscipt task, which do a lot 
> of shell/system calls. This last bit makes the whole system very 
> fragile, according to our experience.

slow too. you are execing a lot.

> 
> I think that the best option would be to subclass FileSet and add target 
> directory attribute to it. But maybe someone here has a better idea or 
> some other hint...

Java 6.0? Maybe there is also some stuff in sourceforge to do filesystem 
permissions. If not, you could write one.

otherwise, I'd try creating a good cp -r command, possibly with <apply>.

-steve

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


Re: Task adapter

Posted by Mikhail Fedotov <mi...@kittown.com>.
Steve Loughran wrote:
> The alternative is creating and binding by hand:
>
> MyTask task=new MyTask();
> task.setProject(getProject());
> task.setName(getName());
> task.setLocation(getLocation());
> task.init();
>
> This is how everything in Ant1.7 does it, though there we cheated add 
> added Task.bindToOwner(Task owner) to do the repetitive work of 
> propagating project, name and location.
Thanks! I'll use that.

A bit more info about that I'm doing.

I need an alternative to standard copy task . The standard one does not 
preserve permissions on unix systems, can not be told to create 
hardlinks if possible instead of copying,
etc etc, and I need all that. I'm planning to get standard copy task and 
modify it to produce system-dependent script (for windows and for linux) 
and then pass the script to shellscript
task from ant-contrib.

The problem is that I have a lot of filesets, and each of them must be 
copied to its own directory. This way I'm getting a lot of instances of 
modified copy task,
which in turn create many instances of shellscipt task, which do a lot 
of shell/system calls. This last bit makes the whole system very 
fragile, according to our experience.

I think that the best option would be to subclass FileSet and add target 
directory attribute to it. But maybe someone here has a better idea or 
some other hint...

Thanks,
Mikhail

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


Re: Task adapter

Posted by Steve Loughran <st...@apache.org>.
Mikhail Fedotov wrote:
> Hi all,
> 
> I have two existing tasks. I want to modify the first task so that it 
> runs the second one as part
> of its work.
> 
> I have code which creates ant build file with parameters for the second 
> task and then uses
> new instance of AntScenario to run that file. The question is, can I do 
> the same thing without
> creating any extra files ? Can I just create an instance of the second 
> task while executing the
> first one, call needed setter methods and execute it ?

It is easy to delegate stuff to existing tasks, it is how much of ant is 
built underneath.

You can create tasks in two ways.

By asking the project for it:

MyTask task=(Mytask)Project.createTask("my-task");

This is easy but breaks if someone uses presetdef or macrodef to wrap 
your task, because the type of the returned class is wrong.

The alternative is creating and binding by hand:

MyTask task=new MyTask();
task.setProject(getProject());
task.setName(getName());
task.setLocation(getLocation());
task.init();

This is how everything in Ant1.7 does it, though there we cheated add 
added Task.bindToOwner(Task owner) to do the repetitive work of 
propagating project, name and location.

-steve


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