openrocket/core/build.xml

288 lines
9.2 KiB
XML

<project name="OpenRocket" basedir=".">
<property file="resources/build.properties" />
<property name="src.dir" value="src"/> <!-- Source directory -->
<property name="src-test.dir" value="test"/> <!-- Test directory -->
<property name="build.dir" value="build"/> <!-- Build directory -->
<property name="build-test.dir" value="build/test"/><!-- Build directory -->
<!-- Distribution directory, from which stuff is jar'ed -->
<property name="dist.dir" value="${build.dir}/dist"/>
<property name="dist-test.dir" value="${build.dir}/dist-test"/>
<property name="classes.dir" value="${dist.dir}"/> <!-- Directory for classes -->
<property name="jar.dir" value="${build.dir}/jar"/> <!-- Directory for built jar's -->
<property name="lib.dir" value="lib"/> <!-- Library source directory -->
<property name="pkgname" value="${ant.project.name}-${build.version}"/>
<property name="jar.file" value="${jar.dir}/${ant.project.name}.jar"/>
<property name="dist.bin" value="${jar.dir}/${pkgname}.jar"/>
<property name="dist.src" value="${jar.dir}/${pkgname}-src.zip"/>
<!-- The main class of the application -->
<property name="main-class" value="net.sf.openrocket.startup.Startup"/>
<!-- Classpath definitions -->
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<path id="test-classpath">
<path refid="classpath"/>
<pathelement location="${basedir}/resources"/>
<pathelement location="${build-test.dir}"/>
<pathelement location="${classes.dir}"/>
<pathelement location="${src-test.dir}"/>
<fileset dir="lib-test/" includes="*.jar"/>
</path>
<path id="run-classpath">
<path refid="classpath"/>
<pathelement location="${basedir}/resources"/>
<pathelement location="${classes.dir}"/>
</path>
<!-- Add Ant-contrib tasks so we can use for loop -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib-extra/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<!-- CLEAN -->
<target name="clean" description="Removes all build artifacts">
<delete dir="${build.dir}"/>
<delete dir="tmp/"/>
</target>
<!-- BUILD -->
<target name="build">
<mkdir dir="${classes.dir}"/>
<echo level="info">Compiling main classes</echo>
<javac debug="true" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>
<!-- Executible Eclipse-Jar-In-Jar style JAR -->
<target name="jar" depends="core-jar" description="Create the OpenRocket jar-in-jar Executable">
<mkdir dir="${jar.dir}" />
<jar destfile="${jar.file}">
<manifest>
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
<attribute name="Rsrc-Main-Class" value="${main-class}" />
<attribute name="SplashScreen-Image" value="pix/splashscreen.png" />
<attribute name="Class-Path" value="." />
<attribute name="Rsrc-Class-Path" value="./ main/${ant.project.name}-Core.jar lib/jfreechart-1.0.13.jar lib/jcommon-1.0.16.jar lib/gluegen-rt.jar lib/miglayout15-swing.jar lib/iText-5.0.2.jar lib/jogl.all.jar lib/opencsv-2.3.jar lib/OrangeExtensions-1.2.jar" />
</manifest>
<!-- Unzip the Eclipse JIJ Loader -->
<zipfileset src="lib/jar-in-jar-loader.jar" />
<!-- Include, in the root of the JAR, the resources needed by OR -->
<fileset dir="src/" includes="META-INF/" />
<fileset dir="resources/" />
<!-- Include the core OpenRocket JAR -->
<zipfileset dir="${build.dir}/" prefix="main">
<include name="${ant.project.name}-Core.jar"/>
</zipfileset>
<!-- Include libraries needed by OR -->
<zipfileset dir="${lib.dir}" prefix="lib">
<include name="*.jar"/>
</zipfileset>
<zipfileset dir="${lib.dir}/jogl" prefix="lib">
<include name="*.jar"/>
</zipfileset>
<!-- Include metafiles about OR -->
<fileset dir="." includes="LICENSE.TXT README.TXT ChangeLog ReleaseNotes fileformat.txt" />
</jar>
</target>
<!-- Core OpenRocket JAR -->
<target name="core-jar" depends="build" description="Create the OpenRocket code-only jar file">
<jar destfile="${build.dir}/${ant.project.name}-Core.jar" basedir="${dist.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
<attribute name="SplashScreen-Image" value="pix/splashscreen.png"/>
</manifest>
</jar>
</target>
<!-- CONVERT vendor csv to ORC files -->
<macrodef name="build-orc-file">
<attribute name="dir"/>
<attribute name="vendor"/>
<sequential>
<echo>Generating ORC file for vendor @{vendor}</echo>
<java classname="net.sf.openrocket.preset.loader.RocksimComponentFileTranslator"
fork="true"
classpathref="run-classpath"
failonerror="true">
<arg value="@{dir}"/>
<arg value="resources/datafiles/presets/@{vendor}.orc"/>
</java>
</sequential>
</macrodef>
<target name="generate-orc-files"
description="Generate ORC file from vendor csv"
depends="build">
<for param="vendor-dir">
<dirset dir="resources-src/datafiles/rocksim_components"
includes="*"/>
<sequential>
<propertyregex property="vendor"
override="true"
input="@{vendor-dir}"
select="\1"
regexp=".*[/\\]([^/\\]*)$"/>
<build-orc-file dir="@{vendor-dir}" vendor="${vendor}"/>
</sequential>
</for>
</target>
<!-- DIST-SRC -->
<target name="dist-src">
<echo>
Building source distribution
</echo>
<mkdir dir="${build.dir}/${pkgname}"/>
<mkdir dir="${jar.dir}"/>
<copy todir="${build.dir}/${pkgname}">
<fileset dir="." includes="*" excludes="*.log">
<type type="file"/>
</fileset>
<fileset dir="." includes="resources/ lib/ lib-test/ src/ test/"/>
</copy>
<zip destfile="${dist.src}" basedir="${build.dir}" includes="${pkgname}/"/>
<delete dir="${build.dir}/${pkgname}"/>
</target>
<!-- DIST-SRC-TEST -->
<target name="dist-src-test" depends="dist-src">
<echo>
Testing source distribution
</echo>
<delete dir="${dist-test.dir}"/>
<mkdir dir="${dist-test.dir}"/>
<unzip dest="${dist-test.dir}" src="${dist.src}"/>
<ant dir="${dist-test.dir}/${pkgname}" antfile="build.xml" target="jar"/>
<ant dir="${dist-test.dir}/${pkgname}" antfile="build.xml" target="unittest"/>
<delete dir="${dist-test.dir}"/>
<echo>
Source distribution test successful
</echo>
</target>
<!-- DIST-BIN -->
<target name="dist-bin" depends="check,clean,unittest,jar">
<move file="${jar.file}" tofile="${dist.bin}"/>
</target>
<!-- DIST -->
<target name="dist" depends="dist-bin,dist-src,dist-src-test">
<echo>Distribution ${build.version} (${build.source}) built into directory ${jar.dir}</echo>
</target>
<!-- CHECK -->
<target name="check" depends="checktodo,checkascii"/>
<!-- CHECK TODOs -->
<target name="todo" depends="checktodo"/>
<target name="checktodo">
<tempfile property="todo.file" prefix="checktodo-"/>
<echo>Checking project for FIXMEs.</echo>
<concat destfile="${todo.file}">
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
<fileset dir="${src-test.dir}">
<include name="**/*.java"/>
</fileset>
<filterchain>
<linecontainsregexp>
<regexp pattern="(FIXME|TODO:.*CRITICAL)"/>
</linecontainsregexp>
</filterchain>
</concat>
<loadfile srcfile="${todo.file}" property="criticaltodos"/>
<delete file="${todo.file}"/>
<fail if="criticaltodos">CRITICAL TODOs exist in project:
${criticaltodos}</fail>
<echo>No critical TODOs in project.</echo>
</target>
<!-- CHECK TODOs -->
<target name="ascii" depends="checkascii"/>
<target name="checkascii">
<tempfile property="ascii.file" prefix="checkascii-"/>
<echo>Checking project for non-ASCII characters.</echo>
<concat destfile="${ascii.file}">
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
<fileset dir="${src-test.dir}">
<include name="**/*.java"/>
</fileset>
<filterchain>
<linecontainsregexp>
<regexp pattern="\P{ASCII}"/>
</linecontainsregexp>
</filterchain>
</concat>
<loadfile srcfile="${ascii.file}" property="nonascii"/>
<delete file="${ascii.file}"/>
<fail if="nonascii">Non-ASCII characters exist in project:
${nonascii}</fail>
<echo>No non-ASCII characters in project.</echo>
</target>
<!-- Unit tests -->
<target name="unittest" description="Execute unit tests" depends="build">
<echo>Building unit tests</echo>
<mkdir dir="${build-test.dir}"/>
<javac debug="true" srcdir="${src-test.dir}" destdir="${build-test.dir}" classpathref="test-classpath"/>
<echo>Running unit tests</echo>
<mkdir dir="tmp/rawtestoutput"/>
<junit fork="yes" forkmode="once" printsummary="false" failureproperty="junit.failure">
<classpath>
<path refid="test-classpath"/>
<path location="${basedir}"/>
</classpath>
<batchtest todir="tmp/rawtestoutput">
<fileset dir="${build-test.dir}">
<include name="**/Test*.class" />
<include name="**/*Test.class" />
<exclude name="**/*$*.class" />
<exclude name="Test.class" />
</fileset>
<formatter type="xml"/>
</batchtest>
</junit>
<junitreport todir="tmp">
<fileset dir="tmp/rawtestoutput"/>
<report todir="tmp/test-reports"/>
</junitreport>
<fail if="junit.failure" message="Unit test(s) failed. See report in ${basedir}/tmp/test-reports/index.html"/>
<echo>
Unit tests passed successfully.
</echo>
</target>
</project>