Fixed ant build.

This commit is contained in:
Phil Steitz 2016-01-02 10:30:49 -07:00
parent 8a8ca83f25
commit 75676e5d4e
2 changed files with 32 additions and 39 deletions

View File

@ -30,12 +30,12 @@
<!-- ========== External Dependencies ===================================== --> <!-- ========== External Dependencies ===================================== -->
<property name="repository" value = "${user.home}/.m2/repository"/>
<!-- Junit --> <!-- Junit -->
<property name="junit.version" value="4.8.2"/> <property name="junit.version" value="4.11"/>
<property name="junit.home" value="/usr/share/junit"/> <property name="junit.jar" value="$junit-{junit.version}.jar"/>
<property name="junit.jar" value="${junit.home}/junit-${junit.version}.jar"/> <property name="hamcrest.jar" value="hamcrest-core-1.3.jar"/>
<!-- ========== Component Declarations ==================================== --> <!-- ========== Component Declarations ==================================== -->
@ -111,6 +111,7 @@
<!-- External dependency classpath --> <!-- External dependency classpath -->
<path id="downloaded.lib.classpath"> <path id="downloaded.lib.classpath">
<pathelement location="${download.lib.dir}/junit-${junit.version}.jar"/> <pathelement location="${download.lib.dir}/junit-${junit.version}.jar"/>
<pathelement location="${download.lib.dir}/${hamcrest.jar}"/>
</path> </path>
<!-- ========== Test Execution Defaults =================================== --> <!-- ========== Test Execution Defaults =================================== -->
@ -121,6 +122,7 @@
<pathelement location="${build.home}/classes"/> <pathelement location="${build.home}/classes"/>
<pathelement location="${build.home}/test-classes"/> <pathelement location="${build.home}/test-classes"/>
<pathelement location="${junit.jar}"/> <pathelement location="${junit.jar}"/>
<pathelement location="${hamcrest.jar}"/>
<path refid="downloaded.lib.classpath"/> <path refid="downloaded.lib.classpath"/>
</path> </path>
@ -346,6 +348,7 @@
depends="check-availability" unless="skip.download"> depends="check-availability" unless="skip.download">
<echo message="doing download-dependencies..." /> <echo message="doing download-dependencies..." />
<antcall target="download-junit" /> <antcall target="download-junit" />
<antcall target="download-hamcrest" />
</target> </target>
<target name="check-availability"> <target name="check-availability">
@ -361,5 +364,13 @@
src="http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.jar"/> src="http://repo1.maven.org/maven2/junit/junit/${junit.version}/junit-${junit.version}.jar"/>
</target> </target>
<target name="download-hamcrest" unless="hamcrest.found">
<echo message="Downloading hamcrest..."/>
<mkdir dir="${download.lib.dir}" />
<get dest="${download.lib.dir}/${hamcrest.jar}"
usetimestamp="true" ignoreerrors="true"
src="http://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
</target>
</project> </project>

View File

@ -21,25 +21,23 @@
Compiles and runs unit tests against distribution jar(s). Use .antrc or the Compiles and runs unit tests against distribution jar(s). Use .antrc or the
command line to control the jdk used to execute this build file. command line to control the jdk used to execute this build file.
Assumes that the distribution jar to be tested is in the base directory. Assumes that the distribution jar to be tested is in the basedir/lib, along
Use the "jardir" property to specify the path to the directory containing with any dependent jars (junit, hamcrest). Use the "libdir" property to specify
the jar. Any other jars in this directory will also be added to the the path to the directory containing these jars.
classpath.
The default target, "test," executes clean as a dependency. The default target, "test," executes clean as a dependency.
--> -->
<project default="test" name="commons-math" basedir="."> <project default="test" name="commons-math" basedir=".">
<property name="defaulttargetdir" value="target"/> <property name="libdir" value="lib"/>
<property name="libdir" value="target/lib"/>
<property name="testclassesdir" value="target/test-classes"/> <property name="testclassesdir" value="target/test-classes"/>
<property name="testreportdir" value="target/test-reports"/> <property name="testreportdir" value="target/test-reports"/>
<property name="defaulttargetdir" value="target"/> <property name="defaulttargetdir" value="target"/>
<property name="jardir" value="${basedir}"/> <property name="test.resources" value="src/test/resources"/>
<property name="build.home" value="target"/>
<path id="build.classpath"> <path id="build.classpath">
<fileset dir="${libdir}"> <fileset dir="${libdir}">
<include name="**/*.jar"> <include name="*.jar" />
</include>
</fileset> </fileset>
</path> </path>
<target name="clean" description="o Clean up the generated directories"> <target name="clean" description="o Clean up the generated directories">
@ -58,24 +56,17 @@
Java library path: ${java.library.path} Java library path: ${java.library.path}
=========================================================================== ===========================================================================
</echo> </echo>
<mkdir dir="${libdir}" />
<condition property="noget">
<equals arg2="only" arg1="${build.sysclasspath}">
</equals>
</condition>
<!--Test if JUNIT is present in ANT classpath-->
<available property="Junit.present" classname="org.junit.Test">
</available>
</target> </target>
<target name="test" description="o Run the test cases" if="test.failure" depends="internal-test"> <target name="test" description="o Run the test cases" if="test.failure" depends="internal-test">
<fail message="There were test failures."> <fail message="There were test failures.">
</fail> </fail>
</target> </target>
<target name="internal-test" if="Junit.present" depends="clean, junit-present,compile-tests"> <target name="internal-test" depends="clean,compile-tests">
<mkdir dir="${testreportdir}"/> <mkdir dir="${testreportdir}"/>
<junit dir="./" failureproperty="test.failure" printSummary="yes" fork="true" haltonerror="true"> <junit dir="./" failureproperty="test.failure" printSummary="yes"
fork="true" haltonerror="true" showOutput="true">
<sysproperty key="basedir" value="."/> <sysproperty key="basedir" value="."/>
<formatter usefile="false" type="plain"/> <formatter type="brief"/>
<classpath> <classpath>
<path refid="build.classpath"/> <path refid="build.classpath"/>
<pathelement path="${testclassesdir}"/> <pathelement path="${testclassesdir}"/>
@ -88,14 +79,7 @@
</batchtest> </batchtest>
</junit> </junit>
</target> </target>
<target name="junit-present" unless="Junit.present" depends="init"> <target name="compile-tests" >
<echo>
================================= WARNING ================================
Junit isn't present in your ${ANT_HOME}/lib directory. Tests not executed.
==========================================================================
</echo>
</target>
<target name="compile-tests" if="Junit.present" depends="junit-present">
<mkdir dir="${testclassesdir}"/> <mkdir dir="${testclassesdir}"/>
<javac destdir="${testclassesdir}" deprecation="true" debug="true" <javac destdir="${testclassesdir}" deprecation="true" debug="true"
optimize="false" excludes="**/package.html"> optimize="false" excludes="**/package.html">
@ -106,10 +90,8 @@
<path refid="build.classpath"/> <path refid="build.classpath"/>
</classpath> </classpath>
</javac> </javac>
<copy todir="${testclassesdir}"> <copy todir="${build.home}/test-classes">
<fileset dir="src/test/resources"> <fileset dir="${test.resources}">
<include name="**/*.xml"/>
<include name="**/*.txt"/>
</fileset> </fileset>
</copy> </copy>
</target> </target>