ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: Adding equals() and hashCode() methods to Task and Target
Date Tue, 28 Feb 2006 16:19:15 GMT
Robert Smith wrote:
> Hi all,
> 
> Quite some time ago, I wrote a RemoteAnt implementation to allow
> portions of an Ant build to run remotely with synchronous logging back
> to the main Ant instance. You can find it at
> http://confluence.public.thoughtworks.org/display/CC/RobertsRemoteAnt.

Yes, I'm aware of it, its on the general list of "abuses of Ant", but on 
the mild scale compared to GridAnt or (possibly) Askalon.

> 
> I've hit a problem with the XmlLogger class, however. The XmlLogger
> uses a hashtable to store references to tasks and targets as the build
> progresses. The problem is that the Task and Target classes do not
> overide the equals() and hashcode() methods. This causes problems for
> me as I am creating local Tasks and Targets to represent those running
> on the remote machine. However, when the XmlLogger goes to check the
> hashtable when a Task completes, it's not finding the local Task that
> was created when the remote Task started.
> 
> Would it be possible to implemnent the equals() and hashCode() methods
> for Task and Target using only String values (such as project name,
> task name, etc.)?

Target, yes, easy. Just running the tests to see if anything breaks and 
I'll check it in if all is well. The biggest risk is if anything changes 
the name of a target, you break the immutability rule of hashCode. 
Still, the equality check is in sync.

For Task,  I'd have to ask the team to see if things break, primarily 
because so many people subclass it in interesting ways,and use them a 
lot of embedded places. It makes me, nervous. For example, what if the 
XmlLogger is running two tasks with the same name in parallel? Right now 
they are unique, but if you go off task name, everything breaks; they 
should really be scoped by some unique id which may be the full path to 
the component

Actually, target could have the same problem here, once you get into 
antcall - I dont think the name of a target is unique enough to identify 
a target uniquely on a sufficiently complex build. This makes me nervous 
about committing my pending changes to Target.

If its just the logger, dont you really need a special remote task 
logger instead of trying to use local classes as proxies for the distant 
ones. Or, we tune XmlLogger to store things differently, perhaps by 
giving every task/target a unique ID, which could just be a number 
allocated by a synchronized counter.

-Steve

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


Mime
View raw message