how to call an ant target when overriding the target in a child file
i have a project that uses a parent ant file
similar to this:
<project name="some-portlet" basedir="." default="deploy">
<import file=".开发者_如何学Python./build-common-portlet.xml" />
<target name="test">
<echo message="do foo"/>
RUN TEST FROM PARENT HERE
</target>
</project>
now i want to override the parent test target in this way:
- do some copying of jars needed
- run the test target from the parent file
the first part is no problem, but i do not see a way to call test from the parent file
i want the target to be named test also, so that CI can simply run the test target.
is there a way to call test in ../build-common-portlet.xml ?
The simplest way is to use dependency on parent's test.
For that it's important that you keep <project>
name attribute in sync with its file name ( OK that's not, strictly speaking, necessary, but greatly improves your script's readability and maintainability ).
So in build-common-portlet.xml:
<project
name="build-common-portlet" <-- note the name
...
>
<target name="test">
<echo message="Calling parent test target"/>
...
</target>
</project>
That way you can just do:
<project name="some-portlet" basedir="." default="deploy">
<import file="../build-common-portlet.xml" />
<target name="test"
depends="build-common-portlet.test" <-- note parent specification
>
<echo message="do foo"/>
RUN TEST FROM PARENT HERE
</target>
</project>
>> In reply to comment
If you want to do some work before running parent's test, just create a new target and put dependency on it before parent's test:
<project name="some-portlet" basedir="." default="deploy">
<import file="../build-common-portlet.xml" />
<target name="copy-jars">
<echo message="copying jars"/>
</target>
<target name="test"
depends="
copy-jars,
build-common-portlet.test
"
/>
</project>
I found a solution, that would run my commands and then call test from the parent ant file. Override the parent's test, then call when the parent's test once you've done your own "magic".
All other parent's targets can be called too.
So for somebody not knowing your ant file, she can call ant test the way it's expected.
<project name="some-portlet" basedir="." default="deploy">
<import file="../build-common-portlet.xml" />
<target name="test">
<echo message="do foo"/>
<ant antfile="../build-common-portlet.xml" target="test"/>
</target>
</project>
精彩评论