Added protected copy constructor which makes a deep copy. This is used in the androi...
[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         
71         <!-- JAR -->
72         <target name="jar" depends="build" description="Create the OpenRocket jar file">
73                 <copy todir="${dist.dir}/">
74                         <fileset dir="." includes="LICENSE.TXT README.TXT ChangeLog ReleaseNotes fileformat.txt" />
75                         <fileset dir="resources/"/>
76                         <fileset dir="src/" includes="META-INF/" />
77                 </copy>
78                 <mkdir dir="${jar.dir}"/>
79                 <jar destfile="${jar.file}" basedir="${dist.dir}">
80                         <manifest>
81                                 <attribute name="Main-Class" value="${main-class}"/>
82                                 <attribute name="SplashScreen-Image" value="pix/splashscreen.png"/>
83                         </manifest>
84                         <zipfileset src="lib/miglayout15-swing.jar" />
85                         <zipfileset src="lib/jcommon-1.0.16.jar" />
86                         <zipfileset src="lib/jfreechart-1.0.13.jar" />
87                         <zipfileset src="lib/iText-5.0.2.jar" />
88                         <zipfileset src="lib/opencsv-2.3.jar" />
89                 </jar>
90         </target>
91
92         <!-- CONVERT vendor csv to ORC files -->
93         <macrodef name="build-orc-file">
94                 <attribute name="dir"/>
95                 <attribute name="vendor"/>
96                 <sequential>
97                         <echo>Generating ORC file for vendor @{vendor}</echo>
98                         <java classname="net.sf.openrocket.preset.loader.RocksimComponentFileTranslator"
99                                 fork="true"
100                                 classpathref="run-classpath"
101                                 failonerror="true">
102                                 <arg value="@{dir}"/>
103                                 <arg value="resources/datafiles/presets/@{vendor}.orc"/>
104                         </java>
105                 </sequential>
106         </macrodef>
107
108         <target name="generate-orc-files"
109                 description="Generate ORC file from vendor csv"
110                 depends="build">
111
112                 <for param="vendor-dir">
113                         <dirset dir="resources-src/datafiles/rocksim_components"
114                                 includes="*"/>
115                         <sequential>
116                                 <propertyregex property="vendor"
117                                         override="true"
118                                         input="@{vendor-dir}"
119                                         select="\1"
120                                         regexp=".*[/\\]([^/\\]*)$"/>
121                                 <build-orc-file dir="@{vendor-dir}" vendor="${vendor}"/>
122                         </sequential>
123                 </for>
124         </target>
125         
126         <!-- DIST-SRC -->
127         <target name="dist-src">
128                 <echo>                  
129                 Building source distribution
130                 </echo>
131                 <mkdir dir="${build.dir}/${pkgname}"/>
132                 <mkdir dir="${jar.dir}"/>
133                 <copy todir="${build.dir}/${pkgname}">
134                         <fileset dir="." includes="*" excludes="*.log">
135                                 <type type="file"/>
136                         </fileset>
137                         <fileset dir="." includes="resources/ lib/ lib-test/ src/ test/"/>
138                 </copy>
139                 <zip destfile="${dist.src}" basedir="${build.dir}" includes="${pkgname}/"/>
140                 <delete dir="${build.dir}/${pkgname}"/>
141         </target>
142         
143         
144         <!-- DIST-SRC-TEST -->
145         <target name="dist-src-test" depends="dist-src">
146                 <echo>
147                 Testing source distribution
148                 </echo>
149                 <delete dir="${dist-test.dir}"/>
150                 <mkdir dir="${dist-test.dir}"/>
151                 <unzip dest="${dist-test.dir}" src="${dist.src}"/>
152                 <ant dir="${dist-test.dir}/${pkgname}" antfile="build.xml" target="jar"/>
153                 <ant dir="${dist-test.dir}/${pkgname}" antfile="build.xml" target="unittest"/>
154                 <delete dir="${dist-test.dir}"/>
155                 <echo>
156                 Source distribution test successful
157                 </echo>
158         </target>       
159         
160         
161         <!-- DIST-BIN -->
162         <target name="dist-bin" depends="check,clean,unittest,jar">
163                 <move file="${jar.file}" tofile="${dist.bin}"/>
164         </target>
165
166         
167         <!-- DIST -->
168         <target name="dist" depends="dist-bin,dist-src,dist-src-test">
169                 <echo>Distribution ${build.version} (${build.source}) built into directory ${jar.dir}</echo>
170         </target>
171         
172         
173         <!-- CHECK -->
174         <target name="check" depends="checktodo,checkascii"/>
175         
176         <!-- CHECK TODOs -->
177         <target name="todo" depends="checktodo"/>
178         <target name="checktodo">
179                 <tempfile property="todo.file" prefix="checktodo-"/>
180                 <echo>Checking project for FIXMEs.</echo>
181                 <concat destfile="${todo.file}">
182                         <fileset dir="${src.dir}">
183                             <include name="**/*.java"/>
184                         </fileset>
185                         <fileset dir="${src-test.dir}">
186                             <include name="**/*.java"/>
187                         </fileset>
188                         <filterchain>
189                                 <linecontainsregexp>
190                                         <regexp pattern="(FIXME|TODO:.*CRITICAL)"/>
191                                 </linecontainsregexp>
192                         </filterchain>
193                 </concat>
194                 <loadfile srcfile="${todo.file}" property="criticaltodos"/>
195                 <delete file="${todo.file}"/>
196                 <fail if="criticaltodos">CRITICAL TODOs exist in project:
197 ${criticaltodos}</fail>
198                 <echo>No critical TODOs in project.</echo>
199         </target>
200         
201         
202         <!-- CHECK TODOs -->
203         <target name="ascii" depends="checkascii"/>
204         <target name="checkascii">
205                 <tempfile property="ascii.file" prefix="checkascii-"/>
206                 <echo>Checking project for non-ASCII characters.</echo>
207                 <concat destfile="${ascii.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="\P{ASCII}"/>
217                                 </linecontainsregexp>
218                         </filterchain>
219                 </concat>
220                 <loadfile srcfile="${ascii.file}" property="nonascii"/>
221                 <delete file="${ascii.file}"/>
222                 <fail if="nonascii">Non-ASCII characters exist in project:
223 ${nonascii}</fail>
224                 <echo>No non-ASCII characters in project.</echo>
225         </target>
226         
227         
228         <!--  Unit tests  -->
229         <target name="unittest" description="Execute unit tests" depends="build">
230                 <echo>Building unit tests</echo>
231                 <mkdir dir="${build-test.dir}"/>
232                 <javac debug="true" srcdir="${src-test.dir}" destdir="${build-test.dir}" classpathref="test-classpath"/>
233                 
234                 <echo>Running unit tests</echo>
235                 <mkdir dir="tmp/rawtestoutput"/>
236                 <junit fork="yes" forkmode="once" printsummary="false" failureproperty="junit.failure">
237                         <classpath>
238                                 <path refid="test-classpath"/>
239                                 <path location="${basedir}"/>
240                         </classpath>
241                         <batchtest todir="tmp/rawtestoutput">
242                                 <fileset dir="${build-test.dir}">
243                                         <include name="**/Test*.class" />
244                                         <include name="**/*Test.class" />
245                                         <exclude name="**/*$*.class" />
246                                         <exclude name="Test.class" />
247                                 </fileset>
248                                 <formatter type="xml"/>
249                         </batchtest>
250                 </junit>
251                 <junitreport todir="tmp">
252                         <fileset dir="tmp/rawtestoutput"/>
253                         <report todir="tmp/test-reports"/>
254                 </junitreport>
255                 <fail if="junit.failure" message="Unit test(s) failed.  See report in ${basedir}/tmp/test-reports/index.html"/>
256                 <echo>
257         Unit tests passed successfully.
258                 </echo>
259         </target>
260     
261 </project>