|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Problem regarding adding antcall task to some target via JavaScript and script taskHi,
I have a problem with the following build script: ========================= <?xml version="1.0" encoding="UTF-8"?> <project name="Test" default="test"> <macrodef name="appendExecutionOf"> <attribute name="target" /> <attribute name="toTarget" /> <sequential> <script language="javascript"> <![CDATA[ targetName = "@{target}" toTargetName = "@{toTarget}" toTarget = project.getTargets().get(toTargetName) antcall = project.createTask("antcall") antcall.setTarget(targetName) toTarget.addTask(antcall) println("Added task <antcall target=\"" + targetName + "\"/> to target \"" + toTarget + "\"") ]]> </script> </sequential> </macrodef> <target name="init"> <echo>Hello from target 'init'</echo> <appendExecutionOf target="extra-pre-test" toTarget="pre-test" /> <appendExecutionOf target="extra-post-test" toTarget="post-test" /> </target> <target name="extra-pre-test"> <echo>Hello from target 'extra-pre-test'</echo> </target> <target name="extra-post-test"> <echo>Hello from target 'extra-post-test'</echo> </target> <target name="pre-test"> <echo>Hello from target 'pre-test'</echo> </target> <target name="post-test"> <echo>Hello from target 'post-test'</echo> </target> <target name="test" depends="init"> <antcall target="pre-test"/> <echo>Hello from target 'test'</echo> <antcall target="post-test"/> </target> </project> ========================= This is purposing the follwing: Adding execution of additional targets (here "extra-pre-test" and "extra-post-test") to some other targets (here "pre-test" and "post-test", respectively) depending on environmental properties (not shown here for simplicity). I'm trying to achieve this using the macro "appendExecutionOf", which uses JavaScript to add a new <antcall> task to the intended target. But unfortunalety this does not work as expected: ========================= $ ant Buildfile: build.xml init: [echo] Hello from target 'init' [script] Added task <antcall target="extra-pre-test"/> to target "pre-test" [script] Added task <antcall target="extra-post-test"/> to target "post-test" test: pre-test: [echo] Hello from target 'pre-test' [echo] Hello from target 'test' post-test: [echo] Hello from target 'post-test' BUILD SUCCESSFUL Total time: 0 seconds ========================= I would expect something like this: ========================= [...] init: [echo] Hello from target 'init' [script] Added task <antcall target="extra-pre-test"/> to target "pre-test" [script] Added task <antcall target="extra-post-test"/> to target "post-test" test: pre-test: [echo] Hello from target 'pre-test' [echo] Hello from target 'extra-pre-test' // <= ADDITIONAL LINE [echo] Hello from target 'test' post-test: [echo] Hello from target 'post-test' [echo] Hello from target 'extra-post-test' // <= ADDITIONAL LINE [...] ========================= So my question is: Am I missing something important with my JavaScript macro? Or might this be a bug? Any help appreciated. Thanks and regards Christian -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Problem regarding adding antcall task to some target via JavaScript and script taskOn 2009-10-12, Christian Möller <dcmoeller@...> wrote:
> <target name="init"> > <echo>Hello from target 'init'</echo> > <appendExecutionOf target="extra-pre-test" toTarget="pre-test" /> > <appendExecutionOf target="extra-post-test" toTarget="post-test" /> > </target> > <target name="test" depends="init"> > <antcall target="pre-test"/> > <echo>Hello from target 'test'</echo> > <antcall target="post-test"/> > </target> > This is purposing the follwing: Adding execution of additional targets > (here "extra-pre-test" and "extra-post-test") to some other targets > (here "pre-test" and "post-test", respectively) depending on > environmental properties (not shown here for simplicity). > But unfortunalety this does not work as expected: Your macro (which looks fine, that's why I snipped it) adds a new task to a target in the currently executing Project instance. In your test you try to validate that it worked via antcall which creates a new Project instance and re-parses the build file for that new instance - your macro has never been executed for this instance and so the tasks have never been added there. If you try <target name="test" depends="init, pre-test"/> you should see you extra-pre-test. Alternatively make pre-test and post-test depend on init so the tasks get added in their Project instance even in the presence of antcall. Stefan --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Problem regarding adding antcall task to some target via JavaScript and script taskHi Stefan,
-------- Original-Nachricht -------- > Von: Stefan Bodewig <bodewig@...> > On 2009-10-12, Christian Möller <dcmoeller@...> wrote: > > <target name="init"> > > <echo>Hello from target 'init'</echo> > > <appendExecutionOf target="extra-pre-test" toTarget="pre-test" /> > > <appendExecutionOf target="extra-post-test" toTarget="post-test" /> > > </target> > > > <target name="test" depends="init"> > > <antcall target="pre-test"/> > > <echo>Hello from target 'test'</echo> > > <antcall target="post-test"/> > > </target> > > > This is purposing the follwing: Adding execution of additional targets > > (here "extra-pre-test" and "extra-post-test") to some other targets > > (here "pre-test" and "post-test", respectively) depending on > > environmental properties (not shown here for simplicity). > > > But unfortunalety this does not work as expected: > > Your macro (which looks fine, that's why I snipped it) adds a new task > to a target in the currently executing Project instance. In your test > you try to validate that it worked via antcall which creates a new > Project instance and re-parses the build file for that new instance - > your macro has never been executed for this instance and so the tasks > have never been added there. Tank you very much, I got it myself - by a strange coincidence at roughly the same time as you wrote your helpful answer :-). So your reply confirms my own conclusions. In the light of your explanation <antcall> does not only "Call another target within the same buildfile optionally specifying some properties [...]" as stated in the docs. Maybe it's worth emphasizing in the docs that a *new project* is instantiated, isn't it? > If you try > > <target name="test" depends="init, pre-test"/> > > you should see you extra-pre-test. Alternatively make pre-test and > post-test depend on init so the tasks get added in their Project > instance even in the presence of antcall. My solution now looks something like this: [...] <target name="init"> <echo>Target 'init'</echo> <appendExecutionOf target="extra-pre-main" toTarget="pre-main" /> <appendExecutionOf target="extra-post-main" toTarget="post-main" /> </target> <target name="extra-pre-main"> <echo>Target 'extra-pre-main'</echo> </target> <target name="extra-post-main"> <echo>Target 'extra-post-main'</echo> </target> <target name="pre-main"> <echo>Target 'pre-main'</echo> </target> <target name="post-main"> <echo>Target 'post-main'</echo> </target> <target name="do-main"> <echo>Target 'main'</echo> </target> <target name="main" depends="init, pre-main, do-main, post-main"/> Thanks again. Christian -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01 --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
| Free embeddable forum powered by Nabble | Forum Help |