ant-ivy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jarosław Wypychowski <>
Subject Re: "ant call trigger can only be used from an ant build" from ant build
Date Thu, 10 May 2007 10:14:58 GMT

I did found the source of problem - and the solution.

The problem is in fact architectural. 

In my scenario there is a chain of events:

The whole process is in a single Thread. 
so when we are in first ant-call - we override the parent Project
settings. When we are in second - we override the parent Project. Ant
build call creates a new project internally in execute of <ant/> task.
So in the original scenario it would fail if the task already finished
and GC cleaned the project. So the comment in my proposal was cleanly
accidental in its help. 
Unfortunately going from WeakRef to direct save will not help either -
as we will again override parent's project. There needs to be a complete
change in the way the Project is kept within context.

You might not like my solution - so please tell me how it should look
like to fit Your design.

I've added specialized methods into the IvyContext:
	public void setAntProject(Project project){
		List l=(List)_contextMap.get(IvyTask.ANT_PROJECT_CONTEXT_KEY);
			l=new ArrayList();
			_contextMap.put(IvyTask.ANT_PROJECT_CONTEXT_KEY, l);
	public void unsetAntProject(Project project){
		List l=(List)_contextMap.get(IvyTask.ANT_PROJECT_CONTEXT_KEY);

	public void unsetAntProject(){
		List l=(List)_contextMap.get(IvyTask.ANT_PROJECT_CONTEXT_KEY);
	public Project getAntProject(){
		List l=(List)_contextMap.get(IvyTask.ANT_PROJECT_CONTEXT_KEY);
		if(l==null || l.size()==0){
			return null;
		return (Project)l.get(0);

And modified get(String) into:

	public Object get(String key) {
		if(IvyTask.ANT_PROJECT_CONTEXT_KEY.equals(key)) return
		if(_contextMap.get(key) instanceof WeakReference){
			WeakReference ref = (WeakReference) _contextMap.get(key);
			return ref == null ? null : ref.get();
		} else {
			return _contextMap.get(key);

Next I added doExecute as You suggested and made it stack a project on
and off in the IvyTask.execute():
    public void execute() throws BuildException {

Now Projects are stacked during the execution of IvyTasks in single
thread and removed when not needed anymore. Now all my tasks are going
without errors.

Personally I don't really like the solution above (it mixes IvyTask with
IvyContext) - so please suggest a better way. 
And If You would like me to finish the patch - what format of the patch
would you like ? (diff params ?)

Best Regards


Jaroslaw Wypychowski
Interdyscyplinarne Centrum Modelowania Matematycznego i Komputerowego UW

View raw message