Guylene Emond
Guylene Emond

Reputation: 261

ant multiple target to execute

I have few target that I need to execute. I create a target naming all of them but I think it's not the way to do it ? Here is the target run that call all other target :

<target name="test.all" depends="build
echolaunching agent /echo
antcall target="RunJtfTests" /
antcall target="launchOpenAgent" /
antcall target="run.test" //target
target name="run.test" depends="build, launchOpenAgent, runJtfTests"
echo Launching test/echo
echo message="${toString:iControlSilk4J.classpath}" /
  <java classname="com.miranda.icontrol.silk4j.installation.AdministrationCtrl"
classpath><fileset dir="${lib.dir}"
include name="**/*.jar" />
/fileset
pathelement path="${iControlSilk4J.classpath}" /
pathelement location="${jarPath}/Admin.jar" /
/classpath
  </java>
</target>

It doesn't run and I do it to get the report and I get nothing ? What is wrong ? From what I read, antcall is like a goto loop which is not good. I want to call tests instead.

-> Here are all the tests I want to execute :

but this can be more general (regarding tests I will add in Silk4J). Is there a way to be more generic ?

Upvotes: 1

Views: 9459

Answers (1)

David W.
David W.

Reputation: 107060

Repeat after me:

Ant is not a programming language. It's a dependency matrix language.

This is an important distinction. You don't tell Ant what to execute. You tell Ant what you need, and Ant will figure out what to do.

I can tell you're having problems understanding Ant with all of those <antcall/>. That is a no-no because it could make you execute tasks more than once. Your build file also makes no sense.

Use the target's dependency parameter. For example, here's a skeleton build.xml file:

<project>
    <target name="clean"/>

    <target name="prepare"/>

    <target name="compile"
        depends="prepare"/>

    <target name="package"
         depends="compile"/>

    <target name="test-compile
         depends="compile"/>

    <target name="test"
         depends="test-compile"/>

    <target name="deploy"
         depends="package"/>

    <target name="post-test-results"
         depends="test"/>

    <target name="all"
         depends="clean,post-test-results,deploy"/>
</project>

When I want to run my target all, I mainly mean I want to do a clean build, post my test results, and deploy the build. This is true with Makefiles too. I don't list all of my tasks. Why do I care if I do my prep work for compilation? It's not my concern.

So I call, all, and that will call clean, post-test-results, and deploy. I have no idea what Ant will do beyond calling these three targets.

Wait... What do I need to do in order to post my test results? Well, I may need to run my tests. Therefore, I have a dependency to test for my post-test-results target. But, in order to run my tests, I may have to compile them. So, there's a dependency to test-compile on my test target.

In order to compile my tests, I have dependencies on the regular Java code. So, test-compile will depend upon compile. In order to compile, I have to prepare. Maybe that's building the necessary structure, or downloading the required jars. That's called before compile. Now, I can deploy. However, before I can deploy, I need to package my deployment. So, deploy depends upon package.

Package itself depends upon compile, but so did my compile-test. Since I've already called compile, my package target doesn't have to do that. All it has to do is package up the already compiled class files.

Thus, I'll probably execute the following targets in this order:

  • clean
  • prepare
  • compile
  • test-compile
  • post-test-results
  • package
  • deploy

My all target does hit all of my other targets, but I didn't have to list them all as dependencies or force them to build via <antcall/>s.

It looks like you need to learn about Ant and how it works. Your sample Ant file is simply not valid. Ant uses an XML style structure. All tasks are XML style entities.

Fortunately, there are a lot of good books on Ant. I would recommend Manning's Ant in Action as a good starting point.

One of the things you will find out is that you can specify batches of junit tests in a single <junit> task. This can be done via one or more <batchtest> sub-entities on the <junit> task. The <batchtest> will run all classifies that match a particular criteria. You can also use the <test> sub-entity on the <junit> task. The <test> sub-entity allows you to specify individual classfiles to run. Many times, these classfiles may simply call a specified set of other Junit classifies. This way, the developer can specify what tests to run and what tests to skip.

You can control what tests to run or not run by using properties and not by creating dozens of testing tasks. This allows you to specify sets of tests without having to spawn multiple JUnit processes.

Upvotes: 9

Related Questions