create changelog entry
[debian/openrocket] / core / build.xml
1 <project name="OpenRocket" basedir=".">
2
3         <property file="resources/build.properties" />
4         
5         <property name="src.dir"        value="src"/>           <!-- Source directory -->
6         <property name="src-test.dir"   value="test"/>          <!-- Test directory -->
7         <property name="build.dir"      value="build"/>         <!-- Build directory -->
8         <property name="build-test.dir" value="build/test"/><!-- Build directory -->
9                 
10         <!-- Distribution directory, from which stuff is jar'ed -->
11         <property name="dist.dir"       value="${build.dir}/dist"/> 
12         <property name="dist-test.dir"  value="${build.dir}/dist-test"/>
13         
14         <property name="classes.dir" value="${dist.dir}"/>      <!-- Directory for classes -->
15         <property name="jar.dir"     value="${build.dir}/jar"/> <!-- Directory for built jar's -->
16         <property name="lib.dir"     value="lib"/>                              <!-- Library source directory -->
17
18         <property name="pkgname"     value="${ant.project.name}-${build.version}"/>
19         
20         <property name="jar.file"    value="${jar.dir}/${ant.project.name}.jar"/>
21         <property name="dist.bin"    value="${jar.dir}/${pkgname}.jar"/>
22         <property name="dist.src"    value="${jar.dir}/${pkgname}-src.zip"/>
23         
24         <!-- The main class of the application -->
25         <property name="main-class"  value="net.sf.openrocket.startup.Startup"/>
26
27         
28         <!-- Classpath definitions -->
29         <path id="classpath">
30                 <fileset dir="${lib.dir}" includes="**/*.jar"/>
31         </path>
32         
33         <path id="test-classpath">
34                 <path refid="classpath"/>
35                 <pathelement location="${basedir}/resources"/>
36                 <pathelement location="${build-test.dir}"/>
37                 <pathelement location="${classes.dir}"/>
38                 <pathelement location="${src-test.dir}"/>
39                 <fileset dir="lib-test/" includes="*.jar"/>
40         </path>
41
42         <path id="run-classpath">
43                 <path refid="classpath"/>
44                 <pathelement location="${basedir}/resources"/>
45                 <pathelement location="${classes.dir}"/>
46         </path>
47
48         <!-- Add Ant-contrib tasks so we can use for loop -->
49         <taskdef resource="net/sf/antcontrib/antlib.xml">
50                 <classpath>
51                         <pathelement location="lib-extra/ant-contrib-1.0b3.jar"/>
52                 </classpath>
53         </taskdef>
54
55         
56         <!-- CLEAN -->
57         <target name="clean" description="Removes all build artifacts">
58                 <delete dir="${build.dir}"/>
59                 <delete dir="tmp/"/>
60         </target>
61                 
62         
63         <!-- BUILD -->
64         <target name="build">
65                 <mkdir dir="${classes.dir}"/>
66                 <echo level="info">Compiling main classes</echo>
67                 <javac debug="true" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
68         </target>
69         
70         <!-- Executible Eclipse-Jar-In-Jar style JAR -->
71         <target name="jar" depends="core-jar" description="Create the OpenRocket jar-in-jar Executable">
72                 <mkdir dir="${jar.dir}" />
73                 <jar destfile="${jar.file}">
74                         <manifest>
75                                 <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
76                                 <attribute name="Rsrc-Main-Class" value="${main-class}" />
77                                 <attribute name="SplashScreen-Image" value="pix/splashscreen.png" />
78                                 <attribute name="Class-Path" value="." />
79                                 <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" />
80                         </manifest>
81
82                         <!-- Unzip the Eclipse JIJ Loader -->
83                         <zipfileset src="lib/jar-in-jar-loader.jar" />
84                         
85                         <!-- Include, in the root of the JAR, the resources needed by OR -->
86                         <fileset dir="src/" includes="META-INF/" />
87                         <fileset dir="resources/" />
88                         
89                         <!-- Include the core OpenRocket JAR -->
90                         <zipfileset dir="${build.dir}/" prefix="main">
91                                 <include name="${ant.project.name}-Core.jar"/>
92                         </zipfileset>
93                         
94                         <!-- Include libraries needed by OR -->
95                         <zipfileset dir="${lib.dir}" prefix="lib">
96                                 <include name="*.jar"/>
97                         </zipfileset>
98                         <zipfileset dir="${lib.dir}/jogl" prefix="lib">
99                                 <include name="*.jar"/>
100                         </zipfileset>
101                         
102                         <!-- Include metafiles about OR -->
103                         <fileset dir="." includes="LICENSE.TXT README.TXT ChangeLog ReleaseNotes fileformat.txt" />
104                 </jar>
105         </target>
106         
107         
108         <!-- Core OpenRocket JAR -->
109         <target name="core-jar" depends="build" description="Create the OpenRocket code-only jar file">
110                 <jar destfile="${build.dir}/${ant.project.name}-Core.jar" basedir="${dist.dir}">
111                         <manifest>
112                                 <attribute name="Main-Class" value="${main-class}"/>
113                                 <attribute name="SplashScreen-Image" value="pix/splashscreen.png"/>
114                         </manifest>
115                 </jar>
116         </target>
117
118         <!-- CONVERT vendor csv to ORC files -->
119         <macrodef name="build-orc-file">
120                 <attribute name="dir"/>
121                 <attribute name="vendor"/>
122                 <sequential>
123                         <echo>Generating ORC file for vendor @{vendor}</echo>
124                         <java classname="net.sf.openrocket.preset.loader.RocksimComponentFileTranslator"
125                                 fork="true"
126                                 classpathref="run-classpath"
127                                 failonerror="true">
128                                 <arg value="@{dir}"/>
129                                 <arg value="resources/datafiles/presets/@{vendor}.orc"/>
130                         </java>
131                 </sequential>
132         </macrodef>
133
134         <target name="generate-orc-files"
135                 description="Generate ORC file from vendor csv"
136                 depends="build">
137
138                 <for param="vendor-dir">
139                         <dirset dir="resources-src/datafiles/rocksim_components"
140                                 includes="*"/>
141                         <sequential>
142                                 <propertyregex property="vendor"
143                                         override="true"
144                                         input="@{vendor-dir}"
145                                         select="\1"
146                                         regexp=".*[/\\]([^/\\]*)$"/>
147                                 <build-orc-file dir="@{vendor-dir}" vendor="${vendor}"/>
148                         </sequential>
149                 </for>
150         </target>
151         
152         <!-- DIST-SRC -->
153         <target name="dist-src">
154                 <echo>                  
155                 Building source distribution
156                 </echo>
157                 <mkdir dir="${build.dir}/${pkgname}"/>
158                 <mkdir dir="${jar.dir}"/>
159                 <copy todir="${build.dir}/${pkgname}">
160                         <fileset dir="." includes="*" excludes="*.log">
161                                 <type type="file"/>
162                         </fileset>
163                         <fileset dir="." includes="resources/ lib/ lib-test/ src/ test/"/>
164                 </copy>
165                 <zip destfile="${dist.src}" basedir="${build.dir}" includes="${pkgname}/"/>
166                 <delete dir="${build.dir}/${pkgname}"/>
167         </target>
168         
169         
170         <!-- DIST-SRC-TEST -->
171         <target name="dist-src-test" depends="dist-src">
172                 <echo>
173                 Testing source distribution
174                 </echo>
175                 <delete dir="${dist-test.dir}"/>
176                 <mkdir dir="${dist-test.dir}"/>
177                 <unzip dest="${dist-test.dir}" src="${dist.src}"/>
178                 <ant dir="${dist-test.dir}/${pkgname}" antfile="build.xml" target="jar"/>
179                 <ant dir="${dist-test.dir}/${pkgname}" antfile="build.xml" target="unittest"/>
180                 <delete dir="${dist-test.dir}"/>
181                 <echo>
182                 Source distribution test successful
183                 </echo>
184         </target>       
185         
186         
187         <!-- DIST-BIN -->
188         <target name="dist-bin" depends="check,clean,unittest,jar">
189                 <move file="${jar.file}" tofile="${dist.bin}"/>
190         </target>
191
192         
193         <!-- DIST -->
194         <target name="dist" depends="dist-bin,dist-src,dist-src-test">
195                 <echo>Distribution ${build.version} (${build.source}) built into directory ${jar.dir}</echo>
196         </target>
197         
198         
199         <!-- CHECK -->
200         <target name="check" depends="checktodo,checkascii"/>
201         
202         <!-- CHECK TODOs -->
203         <target name="todo" depends="checktodo"/>
204         <target name="checktodo">
205                 <tempfile property="todo.file" prefix="checktodo-"/>
206                 <echo>Checking project for FIXMEs.</echo>
207                 <concat destfile="${todo.file}">
208                         <fileset dir="${src.dir}">
209                             <include name="**/*.java"/>
210                         </fileset>
211                         <fileset dir="${src-test.dir}">
212                             <include name="**/*.java"/>
213                         </fileset>
214                         <filterchain>
215                                 <linecontainsregexp>
216                                         <regexp pattern="(FIXME|TODO:.*CRITICAL)"/>
217                                 </linecontainsregexp>
218                         </filterchain>
219                 </concat>
220                 <loadfile srcfile="${todo.file}" property="criticaltodos"/>
221                 <delete file="${todo.file}"/>
222                 <fail if="criticaltodos">CRITICAL TODOs exist in project:
223 ${criticaltodos}</fail>
224                 <echo>No critical TODOs in project.</echo>
225         </target>
226         
227         
228         <!-- CHECK TODOs -->
229         <target name="ascii" depends="checkascii"/>
230         <target name="checkascii">
231                 <tempfile property="ascii.file" prefix="checkascii-"/>
232                 <echo>Checking project for non-ASCII characters.</echo>
233                 <concat destfile="${ascii.file}">
234                         <fileset dir="${src.dir}">
235                             <include name="**/*.java"/>
236                         </fileset>
237                         <fileset dir="${src-test.dir}">
238                             <include name="**/*.java"/>
239                         </fileset>
240                         <filterchain>
241                                 <linecontainsregexp>
242                                         <regexp pattern="\P{ASCII}"/>
243                                 </linecontainsregexp>
244                         </filterchain>
245                 </concat>
246                 <loadfile srcfile="${ascii.file}" property="nonascii"/>
247                 <delete file="${ascii.file}"/>
248                 <fail if="nonascii">Non-ASCII characters exist in project:
249 ${nonascii}</fail>
250                 <echo>No non-ASCII characters in project.</echo>
251         </target>
252         
253         
254         <!--  Unit tests  -->
255         <target name="unittest" description="Execute unit tests" depends="build">
256                 <echo>Building unit tests</echo>
257                 <mkdir dir="${build-test.dir}"/>
258                 <javac debug="true" srcdir="${src-test.dir}" destdir="${build-test.dir}" classpathref="test-classpath"/>
259                 
260                 <echo>Running unit tests</echo>
261                 <mkdir dir="tmp/rawtestoutput"/>
262                 <junit fork="yes" forkmode="once" printsummary="false" failureproperty="junit.failure">
263                         <classpath>
264                                 <path refid="test-classpath"/>
265                                 <path location="${basedir}"/>
266                         </classpath>
267                         <batchtest todir="tmp/rawtestoutput">
268                                 <fileset dir="${build-test.dir}">
269                                         <include name="**/Test*.class" />
270                                         <include name="**/*Test.class" />
271                                         <exclude name="**/*$*.class" />
272                                         <exclude name="Test.class" />
273                                 </fileset>
274                                 <formatter type="xml"/>
275                         </batchtest>
276                 </junit>
277                 <junitreport todir="tmp">
278                         <fileset dir="tmp/rawtestoutput"/>
279                         <report todir="tmp/test-reports"/>
280                 </junitreport>
281                 <fail if="junit.failure" message="Unit test(s) failed.  See report in ${basedir}/tmp/test-reports/index.html"/>
282                 <echo>
283         Unit tests passed successfully.
284                 </echo>
285         </target>
286     
287 </project>