Bug 48804 - import and extension-point / extensionOf not working as documented
Summary: import and extension-point / extensionOf not working as documented
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.8.0
Hardware: PC Windows XP
: P2 normal with 3 votes (vote)
Target Milestone: 1.8.1
Assignee: Ant Notifications List
Depends on:
Reported: 2010-02-23 20:20 UTC by Brian Repko
Modified: 2010-04-27 00:07 UTC (History)
0 users

build file from documentation (223 bytes, text/plain)
2010-02-23 20:23 UTC, Brian Repko
imported file from documentations (294 bytes, text/plain)
2010-02-23 20:23 UTC, Brian Repko
changed ProjectHelper (20.55 KB, text/plain)
2010-02-23 20:24 UTC, Brian Repko
changed ProjectHelper2 (51.46 KB, text/plain)
2010-02-23 20:25 UTC, Brian Repko
working ProjectHelper2 (51.63 KB, text/plain)
2010-02-23 21:20 UTC, Brian Repko
working ProjectHelper (20.55 KB, text/plain)
2010-02-23 21:20 UTC, Brian Repko
Patch for AntUnit testfile for showing this bug (949 bytes, application/octet-stream)
2010-03-20 13:08 UTC, Jan Mat
Consolidated Brian's changes and Jan's testcase (6.34 KB, patch)
2010-04-23 05:18 UTC, Stefan Bodewig
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Repko 2010-02-23 20:20:02 UTC
As per the documentation on extension-points, there is a note that this is designed to be used with imported build files. I tried to create the example given (see attached files) where build.xml imports targets and an extension-point and then adds a dependency via the extensionOf.
This results in an error that the extension-point does not exist, which it doesn't because the import is done after the build is parsed.  I believe that I have the intent correct but that there is a bug in TargetHelper in ProjectHelper2.  I can see that the extensionOf needs to find the other target so that it can add a dependency but that that target doesn't exist since the import stack hasn't been fully popped.
I believe that the fix is to change ProjectHelper2 (I will try to create my own in the short term) to add the extension to a stack which then is processed after the import stack is done.  That is, all extensions should be done after the imports are done.
Comment 1 Brian Repko 2010-02-23 20:23:26 UTC
Created attachment 25043 [details]
build file from documentation
Comment 2 Brian Repko 2010-02-23 20:23:54 UTC
Created attachment 25044 [details]
imported file from documentations
Comment 3 Brian Repko 2010-02-23 20:24:41 UTC
Created attachment 25045 [details]
changed ProjectHelper
Comment 4 Brian Repko 2010-02-23 20:25:05 UTC
Created attachment 25046 [details]
changed ProjectHelper2
Comment 5 Matt Benson 2010-02-23 20:36:37 UTC
Hi, Brian, and thanks for the submission.  Typically the Ant developers are much better able to digest the intent of a change if it is provided as a patch against the svn trunk code.  When you attach your changes in this format, you should also edit the title of the issue so that it begins with [PATCH].

Comment 6 Brian Repko 2010-02-23 20:43:09 UTC
Just tried these against a different scenario and it fails - please don't use these (I can't delete them).

I didn't find any quick setup guide so that I could provide you a patch (I can't get the source bundle to not report errors in Eclipse) so you probably won't get that from me.  I'm assuming you can do a diff.

Comment 7 Brian Repko 2010-02-23 21:20:04 UTC
Created attachment 25047 [details]
working ProjectHelper2
Comment 8 Brian Repko 2010-02-23 21:20:32 UTC
Created attachment 25048 [details]
working ProjectHelper
Comment 9 Robert E. Menteer 2010-02-26 03:16:41 UTC
I'm having this same problem and have found a work around. If your build files look like this:
<project name="imported">
  <extension-point name="extend-this"/>

<project name="importing">
  <import file="imported"/>
  <target name="extending" extentionOf="extend-this"/>

Ant will complain that extend-this does not exist. By wrapping these build files in another Ant will not complain. The initial build files do not need to be modified so the wrapper files can be deleted when this bug is fixed.

<project name="wrapper">
  <import file="imported"/>
  <import file="importing"/>
Comment 10 Jan Mat 2010-03-20 13:08:00 UTC
Created attachment 25155 [details]
Patch for AntUnit testfile for showing this bug

Attached a path for the AntUnit test.
- create imported buildfile (defining extension-point)
- create importing buildfile (enhancing the EP)
- invoking the importing file
- checks for the expected output
Comment 11 Stefan Bodewig 2010-04-23 05:11:31 UTC
Jan, your test would even fail if there was no bug since you never call any target 8-)

I've a modified version of the patch just undergoing ants unit test suite, it breaks at least one test: testExtensionPointMustBeKnown.  This on asserts you can't extend an extension point that is defined later inside the same build file, which is no longer true.

I'll poll the dev list to see whether this change is more of a benefit than a problem.
Comment 12 Stefan Bodewig 2010-04-23 05:18:58 UTC
Created attachment 25340 [details]
Consolidated Brian's changes and Jan's testcase

I have modified Brian's original change to use a linked list rather than a
vector and a two-element string array rather than a map, but these changes are
really minor.
Comment 13 Stefan Bodewig 2010-04-27 00:07:22 UTC
fixed with svn revision 938315