You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ja...@rzf.fin-nrw.de on 2004/02/13 16:43:46 UTC

RE: Calling Ant from a Java main?

You should have a look at CruiseControl and Gump.
Or AntHill, ...

Jan

> -----Original Message-----
> From: DDU DUQUENNOY Didier [mailto:dduquennoy@sofaxis.com]
> Sent: Friday, February 13, 2004 4:45 PM
> To: Ant Users List
> Subject: Calling Ant from a Java main?
> 
> 
> Hi,
> 
> I'm (still) trying to automate the run of the junit tests of 
> all my modules, running Ant 1.6.0 on a Windows 2000 machine.
> Each module has a build.xml script with a 'test' task 
> defined. The test task first compile the classes and then run 
> a junit task which outputs a XML file.
> I want to be able to invoke all these tasks and then build a 
> report using <junitreport>.
> 
> The problem I'm facing are:
> - if a module doesn't compile, I want the next module to be tested. 
> - if a module doesn't compile I'd like to be able to see it 
> in the final report
> 
> I first thought of a main script like this :
> 
>   <target name="runtests" depends="clean">
>     <ant dir="${root}/module1" target="test"/>
>     <ant dir="${root}/module2" target="test"/>
>     [...]
>   </target>
> 
> but it isn't OK because the run will stop if a module doesn't compile.
> 
> So I though of writing a main java class to call my ant 
> scripts. I should then be able to detect the failure of a 
> test a do what I want then.
> Here are the techniques I tried:
> 
> - use java.lang.Runtime.exec(<cmd line>) : I go asynchronous 
> and I can't check the state of the run
> 
> - use org.apache.tools.ant.launch.Launcher : the first script 
> runs, but it seems that there is a System.exit() after :-(
> 
> - use or a ProjectHelper to build the project :
>       ProjectHelper.getProjectHelper();
>       Project project = new Project();
>       helper.parse(project, xmlFile);
>       Target target = (Target)targetTable.get("test");
>       target.execute();
> 
>   but I get an error "Could not create task or type of type: 
> junit". But junit.jar and all the contents of Ant1.6/lib is 
> in my classpath
> 
> - use of org.apache.tools.ant.taskdefs.Ant to simulate a <ant 
> dir="${root}/module1" target="test"/> :
>       Ant antTask = new Ant();
>       antTask.setProject(new Project());
>       antTask.setAntfile(xmlFile);
>       antTask.setTarget("test");
>       antTask.execute();
> 
>   but I get an error "Could not create task or type of type: 
> property". (???)
> 
> Well, how can I do the trick?
> 
> Didier D
> 
> ______________________________________________________________
> ___________________________________________
> Ce message (et toutes les pièces jointes) sont confidentiels 
> ; son contenu ne représente en aucun cas un engagement de la 
> part de DEXIA SOFAXIS. Toute publication, utilisation ou 
> diffusion, même partielle, doit être autorisée préalablement 
> par l'émetteur. 
> 
> Si vous n'êtes pas destinataire de ce message, merci d'en 
> avertir immédiatement l'expéditeur.
> 
> Conformément aux dispositions de la loi n° 78-17 du 6 janvier 
> 1978 relative à l'informatique, aux fichiers et aux libertés, 
> vous pouvez obtenir communication et, le cas échéant, 
> rectification ou suppression des informations vous concernant 
> en vous adressant à DEXIA SOFAXIS - Route de Creton - 18110 VASSELAY
> 
> 
> ______________________________________________________________
> ___________________________________________
> Consultez notre site internet http://www.sofaxis.com
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>