aboutsummaryrefslogtreecommitdiff
path: root/make/build.xml
blob: f6de558959907cd5999e42b9933c1815d4b4e45d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
<?xml version="1.0" encoding="UTF-8"?>

<!--
 Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

 This code is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License version 2 only, as
 published by the Free Software Foundation.

 This code is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 version 2 for more details (a copy is included in the LICENSE file that
 accompanied this code).

 You should have received a copy of the GNU General Public License version
 2 along with this work; if not, write to the Free Software Foundation,
 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 or visit www.oracle.com if you need additional information or have any
 questions.
-->

<project name="nashorn" default="test" basedir="..">
  <import file="build-nasgen.xml"/>
  <import file="code_coverage.xml"/>

  <target name="init-conditions">
    <!-- loading locally defined resources and properties. NB they owerwrite default ones defined later -->
    <property file="${user.home}/.nashorn.project.local.properties"/>

    <loadproperties srcFile="make/project.properties"/>
    <path id="dist.path">
         <pathelement location="${dist.dir}"/>
    </path>
    <path id="nashorn.ext.path">
      <pathelement location="${dist.dir}"/>
      <pathelement location="${java.ext.dirs}"/>
    </path>
    <property name="ext.class.path" value="-Djava.ext.dirs=&quot;${toString:nashorn.ext.path}&quot;"/>
    <condition property="svn.executable" value="/usr/local/bin/svn" else="svn">
      <available file="/usr/local/bin/svn"/>
    </condition>
    <condition property="hg.executable" value="/usr/local/bin/hg" else="hg">
      <available file="/usr/local/bin/hg"/>
    </condition>
    <condition property="git.executable" value="/usr/local/bin/git" else="git">
      <available file="/usr/local/bin/git"/>
    </condition>
    <!-- check if testng.jar is avaiable -->
    <available property="testng.available" file="${file.reference.testng.jar}"/>
    <!-- check if Jemmy ang testng.jar are avaiable -->
    <condition property="jemmy.jfx.testng.available" value="true">
      <and>
        <available file="${file.reference.jemmyfx.jar}"/>
        <available file="${file.reference.jemmycore.jar}"/>
        <available file="${file.reference.jemmyawtinput.jar}"/>
        <available file="${file.reference.jfxrt.jar}"/>
        <isset property="testng.available"/>
      </and>
    </condition>

    <!-- enable/disable make code coverage -->
    <condition property="cc.enabled">
        <istrue value="${make.code.coverage}" />
    </condition>

    <!-- exclude tests in exclude lists -->
    <condition property="exclude.list" value="./exclude/exclude_list_cc.txt" else="./exclude/exclude_list.txt">
      <istrue value="${make.code.coverage}" />
    </condition>

    <condition property="jfr.options" value="${run.test.jvmargs.jfr}" else="">
      <istrue value="${jfr}"/>
    </condition>
  </target>

  <!-- check minimum ant version required to be 1.8.4 -->
  <target name="check-ant-version">
    <property name="ant.version.required" value="1.8.4"/>
    <antversion property="ant.current.version" />
    <fail message="The current ant version, ${ant.current.version}, is too old. Please use 1.8.4 or above.">
        <condition>
            <not>
                <antversion atleast="${ant.version.required}"/>
            </not>
        </condition>
    </fail>
  </target>

  <target name="check-java-version">
    <!-- look for a Class that is available only in jdk1.8 or above -->
    <!-- core/exposed API class is better than an implementation class -->
    <available property="jdk1.8+" classname="java.util.stream.Stream"/>

    <!-- need jdk1.8 or above -->
    <fail message="Unsupported Java version: ${ant.java.version}. Please use Java version 1.8 or greater." unless="jdk1.8+">
    </fail>
  </target>
  
  <target name="init" depends="check-ant-version, check-java-version, init-conditions, init-cc">
    <!-- extends jvm args -->
    <property name="run.test.jvmargs" value="${run.test.jvmargs.main} ${run.test.cc.jvmargs} ${jfr.options}"/>
    <property name="run.test.jvmargs.octane" value="${run.test.jvmargs.octane.main} ${run.test.cc.jvmargs} ${jfr.options}"/>

    <echo message="run.test.jvmargs=${run.test.jvmargs}"/>
    <echo message="run.test.jvmargs.octane=${run.test.jvmargs.octane}"/>
    <echo message="run.test.xms=${run.test.xms}"/>
    <echo message="run.test.xmx=${run.test.xmx}"/>

  </target>

  <target name="prepare" depends="init">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${build.classes.dir}/META-INF/services"/>
    <mkdir dir="${build.test.classes.dir}"/>
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${dist.javadoc.dir}"/>
  </target>

  <target name="clean" depends="init, clean-nasgen, init-cc-cleanup">
    <delete includeemptydirs="true">
      <fileset dir="${build.dir}" erroronmissingdir="false"/>
    </delete>
    <delete dir="${dist.dir}"/>
  </target>

  <target name="compile" depends="prepare" description="Compiles nashorn">
    <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           classpath="${javac.classpath}"
           source="${javac.source}"
           target="${javac.target}"
           debug="${javac.debug}"
           encoding="${javac.encoding}"
           includeantruntime="false" fork="true">
      <compilerarg value="-J-Djava.ext.dirs="/>
      <compilerarg value="-Xlint:all"/>
      <compilerarg value="-XDignore.symbol.file"/>
      <compilerarg value="-Xdiags:verbose"/>
    </javac>
    <copy todir="${build.classes.dir}/META-INF/services">
       <fileset dir="${meta.inf.dir}/services/"/>
    </copy>
     <copy todir="${build.classes.dir}/jdk/nashorn/api/scripting/resources">
       <fileset dir="${src.dir}/jdk/nashorn/api/scripting/resources/"/>
    </copy>
    <copy todir="${build.classes.dir}/jdk/nashorn/internal/runtime/resources">
       <fileset dir="${src.dir}/jdk/nashorn/internal/runtime/resources/"/>
    </copy>
    <copy todir="${build.classes.dir}/jdk/nashorn/tools/resources">
       <fileset dir="${src.dir}/jdk/nashorn/tools/resources/"/>
    </copy>
    <copy file="${src.dir}/jdk/internal/dynalink/support/messages.properties" todir="${build.classes.dir}/jdk/internal/dynalink/support"/>

    <echo message="full=${nashorn.fullversion}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties"/>
    <echo file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true">${line.separator}</echo>
    <echo message="release=${nashorn.version}" file="${build.classes.dir}/jdk/nashorn/internal/runtime/resources/version.properties" append="true"/>
  </target>

  <target name="jar" depends="compile, run-nasgen, generate-cc-template" description="Creates nashorn.jar" unless="compile.suppress.jar">
    <jar jarfile="${dist.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
      <fileset dir="${build.classes.dir}"/>
      <manifest>
        <attribute name="Archiver-Version" value="n/a"/>
        <attribute name="Build-Jdk" value="${java.runtime.version}"/>
        <attribute name="Built-By" value="n/a"/>
        <attribute name="Created-By" value="Ant jar task"/>
        <section name="jdk/nashorn/">
          <attribute name="Implementation-Title" value="${nashorn.product.name}"/>
          <attribute name="Implementation-Version" value="${nashorn.version}"/>
        </section>
      </manifest>
    </jar>
  </target>

  <target name="use-promoted-nashorn" depends="init">
    <delete file="${dist.dir}/nashorn.jar"/>
    <copy file="${java.home}/lib/ext/nashorn.jar" todir="${dist.dir}"/>
    <property name="compile.suppress.jar" value="defined"/>
  </target>

  <target name="build-fxshell" depends="jar">
    <description>Builds the javafx shell.</description>
    <mkdir dir="${fxshell.classes.dir}"/>
    <javac srcdir="${fxshell.dir}"
           destdir="${fxshell.classes.dir}"
           classpath="${dist.jar}:${javac.classpath}"
           debug="${javac.debug}"
           encoding="${javac.encoding}"
           includeantruntime="false">
    </javac>
    <jar jarfile="${fxshell.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
      <fileset dir="${fxshell.classes.dir}"/>
      <manifest>
        <attribute name="Archiver-Version" value="n/a"/>
        <attribute name="Build-Jdk" value="${java.runtime.version}"/>
        <attribute name="Built-By" value="n/a"/>
        <attribute name="Created-By" value="Ant jar task"/>
        <section name="jdk/nashorn/">
          <attribute name="Implementation-Title" value="Oracle Nashorn FXShell"/>
          <attribute name="Implementation-Version" value="${nashorn.version}"/>
        </section>
      </manifest>
    </jar>
  </target>

  <target name="javadoc" depends="jar">
    <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="src/overview.html" 
        extdirs="${nashorn.ext.path}" windowtitle="${nashorn.product.name} ${nashorn.version}"
        additionalparam="-quiet" failonerror="true">
      <classpath>
        <pathelement location="${build.classes.dir}"/>
      </classpath>
      <fileset dir="${src.dir}" includes="**/*.java"/>
      <fileset dir="${jdk.asm.src.dir}" includes="**/*.java"/>
      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
      <!-- The following tags are used only in ASM sources - just ignore these -->
      <tag name="label" description="label tag in ASM sources" enabled="false"/>
      <tag name="linked" description="linked tag in ASM sources" enabled="false"/>
      <tag name="associates" description="associates tag in ASM sources" enabled="false"/>
    </javadoc>
  </target>

  <!-- generate javadoc only for nashorn extension api classes -->
  <target name="javadocapi" depends="jar">
    <javadoc destdir="${dist.javadoc.dir}" use="yes" extdirs="${nashorn.ext.path}" 
        windowtitle="${nashorn.product.name}" additionalparam="-quiet" failonerror="true">
      <classpath>
        <pathelement location="${build.classes.dir}"/>
      </classpath>
      <fileset dir="${src.dir}" includes="jdk/nashorn/api/**/*.java"/>
      <link href="http://docs.oracle.com/javase/8/docs/api/"/>
    </javadoc>
  </target>


  <!-- generate shell.html for shell tool documentation -->
  <target name="shelldoc" depends="jar">
    <java classname="${nashorn.shell.tool}" dir="${basedir}" output="${dist.dir}/shell.html" failonerror="true" fork="true">
      <jvmarg line="${ext.class.path}"/>
      <arg value="-scripting"/>
      <arg value="docs/genshelldoc.js"/>
    </java>
  </target>

  <!-- generate all docs -->
  <target name="docs" depends="javadoc, shelldoc"/>

  <!-- create .zip and .tar.gz for nashorn binaries and scripts. -->
  <target name="dist" depends="jar">
      <zip destfile="${build.zip}" basedir=".."
          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
      <tar destfile="${build.gzip}" basedir=".." compression="gzip"
          excludes="nashorn/bin/*.sh" includes="nashorn/bin/** nashorn/dist/**"/>
  </target>

  <target name="compile-test" depends="compile, run-nasgen" if="testng.available">
    <!-- testng task -->
    <taskdef name="testng" classname="org.testng.TestNGAntTask"
        classpath="${file.reference.testng.jar}"/>

    <javac srcdir="${test.src.dir}"
           destdir="${build.test.classes.dir}"
           classpath="${javac.test.classpath}"
           source="${javac.source}"
           target="${javac.target}"
           debug="${javac.debug}"
           encoding="${javac.encoding}"
           includeantruntime="false" fork="true">
        <compilerarg value="-J-Djava.ext.dirs="/>
        <compilerarg value="-Xlint:unchecked"/>
        <compilerarg value="-Xlint:deprecation"/>
        <compilerarg value="-Xdiags:verbose"/>
    </javac>

    <copy todir="${build.test.classes.dir}/META-INF/services">
       <fileset dir="${test.src.dir}/META-INF/services/"/>
    </copy>

    <copy todir="${build.test.classes.dir}/jdk/nashorn/internal/runtime/resources">
       <fileset dir="${test.src.dir}/jdk/nashorn/internal/runtime/resources"/>
    </copy>

    <copy todir="${build.test.classes.dir}/jdk/nashorn/api/scripting/resources">
       <fileset dir="${test.src.dir}/jdk/nashorn/api/scripting/resources"/>
    </copy>

    <!-- tests that check nashorn internals and internal API -->
    <jar jarfile="${nashorn.internal.tests.jar}">
      <fileset dir="${build.test.classes.dir}" excludes="**/api/**"/>
    </jar>

    <!-- tests that check nashorn script engine (jsr-223) API -->
    <jar jarfile="${nashorn.api.tests.jar}">
      <fileset dir="${build.test.classes.dir}" includes="**/api/**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/META-INF/**"/>
      <fileset dir="${build.test.classes.dir}" includes="**/resources/*.js"/>
    </jar>

  </target>

  <target name="generate-policy-file" depends="prepare">
    <echo file="${build.dir}/nashorn.policy">

grant codeBase "file:/${toString:dist.path}/nashorn.jar" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${basedir}/${nashorn.internal.tests.jar}" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${basedir}/${file.reference.testng.jar}" {
    permission java.security.AllPermission;
};
//// in case of absolute path:
grant codeBase "file:/${nashorn.internal.tests.jar}" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${file.reference.testng.jar}" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${basedir}/test/script/trusted/*" {
    permission java.security.AllPermission;
};

grant codeBase "file:/${basedir}/test/script/maptests/*" {
    permission java.io.FilePermission "${basedir}/test/script/maptests/*","read";
    permission java.lang.RuntimePermission "nashorn.debugMode";
};

grant codeBase "file:/${basedir}/test/script/basic/*" {
    permission java.io.FilePermission "${basedir}/test/script/-", "read";
    permission java.io.FilePermission "$${user.dir}", "read";
    permission java.util.PropertyPermission "user.dir", "read";
    permission java.util.PropertyPermission "nashorn.test.*", "read";
};

grant codeBase "file:/${basedir}/test/script/basic/parser/*" {
    permission java.io.FilePermission "${basedir}/test/script/-", "read";
    permission java.io.FilePermission "$${user.dir}", "read";
    permission java.util.PropertyPermission "user.dir", "read";
    permission java.util.PropertyPermission "nashorn.test.*", "read";
};

grant codeBase "file:/${basedir}/test/script/basic/es6/*" {
    permission java.io.FilePermission "${basedir}/test/script/-", "read";
    permission java.io.FilePermission "$${user.dir}", "read";
    permission java.util.PropertyPermission "user.dir", "read";
    permission java.util.PropertyPermission "nashorn.test.*", "read";
};

grant codeBase "file:/${basedir}/test/script/basic/JDK-8010946-privileged.js" {
    permission java.util.PropertyPermission "java.security.policy", "read";
};

grant codeBase "file:/${basedir}/test/script/basic/classloader.js" {
    permission java.lang.RuntimePermission "nashorn.JavaReflection";
};

grant codeBase "file:/${basedir}/test/script/markdown.js" {
    permission java.io.FilePermission "${basedir}/test/script/external/showdown/-", "read";
};

    </echo>

    <replace file="${build.dir}/nashorn.policy"><replacetoken>\</replacetoken><replacevalue>/</replacevalue></replace>    <!--hack for Windows - to make URLs with normal path separators -->
    <replace file="${build.dir}/nashorn.policy"><replacetoken>//</replacetoken><replacevalue>/</replacevalue></replace>   <!--hack for Unix - to avoid leading // in URLs -->

  </target>

  <target name="check-external-tests">
      <available file="${test.external.dir}/prototype" property="test-sys-prop.external.prototype"/>
      <available file="${test.external.dir}/sunspider" property="test-sys-prop.external.sunspider"/>
      <available file="${test.external.dir}/underscore" property="test-sys-prop.external.underscore"/>
      <available file="${test.external.dir}/octane" property="test-sys-prop.external.octane"/>
      <available file="${test.external.dir}/yui" property="test-sys-prop.external.yui"/>
      <available file="${test.external.dir}/jquery" property="test-sys-prop.external.jquery"/>
      <available file="${test.external.dir}/test262" property="test-sys-prop.external.test262"/>
      <available file="${test.external.dir}/showdown" property="test-sys-prop.external.markdown"/>
  </target>

  <target name="check-testng" unless="testng.available">
    <echo message="WARNING: TestNG not available, will not run tests. Please copy testng.jar under test/lib directory."/>
  </target>

  <!-- only to be invoked as dependency of "test" target -->
  <target name="-test-classes-all" depends="jar" unless="test.class">
      <fileset id="test.classes" dir="${build.test.classes.dir}">
          <include name="**/api/javaaccess/*Test.class"/>
          <include name="**/api/scripting/*Test.class"/>
          <include name="**/codegen/*Test.class"/>
          <include name="**/parser/*Test.class"/>
          <include name="**/runtime/*Test.class"/>
          <include name="**/runtime/regexp/*Test.class"/>
          <include name="**/runtime/regexp/joni/*Test.class"/>
          <include name="**/framework/*Test.class"/>
     </fileset>
  </target>

  <!-- only to be invoked as dependency of "test" target -->
  <target name="-test-classes-single" depends="jar" if="test.class">
     <fileset id="test.classes" dir="${build.test.classes.dir}">
         <include name="${test.class}*"/>
     </fileset>
  </target>

  <!-- only to be invoked as dependency of "test" target -->
  <target name="-test-nosecurity" unless="test.class">
    <fileset id="test.nosecurity.classes" dir="${build.test.classes.dir}">
      <include name="**/framework/ScriptTest.class"/>
    </fileset>
    <testng outputdir="${build.nosecurity.test.results.dir}/${testResultsSubDir}" classfilesetref="test.nosecurity.classes"
       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
      <sysproperty key="nashorn.jar" value="${dist.dir}/nashorn.jar"/>
      <propertyset>
        <propertyref prefix="nashorn."/>
      </propertyset>
      <propertyset>
        <propertyref prefix="test-sys-prop-no-security."/>
        <mapper from="test-sys-prop-no-security.*" to="*" type="glob"/>
      </propertyset>
      <sysproperty key="optimistic.override" value="${optimistic}"/>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <!-- only to be invoked as dependency of "test" target -->
  <target name="-test-security">
    <delete dir="${build.dir}/nashorn_code_cache"/>
    <property name="debug.test.jvmargs" value=""/>
    <testng outputdir="${build.test.results.dir}/${testResultsSubDir}" classfilesetref="test.classes"
	    verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
      <jvmarg line="${debug.test.jvmargs}"/>
      <propertyset>
        <propertyref prefix="nashorn."/>
      </propertyset>
      <propertyset>
        <propertyref prefix="test-sys-prop."/>
        <mapper from="test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <sysproperty key="optimistic.override" value="${optimistic}"/>
      <sysproperty key="test.js.excludes.file" value="${exclude.list}"/>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <target name="test" depends="test-pessimistic, test-optimistic"/>

  <target name="test-optimistic" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
    <echo message="Running test suite in OPTIMISTIC mode..."/>
    <antcall target="-test-nosecurity" inheritRefs="true">
      <param name="optimistic" value="true"/>
      <param name="testResultsSubDir" value="optimistic"/>
    </antcall>    
    <antcall target="-test-security" inheritRefs="true">
      <param name="optimistic" value="true"/>
      <param name="testResultsSubDir" value="optimistic"/>
    </antcall>
  </target>

  <target name="test-pessimistic" depends="jar, -test-classes-all,-test-classes-single, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
    <echo message="Running test suite in PESSIMISTIC mode..."/>
    <antcall target="-test-nosecurity" inheritRefs="true">
      <param name="optimistic" value="false"/>
      <param name="testResultsSubDir" value="pessimistic"/>
    </antcall>    
    <antcall target="-test-security" inheritRefs="true">
      <param name="optimistic" value="false"/>
      <param name="testResultsSubDir" value="pessimistic"/>
    </antcall>
  </target>

  <target name="check-jemmy.jfx.testng" unless="jemmy.jfx.testng.available">
    <echo message="WARNING: Jemmy or JavaFX or TestNG not available, will not run tests. Please copy testng.jar, JemmyCore.jar, JemmyFX.jar, JemmyAWTInput.jar under test${file.separator}lib directory. And make sure you have jfxrt.jar in ${java.home}${file.separator}lib${file.separator}ext dir."/>
  </target>

  <target name="testjfx" depends="jar, check-jemmy.jfx.testng, compile-test" if="jemmy.jfx.testng.available">
    <fileset id="test.classes" dir="${build.test.classes.dir}">
       <include name="**/framework/*Test.class"/>
    </fileset>

    <copy file="${file.reference.jfxrt.jar}" todir="dist"/>

    <condition property="jfx.prism.order" value="-Dprism.order=j2d" else=" ">
        <not>
            <os family="mac"/>
        </not>
    </condition>

    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} -Dbuild.dir=${build.dir}"/>
      <propertyset>
        <propertyref prefix="testjfx-test-sys-prop."/>
        <mapper from="testjfx-test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <sysproperty key="test.fork.jvm.options" value="${testjfx-test-sys-prop.test.fork.jvm.options} ${jfx.prism.order}"/>
      <classpath>
          <pathelement path="${testjfx.run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <target name="testmarkdown" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
    <fileset id="test.classes" dir="${build.test.classes.dir}">
       <include name="**/framework/*Test.class"/>
    </fileset>

    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
      <propertyset>
        <propertyref prefix="testmarkdown-test-sys-prop."/>
        <mapper from="testmarkdown-test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <target name="test262" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
    <fileset id="test.classes" dir="${build.test.classes.dir}">
       <include name="**/framework/*Test.class"/>
    </fileset>

    <testng outputdir="${build.test.results.dir}" classfilesetref="test.classes"
       verbose="${testng.verbose}" haltonfailure="true" useDefaultListeners="false" listeners="${testng.listeners}" workingDir="${basedir}">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
      <propertyset>
        <propertyref prefix="nashorn."/>
      </propertyset>
      <propertyset>
        <propertyref prefix="test262-test-sys-prop."/>
        <mapper from="test262-test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

  <target name="test262parallel" depends="test262-parallel"/>

  <target name="test262-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
    <!-- use just build.test.classes.dir to avoid referring to TestNG -->
    <java classname="${parallel.test.runner}" dir="${basedir}" fork="true">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs} -Dbuild.dir=${build.dir}"/>
      <!-- avoid too many typeinfo cache files. Each script is run only once anyway -->
      <jvmarg line="-Dnashorn.typeInfo.disabled=true"/>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
      <syspropertyset>
          <propertyref prefix="test262-test-sys-prop."/>
          <mapper type="glob" from="test262-test-sys-prop.*" to="*"/>
      </syspropertyset>
    </java>
  </target>

  <target name="testparallel" depends="test-parallel"/>

  <target name="test-parallel" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
      <!-- use just build.test.classes.dir to avoid referring to TestNG -->
      <java classname="${parallel.test.runner}" dir="${basedir}"
        failonerror="true"
        fork="true">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx} ${run.test.jvmsecurityargs}"/>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      <pathelement path="${build.test.classes.dir}"/>
      </classpath>
      <syspropertyset>
          <propertyref prefix="test-sys-prop."/>
          <mapper type="glob" from="test-sys-prop.*" to="*"/>
      </syspropertyset>
      </java>
  </target>

  <target name="all" depends="test, docs"
      description="Build, test and generate docs for nashorn"/>

  <target name="run" depends="jar"
      description="Run the shell with a sample script">
    <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
        <jvmarg line="${ext.class.path}"/>
        <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
        <arg value="-dump-on-error"/>
        <arg value="test.js"/>
    </java>
  </target>

  <target name="debug" depends="jar"
      description="Debug the shell with a sample script">
    <java classname="${nashorn.shell.tool}" fork="true" dir="samples">
        <jvmarg line="${ext.class.path}"/>
        <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
        <arg value="--print-code"/>
        <arg value="--verify-code"/>
        <arg value="--print-symbols"/>
        <jvmarg value="-Dnashorn.codegen.debug=true"/>
        <arg value="test.js"/>
    </java>
  </target>

  <!-- targets to get external script tests -->

  <!-- test262 test suite -->
  <target name="get-test262" depends="init" unless="${test-sys-prop.external.test262}">
    <!-- clone test262 git repo -->
    <exec executable="${git.executable}">
       <arg value="clone"/>
       <arg value="--branch"/>
       <arg value="es5-tests"/>
       <arg value="https://github.com/tc39/test262"/>
       <arg value="${test.external.dir}/test262"/>
    </exec>
  </target>
  <target name="update-test262" depends="init" if="${test-sys-prop.external.test262}">
    <!-- update test262 git repo -->
    <exec executable="${git.executable}" dir="${test.external.dir}/test262">
       <arg value="pull"/>
    </exec>
  </target>

  <!-- octane benchmark -->
  <target name="get-octane" depends="init" unless="${test-sys-prop.external.octane}">
    <!-- checkout octane benchmarks -->
    <exec executable="${svn.executable}">
       <arg value="--non-interactive"/>
       <arg value="--trust-server-cert"/>
       <arg value="checkout"/>
       <arg value="http://octane-benchmark.googlecode.com/svn/trunk/"/>
       <arg value="${test.external.dir}/octane"/>
    </exec>
  </target>
  <target name="update-octane" depends="init" if="${test-sys-prop.external.octane}">
    <!-- update octane benchmarks -->
    <exec executable="${svn.executable}" dir="${test.external.dir}/octane">
       <arg value="--non-interactive"/>
       <arg value="--trust-server-cert"/>
       <arg value="update"/>
    </exec>
  </target>

  <!-- sunspider benchmark -->
  <target name="get-sunspider" depends="init" unless="${test-sys-prop.external.sunspider}">
    <!-- checkout sunspider -->
    <exec executable="${svn.executable}">
       <arg value="--non-interactive"/>
       <arg value="--trust-server-cert"/>
       <arg value="checkout"/>
       <arg value="http://svn.webkit.org/repository/webkit/trunk/PerformanceTests/SunSpider"/>
       <arg value="${test.external.dir}/sunspider"/>
    </exec>
  </target>
  <target name="update-sunspider" depends="init" if="${test-sys-prop.external.sunspider}">
    <!-- update sunspider -->
    <exec executable="${svn.executable}" dir="${test.external.dir}/sunspider">
       <arg value="--non-interactive"/>
       <arg value="--trust-server-cert"/>
       <arg value="update"/>
    </exec>
  </target>

  <!-- get all external test scripts -->
  <target name="externals" depends="init, check-external-tests, get-test262, get-octane, get-sunspider">
    <!-- make external test dir -->
    <mkdir dir="${test.external.dir}"/>

    <!-- jquery -->
    <mkdir dir="${test.external.dir}/jquery"/>
    <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>
    <get src="http://code.jquery.com/jquery-1.7.2.min.js" dest="${test.external.dir}/jquery" skipexisting="true" ignoreerrors="true"/>

    <!-- prototype -->
    <mkdir dir="${test.external.dir}/prototype"/>
    <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"/>

    <!-- underscorejs -->
    <mkdir dir="${test.external.dir}/underscore"/>
    <get src="http://underscorejs.org/underscore.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>
    <get src="http://underscorejs.org/underscore-min.js" dest="${test.external.dir}/underscore" skipexisting="true" ignoreerrors="true"/>

    <!-- yui -->
    <mkdir dir="${test.external.dir}/yui"/>
    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>
    <get src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js" dest="${test.external.dir}/yui" skipexisting="true" ignoreerrors="true"/>

    <!-- showdown -->
    <mkdir dir="${test.external.dir}/showdown"/>
    <get src="https://raw.github.com/coreyti/showdown/master/src/showdown.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>
    <get src="https://raw.github.com/coreyti/showdown/master/src/extensions/table.js" dest="${test.external.dir}/showdown" skipexisting="true" ignoreerrors="true"/>

  </target>

  <!-- update external test suites that are pulled from source control systems -->
  <target name="update-externals" depends="init, check-external-tests, update-test262, update-octane, update-sunspider"/>

  <!-- run all perf tests -->
  <target name="perf" depends="externals, update-externals, sunspider, octane"/>

  <!-- run all tests -->
  <target name="exit-if-no-testng" depends="init, check-testng" unless="${testng.available}">
     <fail message="Exiting.."/>
  </target>

  <target name="alltests" depends="exit-if-no-testng, externals, update-externals, test, test262parallel, perf"/>

  <import file="build-benchmark.xml"/>

</project>