Bug 40093 - ant.PropertyHelper reference not passed to called build
Summary: ant.PropertyHelper reference not passed to called build
Status: REOPENED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.6.5
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2006-07-22 08:39 UTC by Stefano Marsili
Modified: 2009-07-30 06:19 UTC (History)
0 users



Attachments
build.xml showing problem (3.49 KB, application/zip)
2006-07-22 08:42 UTC, Stefano Marsili
Details
Patch to clone PropertyHelper for subbuilds (3.01 KB, patch)
2006-07-26 00:35 UTC, Stefano Marsili
Details | Diff
Cloneable PropertyHelper (1.22 KB, patch)
2006-07-26 00:38 UTC, Stefano Marsili
Details | Diff
Test: custom property helper cloned in subbuilds (5.58 KB, application/zip)
2006-07-26 00:42 UTC, Stefano Marsili
Details
Patches of Ant.java and PropertyFunction.java (patch.xml) (4.28 KB, patch)
2006-07-26 09:19 UTC, Stefano Marsili
Details | Diff
Patches of sources, tests and docu, plus new files (48.71 KB, application/zip)
2006-07-28 13:15 UTC, Stefano Marsili
Details
Corrected PropertyHelper patch.txt (53.90 KB, patch)
2006-07-30 06:47 UTC, Stefano Marsili
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stefano Marsili 2006-07-22 08:39:25 UTC
The reference 'ant.PropertyHelper' isn't passed correctly to
the target of an ant (task) call. If a new PropertyHelper (a subclass of it)
is installed, it is not passed to the called build.
It seems that property expansion is executed before the references 
are passed (with inherirefs="true"). This means that a
standard PropertyHelper instance is created for the reference 
'ant.PropertyHelper' and the new reference is therefore ignored.
Maybe this reference should be treated separately?
See:
- the call to newProject.setInheritedProperty in Ant.execute()
- overrideProperties() calling Property.execute()
Comment 1 Stefano Marsili 2006-07-22 08:42:00 UTC
Created attachment 18624 [details]
build.xml showing problem
Comment 2 Stefano Marsili 2006-07-22 09:37:38 UTC
I see that passing the property helper as reference doesn't even
make sense. Adding a property to the build would (AFAIK) also add
it to the called build, which is wrong. A solution would be
to clone the PropertyHelper if it's subclassed and if an
attribute inheritPropertyHelper="true" is set.
And I guess there are other tasks that would have to implement the same.
Comment 3 Stefano Marsili 2006-07-22 12:16:34 UTC
Sorry for polluting bugzilla. I think the PropertyHelper isn't
conceived for being (cloned and) passed to a sub build, so 
I mark this bug as invalid and live with the limitation.
Comment 4 Stefano Marsili 2006-07-26 00:35:42 UTC
Created attachment 18638 [details]
Patch to clone PropertyHelper for subbuilds

Custom property helper is not passed to subbuilds at all. 
This clones the PropertyHelper if inheritAll
is true (but an additional attribute like 
inheritPropertyHandler may be better).
Comment 5 Stefano Marsili 2006-07-26 00:38:41 UTC
Created attachment 18639 [details]
Cloneable PropertyHelper

This patch declares PropertyHelper as Cloneable.
The implementation sets values as if it where
newly constructed, since properties are set
through the project.
Comment 6 Stefano Marsili 2006-07-26 00:42:04 UTC
Created attachment 18640 [details]
Test: custom property helper cloned in subbuilds

This test should be successful if patches are applied.
Calls subbuilds with ant,antcall,subant.
Comment 7 Stefano Marsili 2006-07-26 00:49:01 UTC
I know not many care about the property helper,
but I think the current behaviour is wrong.
The PropertyHelper class is there to be extended
and Ant should therefore handle it correctly.
The patch implementation clones the PH when inheritAll 
is true, but a new attribute may be defined.
Comment 8 Stefano Marsili 2006-07-26 09:19:18 UTC
Created attachment 18641 [details]
Patches of Ant.java and PropertyFunction.java (patch.xml)

Found out there is the very handy patch.xml build
to create patches for Ant.
Added a missing setProject() in the code.
Comment 9 Stefano Marsili 2006-07-28 13:15:49 UTC
Created attachment 18659 [details]
Patches of sources, tests and docu, plus new files

PropertyHelper patches.
 
Why (the problem): 
  even though it is possible for a custom task to install a 
  new property helper as a hook or even as the main property helper, 
  at present there is no way to pass the helper to subbuilds. 
  The additional data in the PropertyHelper subclass and the hooks 
  are not inherited. 
Proposed solution:
  this patch extends the PropertyHelper interface to install
  and clone PropertyHelper instances in a way suitable to Ant.

** Sources **
PropertyHelper.java:
 - installPropertyHelper(project, newHelper) 
      to install a custom PropertyHelper into a project 
 - clonePropertyHelper(fromProject, newProject, inheritAll)
      to clone a PropertyHelper to a new project and optionally
      copy hooks' properties to their clones
 - areYouOverridableBy(newHelper) method that let's the main 
      property helper decide whether it wants to give up control 
      of the build's property handling to a new helper.

Ant.java, CallTarget.java, SubAnt.java: 
 - new "inheritph" attribute telling whether the property helper
   and its hooks should be cloned to the new project

** Tests **
PropertyHelperTest.java:
 - created new test case, testing installation of property helpers
   and hooks into a project

AntTest.java, CallTargetTest.java:
 - extended to test cloning of property helper and its hooks

** Docu **
Ant.html, AntCall.html, SubAnt.html:
 - added "inheritph" attribute with a small comment

** Note **
Modified and patched against latest 1.70alpha.
The proposed changes should be backward compatible.
Comment 10 Stefano Marsili 2006-07-30 06:47:59 UTC
Created attachment 18662 [details]
Corrected PropertyHelper patch.txt

New in patch:
- added PropertyHelper.installPropertyHelperHook(project, newHook) 
- added minimal SubAntTest.java
- corrected some bugs (setProject on clones,...)

Further corrections, comments, suggestions, motivated refusals are welcome.

I know the bugzilla title no longer reflects the contents 
of the patch and sorry for the many files posted, 
but this was my first patch ever (I'm sure you noticed :-)

Thank you,
Stefano Marsili
Comment 11 Peter Reilly 2006-09-20 09:40:15 UTC
Thanks for the patch, unit tests and doc - this is
great!.