Making Java step in Ant script fail the build - java

Please excuse if the question is dumb, I'm only 2nd day on Ant and Java hacking together some CI solution with next to no knowledge of Ant or Java.
So I wish a build to fail if (my) java program run as a step within the build decides that the build must fail.
I thought of just throwing an unhandled exception in the Java program or using System.exit() to shut down the JVM but they seem quite nasty.
Is there a nice way of ant failing the build if a java step decides it should?

For the <java> task, there is an attribute failonerror. If you set it to yes (or true), the build will fail if the process returned anything else than 0.
The problem is that for returning some value from a java call, this call must System.exit(value). For it to not kill your ant, you also need to provide fork=true to run in a new JVM.
So, the java call could look like this:
<java jar="..."
fork="yes"
failonerror="yes">
</java>
Of course, you could also have your Java program implement the Ant Task API and load/call it as a proper ant task. Then it can itself decide what to do (and will be more configurable, too).

The Ant manual shows a built-in task named Fail which you can configure with specific conditions to make the build fail.
<fail message="Files are missing.">
<condition>
<not>
<resourcecount count="2">
<fileset id="fs" dir="." includes="one.txt,two.txt"/>
</resourcecount>
</not>
</condition>
</fail>
You might want to look into that one.

Ant ought to be straightforward. It does fail a build if a particular step does not succeed. I think the behavior you want is already built-in.
As for your custom step, my advice would be to find a way to do that outside of Ant for now while you get the rest of the CI flow working. Better to make that much progress rather than falling into a hole over one detail.
It might help if you describe what your program is doing. Perhaps there's a better way to accomplish what you need.
UPDATE: I don't think you should head down this path. The tests you run with CC should be unit tests. If you have to package and deploy the application to test, I'd call those integration tests. Run those separately as part of your QA step, not the build.
You're doing the right thing with Selenium; I like your rigor and effort. But I'd recommend running just the unit tests with CC, package and deploy the app to a QA server, then run your Selenium tests as JUnits. They're scripted and fast.
I also wonder about the wisdom of using Selenium to check for widget placements in the UI. That seems brittle to me; best left to a human.
Here's a generic Ant build that I re-use often. Feel free to use it as reference. Keep telling yourself "This ought to be simple." IF it gets too hard, you're doing it wrong.
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>

Related

Run multiple JUnit tests with Ant

probably this is a very basic question but I am new to java, so please bear with me.
I am trying to run java task in ant and I want to know if there is any way to get all the name of the classes inside a folder in ant?
This is the build.xml file
<project default='run-test' basedir=".">
<property name="src" value="src"/>
<property name="test" value="test"/>
<property name="build" value="build"/>
<property name="build-classes" value="build/classes"/>
<property name="build-test-classes" value="build/test/classes"/>
<property name="junit4" value="/usr/share/java/junit4.jar"/>
<target name="init">
<mkdir dir="${build-classes}"/>
<mkdir dir="${build-test-classes}"/>
</target>
<target name="compile" depends="init">
<javac includeantruntime="false"
srcdir="${src}"
destdir="${build-classes}"/>
</target>
<target name="compile-test" depends="compile">
<javac includeantruntime="false"
classpath="${junit4}:${build-classes}"
srcdir="${test}"
destdir="${build-test-classes}"/>
</target>
<target name="run-test" depends="compile-test">
<java classpath="${junit4}:${build-classes}:${build-test-classes}"
classname="org.junit.runner.JUnitCore"
args="myclass.MyClassTest"/> <---This is my problem
</target>
<target name="clean">
<delete dir="${build}"/>
</target>
</project>
I have to manually mention the name of the class in the arguments.
Is there any way where I can only mention the folder and all the class names will be taken up as arguments for the javatask automatically?
Ant ships with a task for running JUnit tests.
In the run-test target in your example, replace the <java> task with the following:
<junit>
<formatter type="plain" usefile="false"/>
<classpath>
<pathelement location="${junit4}"/>
<pathelement location="${build-classes}"/>
<pathelement location="${build-test-classes}"/>
</classpath>
<batchtest>
<fileset dir="${build-test-classes}">
<include name="**/*.class"/>
</fileset>
</batchtest>
</junit>

dataDriven excel - ant via commandLine( testng ant webdriver)

I can run my tests via Ant in IDE.
But, While i try to run it from Command Line - it fails, because cant find the Excel from Resources
I added:
`<copy todir="test/Resources/Data">
<fileset dir="${Resources}/Data">
<exclude name="**/*.java"/>
</fileset>
</copy>`
the file copied but still fail.
Looks like code doesnt look in correct place..
Any idea?
full build.xml:
<project name="TestNGTest" default="test" basedir=".">
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/testng-6.8.5.jar"/>
</classpath>
</taskdef>
<property name="testdir" location="test" />
<property name="srcdir" location="src" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<property name="Resources" location="Resources"/>
<copy todir="test/Resources/Data">
<fileset dir="${Resources}/Data">
<exclude name="**/*.java"/>
</fileset>
</copy>
<path id="classpath.base"/>
<path id="classpath.test">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${testdir}" />
<pathelement location="${srcdir}" />
<path refid="classpath.base" />
</path>
<target name="clean" >
<delete verbose="${full-compile}">
<fileset dir="${testdir}" includes="**/*.class" />
</delete>
</target>
<target name="compile" depends="clean">
<javac srcdir="${srcdir}" destdir="${testdir}"
verbose="${full-compile}">
<classpath refid="classpath.test"/>
</javac>
</target>
<target name="test" depends="compile">
<testng outputdir=".test-output" classpathref="classpath.test"
useDefaultListeners="false"
listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
<xmlfileset dir="." includes="testng.xml"/>
</testng>
</target>
</project>'
i found the problem.
in code i use the System.getProperty("user.dir") and when running from ant it finds my "user" folder.
So i can manually put there the excel ant it works.
Now, i need to find the way to change the System.getProperty("user.dir") to something that points to projects root

Mysterious Ant script

I have problem with my Ant script. I have to run junit test on ant run.
My current script looks like:
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="doc" location="doc"/>
<property name="dist" location="dest"/>
<property name="lib" location="lib"/>
<property name="app" value="${ant.project.name}.jar"/>
<presetdef name="javac">
<javac includeantruntime="false"/>
</presetdef>
<target name="clean">
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
<target name="compile" depends="clean" description="Compile">
<mkdir dir="${build}"/>
<javac srcdir="${src}"
destdir="${build}"
classpath="${lib}/junit-4.10.jar:${lib}/swing-layout-1.0.4.jar:${src}">
</javac>
<copy todir="${build}/checkers">
<fileset dir="${lib}">
<include name="resources/**" />
</fileset>
</copy>
</target>
<target name="run" depends="compile">
<echo>Running the junit tests...</echo>
<junit showoutput="no" fork="no">
<classpath>
<pathelement location="${build}"/>
<pathelement path="${build}:${lib}/junit-4.10.jar"/>
</classpath>
<formatter type="plain" usefile="false" />
<test name="checkers.CheckersTest"/>
</junit>
</target>
On my Linux box test runs fine and everything looks good. But on my Windows, Ant gives my nice:
java.lang.NoClassDefFoundError: junit/framework/TestListener
Ant in debug mode however told me that he loaded TestListener.class from suplied junit-4.10.jar file.
Try this answer http://youtrack.jetbrains.com/issue/TW-4882:
To fix the problem you should either use fork="true" attribute for
junit task (in this case classpath will be created correctly), or
to copy junit.jar to ANT_HOME/lib (to ensure correct class loading).
Here is also bug for this https://bugs.eclipse.org/bugs/show_bug.cgi?id=36198. Last comment says JUnit is available in Ant via the org.eclipse.ant.optional.junit fragment

Help setting up a Java build environment

I'm at my wit's end. I'm spending more time working on getting my build to work rather than actually developing software. I'm currently working on large-scale Java web application based on Tomcat 6.
Currently the code-base is about 25k LOC (although that's not quite representative because some of that is autogenerated for web services -- but the take away is that it's big) and I've been working exclusively with eclipse to do everything from debugging, to build path management to building. In the past, eclipse has always been more than enough, but I've never worked on a project this large before.
The first problem I had was when I started adding GWT content. It worked ok, but the build process was a bit hacky: I had to manually compile and then copy the js output into the appropriate directory and debugging was a nightmare (I realize some of those problems are just GWT and the way it works...). Now, the issue I'm running into is attempting to work on the project on a Windows machine (I had been working on a Mac, and will continue to work from a Mac from time to time). Eclipse added the Mac OS JVM libraries to the build path which, of course, Windows can't find.
I asked a question about working in two different environments and most of the answers pertained to using a build tool like Ant+Ivy or Maven. I've started investigating Maven and attempting to get my project to use it, but it's just been one headache after another and I haven't even begun to try to actually execute/debug my application in Tomcat through eclipse. The most frustrating part of all of this is it, to me, seems like these build tools are exceptionally complex (and to be fair, incredibly flexible) but, at least initially, make life even more difficult while you try to figure out how to simply compile a Java file.
So all of that to say, does anybody have suggestions for how to simplify this scenario? Dependency management would be nice, but I don't mind hunting down the JARs myself. The biggest thing I need is something that will just get out of my way and let me work on what I'm actually trying to work on, not spend hours debugging my typos in an xml file used by the build system.
Thanks in advance
I agree. You don't need Maven; you don't need Ivy. Start with Ant.
Here's a relatively generic Ant build.xml. Customize it as you wish.
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>
while maven may be a bit daunting at first glance, i think it really is a pretty nice tool. yes, it does have it's warts, but all in all i think it's one of the best choices for java. the "thing" you really need to get about maven is that everything is based on convention. if you do everything the conventional maven way, then your maven pom is generally very small and everything "just works". and there is plenty of getting started info out there to show you what the "maven convention" is. (and yes, you usually can do things your own way, but it's usually not worth it unless you are stuck w/ an existing project which would be difficult to re-organize).
There are alternatives to Ant/Ivy or Maven XML that might be worth a gander. They use a real programming language instead of an XML DSL.
http://buildr.apache.org/ (Ruby based)
http://www.gradle.org/index.php (Groovy based)
One simplification you can use when working solely in Eclipse is to let Eclipse take care of the compilation. A given project can have its own simple Ant script, which packages up whatever is need from bin into a jar.

Yet another Ant + JUnit classpath problem

I'm developing an Eclipse SWT application using Eclipse. There are also some JUnit 4 tests, which test some DAO's. But when I try to run the tests via an ant build, all of the tests fail, because the test classes aren't found.
Google brought up about a million of people who all have the same problem, but none of their solutions seem to work for me -.- .
These are the contents of my build.xml file:
<property name="test.reports" value="./test/reports" />
<property name="classes" value="build" />
<path id="project.classpath">
<pathelement location="${classes}" />
</path>
<target name="testreport">
<mkdir dir="${test.reports}" />
<junit fork="yes" printsummary="no" haltonfailure="no">
<batchtest fork="yes" todir="${test.reports}" >
<fileset dir="${classes}">
<include name="**/Test*.class" />
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="project.classpath" />
</junit>
<junitreport todir="${test.reports}">
<fileset dir="${test.reports}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reports}" />
</junitreport>
</target>
The test classes are in the build-directory together with the application classes, although they are in some subfolders according to their packages.
Maybe this is important too: At first Ant complained that JUnit wasn't in its classpath, but since I put it there (with the eclipse configuration editor) it complains about JUnit being in its classpath twice.
WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:C:/Users/as df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] and jar:file:/C:/Users/as%20df/Documents/eclipse/plugins/org.apache.ant_1.7.1.v20090120-1145/lib/ant.jar!/org/apache/tools/ant/Project.class
I've tried specifying each and every subdirectory, each and every class file, I've tried filesets and filelists, nothing seems to work.
Thanks for your help, I've been sitting for hours on this thing now...
I was getting this only when using the 'fork=true' option to the junit task. It was happening because my ANT_HOME had '..' in it (e.g. '/3rdparth/jboss/jboss-5/../tools'). Once I reduced that path, the 'multiple versions of ant' warning went away.
I had the same problem 'multiple versions of ant detected in path for junit'. The problem went away when I renamed by Eclipse_Home directory and removed special characters from it. The path had '[1]' in it which was causing the problem.
This Ant build.xml works fine for me. Check out the properties to see if the directory structure matches yours; adjust as needed.
<?xml version="1.0" encoding="UTF-8"?>
<project name="xslt-converter" basedir="." default="package">
<property name="version" value="1.6"/>
<property name="haltonfailure" value="no"/>
<property name="out" value="out"/>
<property name="production.src" value="src"/>
<property name="production.lib" value="lib"/>
<property name="production.resources" value="config"/>
<property name="production.classes" value="${out}/production/${ant.project.name}"/>
<property name="test.src" value="test"/>
<property name="test.lib" value="lib"/>
<property name="test.resources" value="config"/>
<property name="test.classes" value="${out}/test/${ant.project.name}"/>
<property name="exploded" value="out/exploded/${ant.project.name}"/>
<property name="exploded.classes" value="${exploded}/WEB-INF/classes"/>
<property name="exploded.lib" value="${exploded}/WEB-INF/lib"/>
<property name="reports.out" value="${out}/reports"/>
<property name="junit.out" value="${reports.out}/junit"/>
<property name="testng.out" value="${reports.out}/testng"/>
<path id="production.class.path">
<pathelement location="${production.classes}"/>
<pathelement location="${production.resources}"/>
<fileset dir="${production.lib}">
<include name="**/*.jar"/>
<exclude name="**/junit*.jar"/>
<exclude name="**/*test*.jar"/>
</fileset>
</path>
<path id="test.class.path">
<path refid="production.class.path"/>
<pathelement location="${test.classes}"/>
<pathelement location="${test.resources}"/>
<fileset dir="${test.lib}">
<include name="**/junit*.jar"/>
<include name="**/*test*.jar"/>
</fileset>
</path>
<path id="testng.class.path">
<fileset dir="${test.lib}">
<include name="**/testng*.jar"/>
</fileset>
</path>
<available file="${out}" property="outputExists"/>
<target name="clean" description="remove all generated artifacts" if="outputExists">
<delete dir="${out}" includeEmptyDirs="true"/>
<delete dir="${reports.out}" includeEmptyDirs="true"/>
</target>
<target name="create" description="create the output directories" unless="outputExists">
<mkdir dir="${production.classes}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${reports.out}"/>
<mkdir dir="${junit.out}"/>
<mkdir dir="${testng.out}"/>
<mkdir dir="${exploded.classes}"/>
<mkdir dir="${exploded.lib}"/>
</target>
<target name="compile" description="compile all .java source files" depends="create">
<!-- Debug output
<property name="production.class.path" refid="production.class.path"/>
<echo message="${production.class.path}"/>
-->
<javac srcdir="src" destdir="${out}/production/${ant.project.name}" debug="on" source="${version}">
<classpath refid="production.class.path"/>
<include name="**/*.java"/>
<exclude name="**/*Test.java"/>
</javac>
<javac srcdir="${test.src}" destdir="${out}/test/${ant.project.name}" debug="on" source="${version}">
<classpath refid="test.class.path"/>
<include name="**/*Test.java"/>
</javac>
</target>
<target name="junit-test" description="run all junit tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<junit printsummary="yes" haltonfailure="${haltonfailure}">
<classpath refid="test.class.path"/>
<formatter type="xml"/>
<batchtest fork="yes" todir="${junit.out}">
<fileset dir="${test.src}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${junit.out}">
<fileset dir="${junit.out}">
<include name="TEST-*.xml"/>
</fileset>
<report todir="${junit.out}" format="frames"/>
</junitreport>
</target>
<taskdef resource="testngtasks" classpathref="testng.class.path"/>
<target name="testng-test" description="run all testng tests" depends="compile">
<!-- Debug output
<property name="test.class.path" refid="test.class.path"/>
<echo message="${test.class.path}"/>
-->
<testng classpathref="test.class.path" outputDir="${testng.out}" haltOnFailure="${haltonfailure}" verbose="2" parallel="methods" threadcount="50">
<classfileset dir="${out}/test/${ant.project.name}" includes="**/*.class"/>
</testng>
</target>
<target name="exploded" description="create exploded deployment" depends="testng-test">
<copy todir="${exploded.classes}">
<fileset dir="${production.classes}"/>
</copy>
<copy todir="${exploded.lib}">
<fileset dir="${production.lib}"/>
</copy>
</target>
<target name="package" description="create package file" depends="exploded">
<jar destfile="${out}/${ant.project.name}.jar" basedir="${production.classes}" includes="**/*.class"/>
</target>
</project>

Categories