build.xml revision 18:4cd65798ec70
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
6 This code is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License version 2 only, as
8 published by the Free Software Foundation.
9
10 This code is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 version 2 for more details (a copy is included in the LICENSE file that
14 accompanied this code).
15
16 You should have received a copy of the GNU General Public License version
17 2 along with this work; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 or visit www.oracle.com if you need additional information or have any
22 questions.
23-->
24<project name="nashorn" default="all" basedir="..">
25  <import file="build-nasgen.xml"/>
26  <import file="build-benchmark.xml"/>
27
28  <target name="init">
29    <loadproperties srcFile="make/project.properties"/>
30    <path id="nashorn.ext.path">
31      <pathelement location="${dist.dir}"/>
32    </path>
33    <property name="ext.class.path" value="-Djava.ext.dirs=&quot;${toString:nashorn.ext.path}&quot;"/>
34    <condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
35      <available file="/usr/local/bin/svn"/>
36    </condition>
37    <condition property="hg.executable" value="/usr/local/bin/hg" else="hg">
38      <available file="/usr/local/bin/hg"/>
39    </condition>
40  </target>
41
42  <target name="prepare" depends="init">
43    <mkdir dir="${build.dir}"/>
44    <mkdir dir="${build.classes.dir}"/>
45    <mkdir dir="${build.classes.dir}/META-INF/services"/>
46    <mkdir dir="${build.test.classes.dir}"/>
47    <mkdir dir="${dist.dir}"/>
48    <mkdir dir="${dist.javadoc.dir}"/>
49    <!-- check if JDK already has ASM classes -->
50    <available property="asm.available" classname="jdk.internal.org.objectweb.asm.Type"/>
51    <!-- check if testng.jar is avaiable -->
52    <available property="testng.available" file="${file.reference.testng.jar}"/>
53  </target>
54
55  <target name="clean" depends="init, clean-nasgen">
56    <delete includeemptydirs="true">
57      <fileset dir="${build.dir}" excludes="${dynalink.dir.name}/**/*" erroronmissingdir="false"/>
58    </delete>
59    <delete dir="${dist.dir}"/>
60  </target>
61
62  <target name="clean-dynalink">
63    <delete dir="${dynalink.dir}"/>
64  </target>
65
66  <target name="clean-all" depends="clean-dynalink, clean">
67    <delete dir="${build.dir}"/>
68  </target>
69
70  <!-- do it only if ASM is not available -->
71  <target name="compile-asm" depends="prepare" unless="asm.available">
72    <javac srcdir="${jdk.asm.src.dir}"
73           destdir="${build.classes.dir}"
74           excludes="**/optimizer/* **/xml/* **/attrs/*"
75           source="${javac.source}"
76           target="${javac.target}"
77           debug="${javac.debug}"
78           encoding="${javac.encoding}"
79           includeantruntime="false"/>
80  </target>
81
82  <target name="check-dynalink-uptodate" depends="init">
83    <property name="versioned.dynalink.jar" value="${dynalink.dir}/dynalink-${dynalink.jar.version}.jar"/>
84    <condition property="dynalink.uptodate">
85      <and>
86        <available file="${versioned.dynalink.jar}"/>
87        <filesmatch file1="${versioned.dynalink.jar}" file2="${dynalink.jar}"/>
88      </and>
89    </condition>
90  </target>
91
92  <target name="get-dynalink" depends="check-dynalink-uptodate" unless="dynalink.uptodate">
93    <mkdir dir="${dynalink.dir}"/>
94    <!-- Delete previous snapshots, if any -->
95    <delete>
96      <fileset dir="${dynalink.dir}" includes="*"/>
97    </delete>
98    <property name="dynalink.download.base.url" value="http://oss.sonatype.org/content/repositories/${dynalink.version.type}s/org/dynalang/dynalink/${dynalink.version}/dynalink-${dynalink.jar.version}"/>
99    <get src="${dynalink.download.base.url}.jar" dest="${versioned.dynalink.jar}" usetimestamp="true"/>
100    <get src="${dynalink.download.base.url}-sources.jar" dest="${dynalink.dir}/dynalink-sources.jar" usetimestamp="true"/>
101    <copy file="${versioned.dynalink.jar}" tofile="${dynalink.jar}" overwrite="true"/>
102  </target>
103
104  <target name="compile" depends="compile-asm, get-dynalink" description="Compiles nashorn">
105    <javac srcdir="${src.dir}"
106           destdir="${build.classes.dir}"
107           classpath="${javac.classpath}"
108           source="${javac.source}"
109           target="${javac.target}"
110           debug="${javac.debug}"
111           encoding="${javac.encoding}"
112           includeantruntime="false">
113      <compilerarg value="-Xlint:unchecked"/>
114      <compilerarg value="-Xlint:deprecation"/>
115      <compilerarg value="-XDignore.symbol.file"/>
116    </javac>
117    <copy todir="${build.classes.dir}/META-INF/services">
118       <fileset dir="${meta.inf.dir}/services/"/>
119    </copy>
120     <copy todir="${build.classes.dir}/jdk/nashorn/api/scripting/resources">
121       <fileset dir="${src.dir}/jdk/nashorn/api/scripting/resources/"/>
122    </copy>
123    <copy todir="${build.classes.dir}/jdk/nashorn/internal/runtime/resources">
124       <fileset dir="${src.dir}/jdk/nashorn/internal/runtime/resources/"/>
125    </copy>
126    <copy todir="${build.classes.dir}/jdk/nashorn/tools/resources">
127       <fileset dir="${src.dir}/jdk/nashorn/tools/resources/"/>
128    </copy>
129    <echo message="full=${nashorn.fullversion}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
130    <echo file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
131    <echo message="release=${nashorn.version}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
132  </target>
133
134  <target name="jar" depends="compile, run-nasgen" description="Creates nashorn.jar">
135    <jar jarfile="${dist.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
136      <fileset dir="${build.classes.dir}"/>
137      <zipfileset src="${dynalink.jar}"/>
138      <manifest>
139        <attribute name="Archiver-Version" value="n/a"/>
140        <attribute name="Build-Jdk" value="${java.runtime.version}"/>
141        <attribute name="Built-By" value="n/a"/>
142        <attribute name="Created-By" value="Ant jar task"/>
143        <section name="jdk/nashorn/">
144          <attribute name="Implementation-Title" value="${nashorn.product.name}"/>
145          <attribute name="Implementation-Version" value="${nashorn.version}"/>
146        </section>
147      </manifest>
148    </jar>
149  </target>
150
151  <target name="javadoc" depends="prepare">
152    <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="src/overview.html" windowtitle="${nashorn.product.name} ${nashorn.version}" additionalparam="-quiet" failonerror="true">
153      <classpath>
154        <pathelement location="${build.classes.dir}"/>
155        <pathelement location="${dynalink.jar}"/>
156      </classpath>
157      <fileset dir="${src.dir}" includes="**/*.java"/>
158      <fileset dir="${jdk.asm.src.dir}" includes="**/*.java"/>
159      <link href="http://docs.oracle.com/javase/7/docs/api/"/>
160      <link href="http://szegedi.github.com/dynalink/0.4/javadoc/"/>
161      <!-- The following tags are used only in ASM sources - just ignore these -->
162      <tag name="label" description="label tag in ASM sources" enabled="false"/>
163      <tag name="linked" description="linked tag in ASM sources" enabled="false"/>
164      <tag name="associates" description="associates tag in ASM sources" enabled="false"/>
165    </javadoc>
166  </target>
167
168  <!-- generate shell.html for shell tool documentation -->
169  <target name="shelldoc" depends="jar">
170    <java classname="${nashorn.shell.tool}" dir="${basedir}" output="${dist.dir}/shell.html" failonerror="true" fork="true">
171      <jvmarg line="${ext.class.path}"/>
172      <arg value="-scripting"/>
173      <arg value="docs/genshelldoc.js"/>
174    </java>
175  </target>
176
177  <!-- generate all docs -->
178  <target name="docs" depends="javadoc, shelldoc"/>
179
180  <!-- create .zip and .tar.gz for nashorn binaries and scripts. -->
181  <target name="dist" depends="jar">
182      <zip destfile="${build.zip}" basedir=".."
183          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
184      <tar destfile="${build.gzip}" basedir=".." compression="gzip"
185          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
186  </target>
187
188  <target name="compile-test" depends="compile, run-nasgen" if="testng.available">
189    <!-- testng task -->
190    <taskdef name="testng" classname="org.testng.TestNGAntTask"
191        classpath="${file.reference.testng.jar}"/>
192
193    <javac srcdir="${test.src.dir}"
194           destdir="${build.test.classes.dir}"
195           classpath="${javac.test.classpath}"
196           source="${javac.source}"
197           target="${javac.target}"
198           debug="${javac.debug}"
199           encoding="${javac.encoding}"
200           includeantruntime="false"/>
201  </target>
202
203  <target name="generate-policy-file">
204    <!-- Generating nashorn.policy file -->
205    <echo message="grant codeBase &quot;file:/${basedir}/dist/nashorn.jar&quot; {" file="${build.dir}/nashorn.policy"/>
206    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
207    <echo message="permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
208    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
209    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
210    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
211
212    <echo message="grant codeBase &quot;file:/${basedir}/build/test/classes&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
213    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
214    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
215    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
216    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
217    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
218
219    <echo message="grant codeBase &quot;file:/${basedir}/${file.reference.testng.jar}&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
220    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
221    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
222    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
223    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
224    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
225
226    <echo message="grant codeBase &quot;file:/${basedir}/test/script/basic/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
227    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
228    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
229    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
230    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
231    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
232
233    <echo message="grant codeBase &quot;file:/${basedir}/test/perf/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
234    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
235    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
236    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
237    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
238    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
239
240    <replace file="${build.dir}/nashorn.policy"><replacetoken>\</replacetoken><replacevalue>/</replacevalue></replace>    <!--hack for Windows - to make URLs with normal path separators -->
241    <replace file="${build.dir}/nashorn.policy"><replacetoken>//</replacetoken><replacevalue>/</replacevalue></replace>   <!--hack for Unix - to avoid leading // in URLs -->
242
243  </target>
244
245  <target name="check-external-tests">
246      <available file="${test.external.dir}/prototype" property="test-sys-prop.external.prototype"/>
247      <available file="${test.external.dir}/sunspider" property="test-sys-prop.external.sunspider"/>
248      <available file="${test.external.dir}/underscore" property="test-sys-prop.external.underscore"/>
249      <available file="${test.external.dir}/octane" property="test-sys-prop.external.octane"/>
250      <available file="${test.external.dir}/yui" property="test-sys-prop.external.yui"/>
251      <available file="${test.external.dir}/jquery" property="test-sys-prop.external.jquery"/>
252      <available file="${test.external.dir}/test262" property="test-sys-prop.external.test262"/>
253  </target>
254
255  <target name="check-testng" unless="testng.available">
256    <echo message="WARNING: TestNG not available, will not run tests. Please copy testng.jar under test/lib directory."/>
257  </target>
258
259  <target name="test" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
260    <java classname="${nashorn.shell.tool}" fork="true" dir="${test.script.dir}/representations" output="${build.dir}/output1.log" error="${build.dir}/err.log">
261      <jvmarg line="${ext.class.path}"/>
262      <jvmarg line="-Dnashorn.fields.dual=true"/>
263      <arg value="NASHORN-592a.js"/>
264    </java>
265    <java classname="${nashorn.shell.tool}" fork="true" dir="${test.script.dir}/representations" output="${build.dir}/output2.log" error="${build.dir}/err.log">
266      <jvmarg line="${ext.class.path}"/>
267      <arg value="NASHORN-592a.js"/>
268    </java>
269    <condition property="representation-ok">
270      <filesmatch file1="${build.dir}/output1.log" file2="${build.dir}/output2.log"/>
271    </condition>
272    <fail unless="representation-ok">Representation test failed - output differs!</fail>
273    <fileset id="test.classes" dir="${build.test.classes.dir}">
274      <include name="**/access/*Test.class"/>
275      <include name="**/api/scripting/*Test.class"/>
276      <include name="**/codegen/*Test.class"/>
277      <include name="**/parser/*Test.class"/>
278      <include name="**/runtime/*Test.class"/>
279      <include name="**/framework/*Test.class"/>
280    </fileset>
281
282    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
283       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
284      <jvmarg line="${ext.class.path}"/>
285      <jvmarg line="${run.test.jvmargs} ${run.test.jvmsecurityargs}"/>
286      <propertyset>
287        <propertyref prefix="test-sys-prop."/>
288        <mapper from="test-sys-prop.*" to="*" type="glob"/>
289      </propertyset>
290      <classpath>
291          <pathelement path="${run.test.classpath}"/>
292      </classpath>
293    </testng>
294  </target>
295
296  <target name="test-basicparallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file">
297      <!-- use just build.test.classes.dir to avoid referring to TestNG -->
298      <java classname="${parallel.test.runner}" dir="${basedir}" classpath="${build.test.classes.dir}" failonerror="true" fork="true">
299      <jvmarg line="${ext.class.path}"/>
300      <jvmarg line="${run.test.jvmargs} ${run.test.jvmsecurityargs}"/>
301      <syspropertyset>
302          <propertyref prefix="test-sys-prop."/>
303          <mapper type="glob" from="test-sys-prop.*" to="*"/>
304      </syspropertyset>
305      </java>
306  </target>
307
308  <target name="test262" depends="jar, check-testng, check-external-tests, compile-test" if="testng.available">
309    <fileset id="test.classes" dir="${build.test.classes.dir}">
310       <include name="**/framework/*Test.class"/>
311    </fileset>
312
313    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
314       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
315      <jvmarg line="${ext.class.path}"/>
316      <jvmarg line="${run.test.jvmargs}"/>
317      <propertyset>
318        <propertyref prefix="test262-test-sys-prop."/>
319        <mapper from="test262-test-sys-prop.*" to="*" type="glob"/>
320      </propertyset>
321      <classpath>
322          <pathelement path="${run.test.classpath}"/>
323      </classpath>
324    </testng>
325  </target>
326
327  <target name="test262parallel" depends="test262-parallel"/>
328
329  <target name="test262-parallel" depends="jar, check-testng, check-external-tests, compile-test" if="testng.available">
330    <!-- use just build.test.classes.dir to avoid referring to TestNG -->
331    <java classname="${parallel.test.runner}" dir="${basedir}" classpath="${build.test.classes.dir}" fork="true">
332      <jvmarg line="${ext.class.path}"/>
333      <jvmarg line="${run.test.jvmargs}"/>
334      <syspropertyset>
335          <propertyref prefix="test262-test-sys-prop."/>
336          <mapper type="glob" from="test262-test-sys-prop.*" to="*"/>
337      </syspropertyset>
338    </java>
339  </target>
340
341  <target name="all" depends="test, docs"
342      description="Build, test and generate docs for nashorn"/>
343
344  <target name="run" depends="jar"
345      description="Run the shell with a sample script">
346    <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
347        <jvmarg line="${ext.class.path}"/>
348        <jvmarg line="${run.test.jvmargs}"/>
349        <arg value="-dump-on-error"/>
350        <arg value="test.js"/>
351    </java>
352  </target>
353
354  <target name="debug" depends="jar"
355      description="Debug the shell with a sample script">
356    <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
357        <jvmarg line="${ext.class.path}"/>
358        <jvmarg line="${run.test.jvmargs}"/>
359        <arg value="--print-code"/>
360        <arg value="--verify-code"/>
361        <arg value="--print-symbols"/>
362        <jvmarg value="-Dnashorn.codegen.debug=true"/>
363        <arg value="test.js"/>
364    </java>
365  </target>
366
367  <!-- targets to get external script tests -->
368
369  <!-- test262 test suite -->
370  <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}">
371    <!-- clone test262 mercurial repo -->
372    <exec executable="${hg.executable}">
373       <arg value="clone"/>
374       <arg value="http://hg.ecmascript.org/tests/test262"/>
375       <arg value="${test.external.dir}/test262"/>
376    </exec>
377  </target>
378  <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}">
379    <!-- update test262 mercurial repo -->
380    <exec executable="${hg.executable}" dir="${test.external.dir}/test262">
381       <arg value="pull"/>
382       <arg value="-u"/>
383    </exec>
384  </target>
385
386  <!-- octane benchmark -->
387  <target name="get-octane" depends="init" unless="${test-sys-prop.external.octane}">
388    <!-- checkout octane benchmarks -->
389    <exec executable="${svn.executable}">
390       <arg value="--non-interactive"/>
391       <arg value="--trust-server-cert"/>
392       <arg value="checkout"/>
393       <arg value="http://octane-benchmark.googlecode.com/svn/trunk/"/>
394       <arg value="${test.external.dir}/octane"/>
395    </exec>
396  </target>
397  <target name="update-octane" depends="init" if="${test-sys-prop.external.octane}">
398    <!-- update octane benchmarks -->
399    <exec executable="${svn.executable}" dir="${test.external.dir}/octane">
400       <arg value="--non-interactive"/>
401       <arg value="--trust-server-cert"/>
402       <arg value="update"/>
403    </exec>
404  </target>
405
406  <!-- sunspider benchmark -->
407  <target name="get-sunspider" depends="init" unless="${test-sys-prop.external.sunspider}">
408    <!-- checkout sunspider -->
409    <exec executable="${svn.executable}">
410       <arg value="--non-interactive"/>
411       <arg value="--trust-server-cert"/>
412       <arg value="checkout"/>
413       <arg value="http://svn.webkit.org/repository/webkit/trunk/PerformanceTests/SunSpider"/>
414       <arg value="${test.external.dir}/sunspider"/>
415    </exec>
416  </target>
417  <target name="update-sunspider" depends="init" if="${test-sys-prop.external.sunspider}">
418    <!-- update sunspider -->
419    <exec executable="${svn.executable}" dir="${test.external.dir}/sunspider">
420       <arg value="--non-interactive"/>
421       <arg value="--trust-server-cert"/>
422       <arg value="update"/>
423    </exec>
424  </target>
425
426  <!-- get all external test scripts -->
427  <target name="externals" depends="prepare, check-external-tests, get-test262, get-octane, get-sunspider">
428    <!-- make external test dir -->
429    <mkdir dir="${test.external.dir}"/> 
430
431    <!-- jquery -->
432    <mkdir dir="${test.external.dir}/jquery"/>    
433    <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
434    <get src="http://code.jquery.com/jquery-1.7.2.min.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
435
436    <!-- prototype -->
437    <mkdir dir="${test.external.dir}/prototype"/>    
438    <get src="http://ajax.googleapis.com/ajax/libs/prototype/1.7.0/prototype.js" dest="${test.external.dir}/prototype" usetimestamp="true" skipexisting="true" ignoreerrors="true"/>
439
440    <!-- underscorejs -->
441    <mkdir dir="${test.external.dir}/underscore"/> 
442    <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
443    <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
444
445    <!-- yui -->
446    <mkdir dir="${test.external.dir}/yui"/> 
447    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
448    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
449
450  </target>
451
452  <!-- update external test suites that are pulled from source control systems -->
453  <target name="update-externals" depends="prepare, check-external-tests, update-test262, update-octane, update-sunspider"/>
454
455</project>
456