Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to call an ant target when overriding the target in a child file

Tags:

target

ant

i have a project that uses a parent ant file

similar to this:

<project name="some-portlet" basedir="." default="deploy">  
  <import file="../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 ?

like image 518
nheid Avatar asked Sep 12 '11 20:09

nheid


People also ask

How do I override property value in ant?

Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it. This way: Anything set at the command line takes precedence over build.

How do you call an ant?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

What is Antcall target?

When a target is invoked by antcall , all of its dependent targets will also be called within the context of any new parameters. For example. if the target doSomethingElse ; depended on the target init , then the antcall of doSomethingElse will call init during the call.


2 Answers

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> 
like image 115
Alexander Pogrebnyak Avatar answered Sep 30 '22 02:09

Alexander Pogrebnyak


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>
like image 35
nheid Avatar answered Sep 30 '22 03:09

nheid