Initial import
[jpf-core.git] / build.xml
1 <?xml version="1.0" ?>
2
3 <!--
4   build.xml - the JPF core build script
5               using Ant (http://jakarta.apache.org/ant)
6   public targets:
7
8     build (default)   compile classes and build JPF jar files
9     compile           compile JPF and its specific (modeled) environment libraries
10     test              run all JPF tests
11     clean             remove the files that have been generated by the build process
12     buildinfo         create buildinfo properties file
13 -->
14
15 <project name="jpf-core" default="build" basedir=".">
16
17   <!-- ===================== ===== COMMON SECTION ========================== -->
18
19   <!-- 
20     local props have to come first, because Ant properties are immutable
21     NOTE: this file is local - it is never in the repository!
22   -->
23   <property file="local.properties"/>
24   <property environment="env"/>
25   
26   <!-- compiler settings -->
27   <property name="debug"         value="on"/>
28   <property name="deprecation"   value="on"/>
29
30   <uptodate property="build_uptodate" targetfile="build/main/gov/nasa/jpf/build.properties" srcfile="build.properties"/>
31
32
33   <!-- generic classpath settings -->
34   <path id="lib.path">
35     <pathelement location="build/main"/>
36     <pathelement location="build/peers"/>
37     <pathelement location="build/annotations"/>
38     <fileset dir=".">
39           <include name="lib/*.jar"/>
40     </fileset>
41   </path>
42
43
44   <!-- init: common initialization -->
45   <target name="-init">
46     <tstamp/>
47
48     <mkdir dir="build"/>               <!-- the build root -->
49     
50     <!-- the things that have to be in the classpath of whatever runs Ant -->
51     <available property="have_javac" classname="com.sun.tools.javac.Main"/>
52     <fail unless="have_javac">no javac was found __or__ check http://babelfish.arc.nasa.gov/trac/jpf/wiki/install/build for possible solutions</fail>
53
54
55     <available file="src/main"        type="dir" property="have_main"/>
56     <available file="src/annotations" type="dir" property="have_annotations"/>
57     <available file="src/peers"       type="dir" property="have_peers"/>
58     <available file="src/classes"     type="dir" property="have_classes"/>
59     <available file="src/tests"       type="dir" property="have_tests"/>
60     <available file="src/examples"    type="dir" property="have_examples"/>
61
62     <available file=".hg"             type="dir" property="have_hg"/>
63
64     <!-- for the core, it's a fail if any of these is missing -->
65     <fail unless="have_main">no src/main</fail>
66     <fail unless="have_annotations">no src/annotations</fail>
67     <fail unless="have_peers">no src/peers</fail>
68     <fail unless="have_classes">no src/classes</fail>
69     <fail unless="have_tests">no src/tests</fail>
70     <fail unless="have_examples">no src/examples</fail>
71
72     <condition property="have_java8">
73         <equals arg1="${ant.java.version}" arg2="1.8"/>
74     </condition>
75
76   </target>
77
78
79   <!-- ======================= COMPILE SECTION ============================= -->
80     
81   <!-- public compile -->
82   <target name="compile" depends="-init,-compile-annotations,-compile-main,-compile-peers,-compile-classes,-compile-tests,-compile-examples"
83           description="compile all JPF core sources" >
84           <copy file="build.properties" todir="build/main/gov/nasa/jpf" failonerror="false"/>
85   </target>
86
87   <target name="-compile-annotations" if="have_annotations">
88     <mkdir dir="build/annotations"/>
89     <javac srcdir="src/annotations" destdir="build/annotations" includeantruntime="false"
90            debug="${debug}" deprecation="${deprecation}" classpath=""/>
91   </target>
92
93   <target name="-compile-main" if="have_main">
94     <mkdir dir="build/main"/>
95     <javac srcdir="src/main" destdir="build/main" includeantruntime="false"
96            debug="${debug}" deprecation="${deprecation}" classpathref="lib.path">
97         <!--
98         <compilerarg value="-XDenableSunApiLintControl"/>
99         <compilerarg value="-Xlint:all"/>
100         -->
101     </javac>
102
103   </target>
104   
105   <target name="-compile-peers" if="have_peers" depends="-compile-main" >
106     <mkdir dir="build/peers"/>
107     <javac srcdir="src/peers" destdir="build/peers" includeantruntime="false"
108            debug="${debug}" deprecation="${deprecation}" classpathref="lib.path">
109         <compilerarg value="-XDenableSunApiLintControl"/>
110         <compilerarg value="-Xlint:all,-sunapi,-serial"/>       
111      </javac>
112   </target>
113   
114   <target name="-compile-classes" if="have_classes" depends="-compile-annotations,-compile-main" >
115     <mkdir dir="build/classes"/>
116     <javac srcdir="src/classes" destdir="build/classes" includeantruntime="false"
117            debug="${debug}" deprecation="${deprecation}">
118       <compilerarg value="-XDenableSunApiLintControl"/>
119       <compilerarg value="-Xlint:all,-sunapi"/>   
120       <classpath>
121         <path refid="lib.path"/>
122         <pathelement location="build/annotations"/>
123       </classpath>
124     </javac>
125   </target>
126   
127   <target name="-compile-tests" if="have_tests" depends="-compile-annotations,-compile-main,-compile-classes">
128     <mkdir dir="build/tests"/>
129
130     <javac sourcepath="" srcdir="src/tests" destdir="build/tests" includeantruntime="false"
131            debug="${debug}" deprecation="${deprecation}"
132            includes="*,gov/nasa/jpf/**,classloader_specific_tests/**">
133       <compilerarg value="-XDenableSunApiLintControl"/>
134       <compilerarg value="-Xlint:all,-sunapi,-serial,-rawtypes,-unchecked"/>
135
136       <include name="*gov/nasa/jpf/**"/>
137       <include name="classloader_specific_tests/**"/>
138       <include name="java8/**" if="have_java8"/>
139
140       <classpath>
141         <path refid="lib.path"/>
142         <pathelement location="build/annotations"/>
143         <pathelement location="build/classes"/>
144       </classpath>       
145     </javac>
146   </target>
147
148   <target name="-compile-examples" if="have_examples" depends="-compile-annotations,-compile-main">
149     <mkdir dir="build/examples" />
150     <javac srcdir="src/examples" destdir="build/examples" includeantruntime="false"
151            debug="${debug}" deprecation="${deprecation}"
152            classpathref="lib.path"/>
153   </target>
154
155   
156   <!-- ======================= MISC SECTION ================================ -->
157   
158   <target name="-version" if="have_hg">
159     <exec executable="hg" outputproperty="version" searchpath="true" failonerror="false" failifexecutionfails="false">
160       <arg value="identify"/>
161       <arg value="-n"/> 
162     </exec>
163         
164     <!-- .version is in .hgignore -->
165     <echo message="${version}${line.separator}" file=".version"/>
166   </target>
167         
168   <!-- build jars -->
169   <target name="build" depends="-cond-clean,compile,-version"
170         description="generate the core JPF jar files" >
171
172     <copy file=".version" todir="build/main/gov/nasa/jpf" failonerror="false"/>
173
174     <jar jarfile="build/jpf-classes.jar">
175       <fileset dir="build/classes"/>
176       <fileset dir="build/annotations"/>
177
178       <fileset dir="build/main">
179           <!-- we need this one in case a SUT uses the Verify API -->
180           <include name="gov/nasa/jpf/vm/Verify.class"/>
181
182           <!-- these are required if we run TestJPF derived test classes -->
183           <include name="gov/nasa/jpf/JPFShell.class"/>
184           <include name="gov/nasa/jpf/util/TypeRef.class"/>
185           <include name="gov/nasa/jpf/util/test/TestJPF.class"/>
186           <include name="gov/nasa/jpf/util/test/TestMultiProcessJPF.class"/>
187           <include name="gov/nasa/jpf/util/test/TestJPFHelper.class"/>
188       </fileset>
189     </jar>
190
191     <jar jarfile="build/jpf.jar" index="true">
192       <fileset dir="build/main"/>
193       <fileset dir="build/peers"/>
194       <!-- this is redundant, but if JPF is executed from java.class.path it wouldn't find annotations -->
195       <fileset dir="build/annotations"/>
196       
197       <!-- this is for annotations used by JPF regression tests, which can also be executed outside of junit -->
198       <fileset dir="build/classes">
199           <include name="org/junit/*.class"/>
200       </fileset>
201       
202       <manifest>
203         <attribute name="Built-By" value="${user.name}"/>
204         <attribute name="Implementation-Vendor" value="NASA Ames Research Center"/>
205         <attribute name="Implementation-Title" value="Java Pathfinder core system"/>
206         <attribute name="Implementation-Version" value="${jpf.version}"/>
207       </manifest>
208     </jar>
209
210     <!-- optional jar that contains annotations to be used in non-JPF dependent apps -->
211     <jar jarfile="build/jpf-annotations.jar">
212       <fileset dir="build/annotations"/>
213     </jar>
214
215     <!-- this jar is needed to test classloaders, it is used by URLClassLoaderTest -->
216     <jar jarfile="build/classloader_specific_tests.jar">
217       <fileset dir="build/tests">
218         <include name="classloader_specific_tests/*.class"/>
219           </fileset>
220     </jar>
221
222     <jar jarfile="build/RunJPF.jar">
223       <fileset dir="build/main">
224         <include name="gov/nasa/jpf/tool/Run.class"/>
225         <include name="gov/nasa/jpf/tool/RunJPF.class"/>
226         <include name="gov/nasa/jpf/Config.class"/>
227         <include name="gov/nasa/jpf/ConfigChangeListener.class"/>
228         <include name="gov/nasa/jpf/Config$MissingRequiredKeyException.class"/>
229         <include name="gov/nasa/jpf/JPFClassLoader.class"/>
230         <include name="gov/nasa/jpf/JPFShell.class"/>
231         <include name="gov/nasa/jpf/JPFException.class"/>
232         <include name="gov/nasa/jpf/JPFConfigException.class"/>
233         <include name="gov/nasa/jpf/JPFTargetException.class"/>
234         <include name="gov/nasa/jpf/util/JPFSiteUtils.class"/>
235         <include name="gov/nasa/jpf/util/FileUtils.class"/>
236         <include name="gov/nasa/jpf/util/StringMatcher.class"/>
237         <include name="gov/nasa/jpf/util/Pair.class"/>        
238       </fileset>
239       
240       <manifest>
241         <attribute name="Built-By" value="${user.name}"/>
242         <attribute name="Implementation-Vendor" value="NASA Ames Research Center"/>
243         <attribute name="Implementation-Title" value="Java Pathfinder core launch system"/>
244         <attribute name="Implementation-Version" value="${jpf.version}"/>
245         <attribute name="Main-Class" value="gov.nasa.jpf.tool.RunJPF"/>
246       </manifest>
247     </jar>
248
249     <jar jarfile="build/RunTest.jar">
250       <fileset dir="build/main">
251         <include name="gov/nasa/jpf/tool/Run.class"/>
252         <include name="gov/nasa/jpf/tool/RunTest.class"/>
253         <include name="gov/nasa/jpf/tool/RunTest$Failed.class"/>
254         <include name="gov/nasa/jpf/Config.class"/>
255         <include name="gov/nasa/jpf/ConfigChangeListener.class"/>
256         <include name="gov/nasa/jpf/Config$MissingRequiredKeyException.class"/>
257         <include name="gov/nasa/jpf/JPFClassLoader.class"/>
258         <include name="gov/nasa/jpf/JPFException.class"/>
259         <include name="gov/nasa/jpf/JPFConfigException.class"/>
260         <include name="gov/nasa/jpf/util/JPFSiteUtils.class"/>
261         <include name="gov/nasa/jpf/util/FileUtils.class"/>
262         <include name="gov/nasa/jpf/util/StringMatcher.class"/>
263         <include name="gov/nasa/jpf/util/DevNullPrintStream.class"/>
264       </fileset>
265       <manifest>
266         <attribute name="Built-By" value="${user.name}"/>
267         <attribute name="Implementation-Vendor" value="NASA Ames Research Center"/>
268         <attribute name="Implementation-Title" value="Java Pathfinder test launch system"/>
269         <attribute name="Implementation-Version" value="${jpf.version}"/>
270         <attribute name="Main-Class" value="gov.nasa.jpf.tool.RunTest"/>
271       </manifest>
272     </jar>
273
274   </target>
275
276
277   <!-- public clean: cleanup from previous tasks/builds -->
278   <target name="clean"
279           description="remove all build artifacts and temporary files">
280     <delete dir="build" failonerror="false"/>
281     <delete dir="tmp" failonerror="false"/>
282     <delete>
283       <fileset dir="." includes="**/*~" defaultexcludes="no" />
284       <fileset dir="." includes="**/*.bak" defaultexcludes="no" />
285       <fileset dir="." includes="**/error.xml" />
286     </delete>
287   </target>
288
289   <target name="-cond-clean" unless="build_uptodate"
290           description="remove all build artifacts and temporaries if build.properties has been changed">
291     <antcall target="clean"/>
292   </target>
293
294
295   <!-- generate buildinfo file  -->
296   <target name="buildinfo" description="create buildinfo properties">
297
298     <!-- make this fail if there are uncommitted changes -->
299     <exec executable="hg" outputproperty="uncommitted_changes" failifexecutionfails="true">
300       <arg value="status"/>
301     </exec>
302     <condition property="have_uncommitted_changes">
303       <length string="${uncommitted_changes}" trim="true" when="greater" length="0"/>
304     </condition>
305 <!--
306     <fail if="have_uncommitted_changes">hg status shows uncommitted changes:
307       ${uncommitted_changes}
308     </fail>
309 -->
310     <exec executable="hg" outputproperty="hg.tip.id" failifexecutionfails="false">
311       <arg value="tip"/>
312       <arg value="--template"/>
313       <arg value="{rev}:{node|short}\n"/>
314     </exec>
315     <exec executable="hg" outputproperty="hg.author" failifexecutionfails="false">
316       <arg value="tip"/>
317       <arg value="--template"/>
318       <arg value="{author}\n"/>
319     </exec>
320     <exec executable="hg" outputproperty="hg.tip.date" failifexecutionfails="false">
321       <arg value="tip"/>
322       <arg value="--template"/>
323       <arg value="{date|isodate}\n"/>
324     </exec>
325     <exec executable="hg" outputproperty="hg.paths.default" failifexecutionfails="false">
326       <arg value="showconfig"/>
327       <arg value="paths.default"/>
328     </exec>
329     
330     <exec executable="hostname" failifexecutionfails="false" outputproperty="env.COMPUTERNAME"/>
331     <property name="hostname" value="${env.COMPUTERNAME}"/>  <!-- Windows doesn't have hostname -->
332
333     <!-- it seems the 'propertyfile' task just appends -->
334     <delete file="build.properties" failonerror="false"/>
335
336     <propertyfile file="build.properties" comment="JPF core build info">
337       <entry key="revision" value="${hg.tip.id}"/>
338       <entry key="date.tip" value="${hg.tip.date}"/>
339
340       <entry key="author" value="${hg.author}"/>
341       <entry key="repository" value="file://${hostname}${basedir}"/>
342       <entry key="upstream" value="${hg.paths.default}"/>
343
344       <entry key="java.version" value="${java.version}"/>
345
346       <entry key="os.arch" value="${os.arch}"/>
347       <entry key="os.name" value="${os.name}"/>
348       <entry key="os.version" value="${os.version}"/>
349       <entry key="user.country" value="${user.country}"/>
350
351     </propertyfile>
352
353   </target>
354
355   <target name="dist" description="build binary distribution">
356     <delete file="build/${ant.project.name}*.zip"/>
357         
358     <exec executable="hg" outputproperty="hg.tip.rev" failifexecutionfails="false">
359       <arg value="tip"/>
360       <arg value="--template"/>
361       <arg value="-r{rev}"/>
362     </exec>
363         
364     <!-- 2do this seems stupid - there needs to be a better way to re-base (zip basedir fails miserably) -->
365     <zip destfile="build/${ant.project.name}${hg.tip.rev}.zip" update="false" excludes="*">
366       <zipfileset file="jpf.properties"  prefix="${ant.project.name}"/>
367       <zipfileset file="build.properties"  prefix="${ant.project.name}"/>
368       <zipfileset dir="lib"  prefix="${ant.project.name}/lib"/>
369       <zipfileset dir="bin"  prefix="${ant.project.name}/bin" filemode="754"/>
370       <zipfileset dir="build" includes="*.jar" prefix="${ant.project.name}/build"/>
371     </zip>
372   </target>
373
374   <target name="src-dist" description="build source distribution">
375     <delete file="build/${ant.project.name}*-src.zip"/>
376     
377     <exec executable="hg" outputproperty="hg.tip.rev" failifexecutionfails="false">
378       <arg value="tip"/>
379       <arg value="--template"/>
380       <arg value="-r{rev}"/>
381     </exec>
382         
383     <zip destfile="build/${ant.project.name}${hg.tip.rev}-src.zip" update="false" excludes="*" whenempty="skip">
384       <zipfileset file="jpf.properties"  prefix="${ant.project.name}"/>
385       <zipfileset file="build.properties"  prefix="${ant.project.name}"/>
386       <zipfileset file="build.xml"  prefix="${ant.project.name}"/>
387         <zipfileset file="LICENSE-2.0.txt"  prefix="${ant.project.name}"/>
388       <zipfileset file="README"  prefix="${ant.project.name}"/>
389       <zipfileset dir="src" prefix="${ant.project.name}/src"/>
390       <zipfileset dir="lib"  prefix="${ant.project.name}/lib" erroronmissingdir="false"/>
391       <zipfileset dir="bin"  prefix="${ant.project.name}/bin" filemode="754"/>
392       <zipfileset dir="tools" prefix="${ant.project.name}/tools" erroronmissingdir="false"/>
393
394       <!-- IDE related configuration files -->
395       <zipfileset file=".project"  prefix="${ant.project.name}"/>
396       <zipfileset file=".classpath"  prefix="${ant.project.name}"/>
397       <zipfileset dir="eclipse" prefix="${ant.project.name}/eclipse"/>
398
399       <zipfileset dir="nbproject" prefix="${ant.project.name}/nbproject"/>
400     </zip>
401   </target>
402
403   <!-- ======================= TEST SECTION ================================ -->
404
405
406
407   <target name="test" depends="build"
408           description="run core regression tests" if="have_tests">
409           
410     <!-- note this can be directly set in local.properties, which overrides this setting -->
411     <property name="junit.home" value="${env.JUNIT_HOME}"/>
412     
413     <condition property="junit.usefile">
414       <!-- don't set if this is running from within an IDE that collects output -->
415       <not>
416         <isset property="netbeans.home"/>  
417       </not>
418     </condition>
419     
420     <junit printsummary="on" showoutput="off" 
421            haltonfailure="no" logfailedtests="true" failureproperty="test.failed" 
422            dir="${basedir}" fork="yes" forkmode="perTest" maxmemory="1024m" outputtoformatters="true">
423       <formatter type="plain" usefile="${junit.usefile}"/>
424
425       <assertions>
426         <enable/>
427       </assertions>
428
429       <classpath>
430         <path refid="lib.path"/>
431         <pathelement location="build/tests"/>
432         <pathelement location="build/classes"/>
433         <pathelement location="build/annotations"/>
434         
435         <fileset dir="${junit.home}">
436           <include name="**/*.jar"/>
437         </fileset>  
438       </classpath>
439
440       <batchtest todir="build/tests">
441         <fileset dir="build/tests">
442           <exclude name="**/JPF_*.class"/>
443           <include name="**/*Test.class"/>
444                 
445           <exclude name="**/SplitInputStreamTest.class"/>
446         </fileset>
447       </batchtest>
448
449     </junit>
450
451     <fail if="test.failed" />
452    
453   </target>
454
455   
456 </project>