by bowser » Wed Jul 11, 2007 1:11 pm
<?xml version="1.0" encoding="UTF-8"?>
<!--
NB you will have to change the run.class variable to the name of the class which contains the public static void main(...
place this build.xml file in a directory. create the following folders
src //contains the *.java files and packages etc
tests //contains the junit tests
lib // copy the classes file from lejos_home/lib, and the junit-8.3.1.jar from somewhere...
In NetBeans, create a new project with ANT script, locate the directory with this build file, add the contents of the lib directory to the classpath when asked..
Compiling single files requires a fix, first try compiling a single file (f9) and answer 'ok' then close netbeans and alter the project.xml file which netbeans creates... in the nbproject directory e.g.
<action name="compile.single">
<script>build.xml</script>
<target>compile-selected-files-in-src</target>
...
Start NetBeans with the project, now clean, build run work as normal!
NB this works on most windows platforms, I am sure a Linux person can add an appropriate <exec for the run target....
Problem with the JUnit tests, no autocomplete as yet... help.....
You may want to change name="NXJ" to something more descriptive for your project
-->
<project name="NXJ" default="default" basedir="." >
<property environment="env" />
<property environment="myenv" />
<property name="src.dir" value="src" />
<property name="build.dir" value="support/build" />
<property name="dist.dir" value="support/dist" />
<property name="dist.javadoc.dir" value="support/javadoc" />
<property name="build.classes.excludes" value="support/excludes" />
<property name="dist.jar" value="support/dist.jar" />
<property name="test.src.dir" value="tests" />
<property name="run.class" value="M" />
<property name="lejos.home" value="${myenv.LEJOS_HOME}" />
<property name="junit.jar" value="lib/junit-8.3.1.jar" />
<property name="test.classes.dir" value="support/testClasses" />
<property name="test.results.dir" value="support/testResults" />
<target name="default" depends="javadoc,run" description="Build and test whole project.">
</target>
<target name="create_dirs" depends="clean">
<mkdir dir="${build.dir}" />
<mkdir dir="${dist.dir}" />
<mkdir dir="${dist.javadoc.dir}" />
<mkdir dir="${build.classes.excludes}" />
<mkdir dir="${test.classes.dir}" />
</target>
<target name="compile" depends="create_dirs" description="Compile the whole project.">
<javac srcdir="${src.dir}"
destdir="${build.dir}"
source="1.3"
target="1.1"
bootclasspath="${lejos.home}/lib/classes.jar;${myenv.CLASSPATH}"
/>
</target>
<target name="build" depends="compile" description="Build whole project.">
<property name="thirdparty.lib" value="${lejos.home}/3rdparty/lib" />
<property name="link.classpath" value="{$thirdparty.classpath}/bcel-5.1.jar;${thirdparty.lib}/commons-cli-1.0.jar;${lejos.home}/lib/jtools.jar;${lejos.home}/lib/classes.jar;" />
<exec dir="${build.dir}" executable="cmd" os="Windows XP,Windows NT,Windows 2000,Windows 2003">
<arg line="/c ${lejos.home}/bin/lejoslink ${run.class} -o ${run.class}.lej"/>
</exec>
<echo message="${os.name}" />
<exec dir="${build.dir}" executable="bash" os="Linux" >
<arg line="${lejos.home}/bin/lejoslink ${run.class} -o ${run.class}.lej"/>
</exec>
</target>
<target name="do-clean" >
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
<delete dir="${dist.javadoc.dir}" />
<delete dir="${build.classes.excludes}" />
<delete dir="${test.classes.dir}" />
<echo message="${os.name}" />
</target>
<target name="-init-check">
<fail unless="src.dir">Must set src.dir</fail>
<fail unless="test.src.dir">Must set test.src.dir</fail>
<fail unless="build.dir">Must set build.dir</fail>
<fail unless="dist.dir">Must set dist.dir</fail>
<fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
<fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
</target>
<target name="clean" depends="-init-check,do-clean" description="Clean build products." />
<target name="run" depends="build" description="Build and run whole project.">
<exec dir="${build.dir}" executable="cmd" os="Windows XP,Windows NT,Windows 2000,Windows 2003">
<arg line="/c ${lejos.home}/bin/lejosdl ${run.class}.bin"/>
</exec>
<echo message="${os.name}" />
<exec dir="${build.dir}" executable="bash" os="Linux" >
<arg line="${lejos.home}/bin/lejosdl ${run.class}.bin"/>
</exec>
</target>
<target name="emulate" depends="build" description="Emulates the code on a LINUX os implementation of the NXT">
<echo message="${os.name}" />
<exec dir="${build.dir}" executable="bash" os="Linux" >
<arg line="${lejos.home}/bin/emj -v ${run.class}.lej"/>
</exec>
<exec dir="${build.dir}" executable="cmd" os="Windows XP,Windows NT,Windows 2000,Windows 2003">
<arg line="/c echo 'Not implemented of Windows yet'"/>
</exec>
</target>
<target name="rebuild" depends="clean,build" description="Build and test whole project.">
</target>
<target name="-javadoc-build" >
<mkdir dir="${dist.javadoc.dir}" />
<javadoc classpath="${lejos.home}/lib/classes.jar;${myenv.CLASSPATH}" destdir="${dist.javadoc.dir}" source="${javac.source}" notree="${javadoc.notree}" use="${javadoc.use}" nonavbar="${javadoc.nonavbar}" noindex="${javadoc.noindex}" splitindex="${javadoc.splitindex}" author="${javadoc.author}" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}" private="${javadoc.private}" failonerror="true" useexternalfile="true">
<classpath>
<path path="${javac.classpath}" />
</classpath>
<sourcepath>
<pathelement location="${src.dir}" />
</sourcepath>
<packageset dir="${src.dir}" includes="*/**" />
<fileset dir="${src.dir}" includes="*.java" />
</javadoc>
</target>
<target name="-javadoc-browse" if="netbeans.home" unless="no.javadoc.preview" depends="-javadoc-build">
<nbbrowse file="${dist.javadoc.dir}/index.html" />
</target>
<target name="javadoc" depends="clean,build,-javadoc-build,-javadoc-browse" description="Build Javadoc." />
<target name="compile-tests" depends="compile">
<javac srcdir="${test.src.dir}"
destdir="${test.classes.dir}"
source="1.3"
target="1.1"
classpath="${junit.jar};./;.;${build.dir}"
bootclasspath="${lejos.home}/lib/classes.jar;${myenv.CLASSPATH}"
/>
</target>
<target name="test" depends="compile-tests">
<delete dir="${test.results.dir}" />
<mkdir dir="${test.results.dir}"/>
<junit showoutput="true"
fork="true"
failureproperty="tests.failed"
errorproperty="tests.failed">
<batchtest todir="${test.results.dir}">
<fileset dir="tests">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
<classpath path="./;.;${build.dir};${junit.jar};${test.classes.dir}"/>
<formatter usefile="false" type="brief"/>
<formatter type="xml"/>
</junit>
</target>
<target name="compile-selected-files-in-src">
<fail unless="files">Must set property 'files'</fail>
<mkdir dir="${build.dir}"/>
<javac includes="${files}"
srcdir="${src.dir}"
destdir="${build.dir}"
target="1.1"
source="1.3"
bootclasspath="${lejos.home}/lib/classes.jar;${myenv.CLASSPATH}"
/>
</target>
</project>