Wed, 03 Jul 2013 12:39:28 +0200
8010946: AccessControl.doPrivileged is broken when called from js script
Reviewed-by: jlaskey, sundar
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.
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.
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).
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.
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="test" basedir="..">
25 <import file="build-nasgen.xml"/>
26 <import file="build-benchmark.xml"/>
27 <import file="code_coverage.xml"/>
30 <target name="init-conditions">
31 <!-- loading locally defined resources and properties. NB they owerwrite default ones defined later -->
32 <property file="${user.home}/.nashorn.project.local.properties"/>
34 <loadproperties srcFile="make/project.properties"/>
35 <path id="nashorn.ext.path">
36 <pathelement location="${dist.dir}"/>
37 </path>
38 <property name="ext.class.path" value="-Djava.ext.dirs="${toString:nashorn.ext.path}""/>
39 <condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
40 <available file="/usr/local/bin/svn"/>
41 </condition>
42 <condition property="hg.executable" value="/usr/local/bin/hg" else="hg">
43 <available file="/usr/local/bin/hg"/>
44 </condition>
45 <!-- check if JDK already has ASM classes -->
46 <available property="asm.available" classname="jdk.internal.org.objectweb.asm.Type"/>
47 <!-- check if testng.jar is avaiable -->
48 <available property="testng.available" file="${file.reference.testng.jar}"/>
50 <!-- enable/disable make code coverage -->
51 <condition property="cc.enabled">
52 <istrue value="${make.code.coverage}" />
53 </condition>
54 </target>
56 <target name="init" depends="init-conditions, init-cc">
58 <!-- extends jvm args -->
59 <property name="run.test.jvmargs" value="${run.test.jvmargs.main} ${run.test.cc.jvmargs}"/>
60 <property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main} ${run.test.cc.jvmargs}" />
62 <echo message="run.test.jvmargs=${run.test.jvmargs}"/>
63 <echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/>
65 </target>
67 <target name="prepare" depends="init">
68 <mkdir dir="${build.dir}"/>
69 <mkdir dir="${build.classes.dir}"/>
70 <mkdir dir="${build.classes.dir}/META-INF/services"/>
71 <mkdir dir="${build.test.classes.dir}"/>
72 <mkdir dir="${dist.dir}"/>
73 <mkdir dir="${dist.javadoc.dir}"/>
74 </target>
76 <target name="clean" depends="init, clean-nasgen, init-cc-cleanup">
77 <delete includeemptydirs="true">
78 <fileset dir="${build.dir}" erroronmissingdir="false"/>
79 </delete>
80 <delete dir="${dist.dir}"/>
81 </target>
83 <!-- do it only if ASM is not available -->
84 <target name="compile-asm" depends="prepare" unless="asm.available">
85 <javac srcdir="${jdk.asm.src.dir}"
86 destdir="${build.classes.dir}"
87 excludes="**/optimizer/* **/xml/* **/attrs/*"
88 source="${javac.source}"
89 target="${javac.target}"
90 debug="${javac.debug}"
91 encoding="${javac.encoding}"
92 includeantruntime="false"/>
93 </target>
95 <target name="compile" depends="compile-asm" description="Compiles nashorn">
96 <javac srcdir="${src.dir}"
97 destdir="${build.classes.dir}"
98 classpath="${javac.classpath}"
99 source="${javac.source}"
100 target="${javac.target}"
101 debug="${javac.debug}"
102 encoding="${javac.encoding}"
103 includeantruntime="false">
104 <compilerarg value="-Xlint:unchecked"/>
105 <compilerarg value="-Xlint:deprecation"/>
106 <compilerarg value="-XDignore.symbol.file"/>
107 </javac>
108 <copy todir="${build.classes.dir}/META-INF/services">
109 <fileset dir="${meta.inf.dir}/services/"/>
110 </copy>
111 <copy todir="${build.classes.dir}/jdk/nashorn/api/scripting/resources">
112 <fileset dir="${src.dir}/jdk/nashorn/api/scripting/resources/"/>
113 </copy>
114 <copy todir="${build.classes.dir}/jdk/nashorn/internal/runtime/resources">
115 <fileset dir="${src.dir}/jdk/nashorn/internal/runtime/resources/"/>
116 </copy>
117 <copy todir="${build.classes.dir}/jdk/nashorn/tools/resources">
118 <fileset dir="${src.dir}/jdk/nashorn/tools/resources/"/>
119 </copy>
120 <copy file="${src.dir}/jdk/internal/dynalink/support/messages.properties" todir="${build.classes.dir}/jdk/internal/dynalink/support"/>
122 <echo message="full=${nashorn.fullversion}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
123 <echo file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
124 <echo message="release=${nashorn.version}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
125 </target>
127 <target name="jar" depends="compile, run-nasgen, generate-cc-template" description="Creates nashorn.jar" unless="compile.suppress.jar">
128 <jar jarfile="${dist.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
129 <fileset dir="${build.classes.dir}"/>
130 <manifest>
131 <attribute name="Archiver-Version" value="n/a"/>
132 <attribute name="Build-Jdk" value="${java.runtime.version}"/>
133 <attribute name="Built-By" value="n/a"/>
134 <attribute name="Created-By" value="Ant jar task"/>
135 <section name="jdk/nashorn/">
136 <attribute name="Implementation-Title" value="${nashorn.product.name}"/>
137 <attribute name="Implementation-Version" value="${nashorn.version}"/>
138 </section>
139 </manifest>
140 </jar>
141 </target>
143 <target name="use-promoted-nashorn" depends="init">
144 <delete file="${dist.dir}/nashorn.jar"/>
145 <copy file="${java.home}/lib/ext/nashorn.jar" todir="${dist.dir}"/>
146 <property name="compile.suppress.jar" value="defined"/>
147 </target>
149 <target name="build-fxshell" depends="jar">
150 <description>Builds the javafx shell.</description>
151 <mkdir dir="${fxshell.classes.dir}"/>
152 <javac srcdir="${fxshell.dir}"
153 destdir="${fxshell.classes.dir}"
154 classpath="${dist.jar}:${javac.classpath}"
155 debug="${javac.debug}"
156 encoding="${javac.encoding}"
157 includeantruntime="false">
158 </javac>
159 <jar jarfile="${fxshell.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
160 <fileset dir="${fxshell.classes.dir}"/>
161 <manifest>
162 <attribute name="Archiver-Version" value="n/a"/>
163 <attribute name="Build-Jdk" value="${java.runtime.version}"/>
164 <attribute name="Built-By" value="n/a"/>
165 <attribute name="Created-By" value="Ant jar task"/>
166 <section name="jdk/nashorn/">
167 <attribute name="Implementation-Title" value="Oracle Nashorn FXShell"/>
168 <attribute name="Implementation-Version" value="${nashorn.version}"/>
169 </section>
170 </manifest>
171 </jar>
172 </target>
174 <target name="javadoc" depends="prepare">
175 <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="src/overview.html" windowtitle="${nashorn.product.name} ${nashorn.version}" additionalparam="-quiet" failonerror="true">
176 <classpath>
177 <pathelement location="${build.classes.dir}"/>
178 </classpath>
179 <fileset dir="${src.dir}" includes="**/*.java"/>
180 <fileset dir="${jdk.asm.src.dir}" includes="**/*.java"/>
181 <link href="http://docs.oracle.com/javase/7/docs/api/"/>
182 <!-- The following tags are used only in ASM sources - just ignore these -->
183 <tag name="label" description="label tag in ASM sources" enabled="false"/>
184 <tag name="linked" description="linked tag in ASM sources" enabled="false"/>
185 <tag name="associates" description="associates tag in ASM sources" enabled="false"/>
186 </javadoc>
187 </target>
189 <!-- generate shell.html for shell tool documentation -->
190 <target name="shelldoc" depends="jar">
191 <java classname="${nashorn.shell.tool}" dir="${basedir}" output="${dist.dir}/shell.html" failonerror="true" fork="true">
192 <jvmarg line="${ext.class.path}"/>
193 <arg value="-scripting"/>
194 <arg value="docs/genshelldoc.js"/>
195 </java>
196 </target>
198 <!-- generate all docs -->
199 <target name="docs" depends="javadoc, shelldoc"/>
201 <!-- create .zip and .tar.gz for nashorn binaries and scripts. -->
202 <target name="dist" depends="jar">
203 <zip destfile="${build.zip}" basedir=".."
204 excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
205 <tar destfile="${build.gzip}" basedir=".." compression="gzip"
206 excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
207 </target>
209 <target name="compile-test" depends="compile, run-nasgen" if="testng.available">
210 <!-- testng task -->
211 <taskdef name="testng" classname="org.testng.TestNGAntTask"
212 classpath="${file.reference.testng.jar}"/>
214 <javac srcdir="${test.src.dir}"
215 destdir="${build.test.classes.dir}"
216 classpath="${javac.test.classpath}"
217 source="${javac.source}"
218 target="${javac.target}"
219 debug="${javac.debug}"
220 encoding="${javac.encoding}"
221 includeantruntime="false">
222 <compilerarg line="-extdirs """/>
223 </javac>
225 <!-- tests that check nashorn internals and internal API -->
226 <jar jarfile="${nashorn.internal.tests.jar}">
227 <fileset dir="${build.test.classes.dir}" excludes="**/api/**"/>
228 </jar>
230 <!-- tests that check nashorn script engine (jsr-223) API -->
231 <jar jarfile="${nashorn.api.tests.jar}">
232 <fileset dir="${build.test.classes.dir}" includes="**/api/**"/>
233 </jar>
235 </target>
237 <target name="generate-policy-file" depends="prepare">
238 <echo file="${build.dir}/nashorn.policy">
240 grant codeBase "file:/${basedir}/${nashorn.internal.tests.jar}" {
241 permission java.security.AllPermission;
242 };
244 grant codeBase "file:/${basedir}/${file.reference.testng.jar}" {
245 permission java.security.AllPermission;
246 };
248 grant codeBase "file:/${basedir}/test/script/trusted/*" {
249 permission java.security.AllPermission;
250 };
252 grant codeBase "file:/${basedir}/test/script/basic/*" {
253 permission java.io.FilePermission "${basedir}/test/script/-", "read";
254 permission java.io.FilePermission "$${user.dir}", "read";
255 permission java.util.PropertyPermission "user.dir", "read";
256 permission java.util.PropertyPermission "nashorn.test.*", "read";
257 };
259 grant codeBase "file:/${basedir}/test/script/basic/JDK-8010946-privileged.js" {
260 permission java.util.PropertyPermission "java.security.policy", "read";
261 };
262 </echo>
264 <replace file="${build.dir}/nashorn.policy"><replacetoken>\</replacetoken><replacevalue>/</replacevalue></replace> <!--hack for Windows - to make URLs with normal path separators -->
265 <replace file="${build.dir}/nashorn.policy"><replacetoken>//</replacetoken><replacevalue>/</replacevalue></replace> <!--hack for Unix - to avoid leading // in URLs -->
267 </target>
269 <target name="check-external-tests">
270 <available file="${test.external.dir}/prototype" property="test-sys-prop.external.prototype"/>
271 <available file="${test.external.dir}/sunspider" property="test-sys-prop.external.sunspider"/>
272 <available file="${test.external.dir}/underscore" property="test-sys-prop.external.underscore"/>
273 <available file="${test.external.dir}/octane" property="test-sys-prop.external.octane"/>
274 <available file="${test.external.dir}/yui" property="test-sys-prop.external.yui"/>
275 <available file="${test.external.dir}/jquery" property="test-sys-prop.external.jquery"/>
276 <available file="${test.external.dir}/test262" property="test-sys-prop.external.test262"/>
277 </target>
279 <target name="check-testng" unless="testng.available">
280 <echo message="WARNING: TestNG not available, will not run tests. Please copy testng.jar under test/lib directory."/>
281 </target>
283 <target name="test" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
284 <java classname="${nashorn.shell.tool}" fork="true" dir="${test.script.dir}/representations" output="${build.dir}/output1.log" error="${build.dir}/err.log">
285 <jvmarg line="${ext.class.path}"/>
286 <jvmarg line="-Dnashorn.fields.dual=true"/>
287 <arg value="NASHORN-592a.js"/>
288 </java>
289 <java classname="${nashorn.shell.tool}" fork="true" dir="${test.script.dir}/representations" output="${build.dir}/output2.log" error="${build.dir}/err.log">
290 <jvmarg line="${ext.class.path}"/>
291 <arg value="NASHORN-592a.js"/>
292 </java>
293 <condition property="representation-ok">
294 <filesmatch file1="${build.dir}/output1.log" file2="${build.dir}/output2.log"/>
295 </condition>
296 <fail unless="representation-ok">Representation test failed - output differs!</fail>
297 <fileset id="test.classes" dir="${build.test.classes.dir}">
298 <include name="**/api/javaaccess/*Test.class"/>
299 <include name="**/api/scripting/*Test.class"/>
300 <include name="**/codegen/*Test.class"/>
301 <include name="**/parser/*Test.class"/>
302 <include name="**/runtime/*Test.class"/>
303 <include name="**/runtime/regexp/*Test.class"/>
304 <include name="**/runtime/regexp/joni/*Test.class"/>
305 <include name="**/framework/*Test.class"/>
306 </fileset>
308 <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
309 verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
310 <jvmarg line="${ext.class.path}"/>
311 <jvmarg line="${run.test.jvmargs} ${run.test.jvmsecurityargs}"/>
312 <propertyset>
313 <propertyref prefix="test-sys-prop."/>
314 <mapper from="test-sys-prop.*" to="*" type="glob"/>
315 </propertyset>
316 <classpath>
317 <pathelement path="${run.test.classpath}"/>
318 </classpath>
319 </testng>
320 </target>
322 <target name="test-basicparallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file">
323 <!-- use just build.test.classes.dir to avoid referring to TestNG -->
324 <java classname="${parallel.test.runner}" dir="${basedir}" classpath="${build.test.classes.dir}" failonerror="true" fork="true">
325 <jvmarg line="${ext.class.path}"/>
326 <jvmarg line="${run.test.jvmargs} ${run.test.jvmsecurityargs}"/>
327 <syspropertyset>
328 <propertyref prefix="test-sys-prop."/>
329 <mapper type="glob" from="test-sys-prop.*" to="*"/>
330 </syspropertyset>
331 </java>
332 </target>
334 <target name="test262" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
335 <fileset id="test.classes" dir="${build.test.classes.dir}">
336 <include name="**/framework/*Test.class"/>
337 </fileset>
339 <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
340 verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
341 <jvmarg line="${ext.class.path}"/>
342 <jvmarg line="${run.test.jvmargs} ${run.test.jvmsecurityargs}"/>
343 <propertyset>
344 <propertyref prefix="test262-test-sys-prop."/>
345 <mapper from="test262-test-sys-prop.*" to="*" type="glob"/>
346 </propertyset>
347 <classpath>
348 <pathelement path="${run.test.classpath}"/>
349 </classpath>
350 </testng>
351 </target>
353 <target name="test262parallel" depends="test262-parallel"/>
355 <target name="test262-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
356 <!-- use just build.test.classes.dir to avoid referring to TestNG -->
357 <java classname="${parallel.test.runner}" dir="${basedir}" fork="true">
358 <jvmarg line="${ext.class.path}"/>
359 <jvmarg line="${run.test.jvmargs} ${run.test.jvmsecurityargs}"/>
360 <classpath>
361 <pathelement path="${run.test.classpath}"/>
362 </classpath>
363 <syspropertyset>
364 <propertyref prefix="test262-test-sys-prop."/>
365 <mapper type="glob" from="test262-test-sys-prop.*" to="*"/>
366 </syspropertyset>
367 </java>
368 </target>
370 <target name="all" depends="test, docs"
371 description="Build, test and generate docs for nashorn"/>
373 <target name="run" depends="jar"
374 description="Run the shell with a sample script">
375 <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
376 <jvmarg line="${ext.class.path}"/>
377 <jvmarg line="${run.test.jvmargs}"/>
378 <arg value="-dump-on-error"/>
379 <arg value="test.js"/>
380 </java>
381 </target>
383 <target name="debug" depends="jar"
384 description="Debug the shell with a sample script">
385 <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
386 <jvmarg line="${ext.class.path}"/>
387 <jvmarg line="${run.test.jvmargs}"/>
388 <arg value="--print-code"/>
389 <arg value="--verify-code"/>
390 <arg value="--print-symbols"/>
391 <jvmarg value="-Dnashorn.codegen.debug=true"/>
392 <arg value="test.js"/>
393 </java>
394 </target>
396 <!-- targets to get external script tests -->
398 <!-- test262 test suite -->
399 <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}">
400 <!-- clone test262 mercurial repo -->
401 <exec executable="${hg.executable}">
402 <arg value="clone"/>
403 <arg value="http://hg.ecmascript.org/tests/test262"/>
404 <arg value="${test.external.dir}/test262"/>
405 </exec>
406 </target>
407 <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}">
408 <!-- update test262 mercurial repo -->
409 <exec executable="${hg.executable}" dir="${test.external.dir}/test262">
410 <arg value="pull"/>
411 <arg value="-u"/>
412 </exec>
413 </target>
415 <!-- octane benchmark -->
416 <target name="get-octane" depends="init" unless="${test-sys-prop.external.octane}">
417 <!-- checkout octane benchmarks -->
418 <exec executable="${svn.executable}">
419 <arg value="--non-interactive"/>
420 <arg value="--trust-server-cert"/>
421 <arg value="checkout"/>
422 <arg value="http://octane-benchmark.googlecode.com/svn/trunk/"/>
423 <arg value="${test.external.dir}/octane"/>
424 </exec>
425 </target>
426 <target name="update-octane" depends="init" if="${test-sys-prop.external.octane}">
427 <!-- update octane benchmarks -->
428 <exec executable="${svn.executable}" dir="${test.external.dir}/octane">
429 <arg value="--non-interactive"/>
430 <arg value="--trust-server-cert"/>
431 <arg value="update"/>
432 </exec>
433 </target>
435 <!-- sunspider benchmark -->
436 <target name="get-sunspider" depends="init" unless="${test-sys-prop.external.sunspider}">
437 <!-- checkout sunspider -->
438 <exec executable="${svn.executable}">
439 <arg value="--non-interactive"/>
440 <arg value="--trust-server-cert"/>
441 <arg value="checkout"/>
442 <arg value="http://svn.webkit.org/repository/webkit/trunk/PerformanceTests/SunSpider"/>
443 <arg value="${test.external.dir}/sunspider"/>
444 </exec>
445 </target>
446 <target name="update-sunspider" depends="init" if="${test-sys-prop.external.sunspider}">
447 <!-- update sunspider -->
448 <exec executable="${svn.executable}" dir="${test.external.dir}/sunspider">
449 <arg value="--non-interactive"/>
450 <arg value="--trust-server-cert"/>
451 <arg value="update"/>
452 </exec>
453 </target>
455 <!-- get all external test scripts -->
456 <target name="externals" depends="init, check-external-tests, get-test262, get-octane, get-sunspider">
457 <!-- make external test dir -->
458 <mkdir dir="${test.external.dir}"/>
460 <!-- jquery -->
461 <mkdir dir="${test.external.dir}/jquery"/>
462 <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
463 <get src="http://code.jquery.com/jquery-1.7.2.min.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
465 <!-- prototype -->
466 <mkdir dir="${test.external.dir}/prototype"/>
467 <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"/>
469 <!-- underscorejs -->
470 <mkdir dir="${test.external.dir}/underscore"/>
471 <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
472 <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
474 <!-- yui -->
475 <mkdir dir="${test.external.dir}/yui"/>
476 <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
477 <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
479 </target>
481 <!-- update external test suites that are pulled from source control systems -->
482 <target name="update-externals" depends="init, check-external-tests, update-test262, update-octane, update-sunspider"/>
484 <!-- run all perf tests -->
485 <target name="perf" depends="externals, update-externals, sunspider, octane"/>
487 <!-- run all tests -->
488 <target name="exit-if-no-testng" depends="init, check-testng" unless="${testng.available}">
489 <fail message="Exiting.."/>
490 </target>
492 <target name="alltests" depends="exit-if-no-testng, externals, update-externals, test, test262parallel, perf"/>
494 </project>