aboutsummaryrefslogtreecommitdiff
path: root/make/build.xml
blob: 69dbf4fd2b5154b40d8182d8ce66c09a36da0d2e (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
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2010, 2012, 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="all" basedir="..">
  <import file="build-nasgen.xml"/>
  <import file="build-benchmark.xml"/>

  <target name="init">
    <loadproperties srcFile="make/project.properties"/>
    <path id="nashorn.ext.path">
      <pathelement location="${dist.dir}"/>
    </path>
    <property name="ext.class.path" value="-Djava.ext.dirs=&quot;${toString:nashorn.ext.path}&quot;"/>
  </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}"/>
    <!-- check if JDK already has ASM classes -->
    <available property="asm.available" classname="jdk.internal.org.objectweb.asm.Type"/>
    <!-- check if testng.jar is avaiable -->
    <available property="testng.available" file="${file.reference.testng.jar}"/>
  </target>

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

  <target name="clean-dynalink">
    <delete dir="${dynalink.dir}"/>
  </target>

  <target name="clean-all" depends="clean-dynalink, clean">
    <delete dir="${build.dir}"/>
  </target>

  <!-- do it only if ASM is not available -->
  <target name="compile-asm" depends="prepare" unless="asm.available">
    <javac srcdir="${asm.src.dir}"
           destdir="${build.classes.dir}"
           excludes="**/optimizer/* **/xml/* **/attrs/*"
           source="${javac.source}"
           target="${javac.target}"
           debug="${javac.debug}"
           encoding="${javac.encoding}"
           includeantruntime="false"/>
  </target>

  <target name="check-dynalink-uptodate" depends="init">
    <property name="versioned.dynalink.jar" value="${dynalink.dir}/dynalink-${dynalink.jar.version}.jar"/>
    <condition property="dynalink.uptodate">
      <and>
        <available file="${versioned.dynalink.jar}"/>
        <filesmatch file1="${versioned.dynalink.jar}" file2="${dynalink.jar}"/>
      </and>
    </condition>
  </target>

  <target name="get-dynalink" depends="check-dynalink-uptodate" unless="dynalink.uptodate">
    <mkdir dir="${dynalink.dir}"/>
    <!-- Delete previous snapshots, if any -->
    <delete>
      <fileset dir="${dynalink.dir}" includes="*"/>
    </delete>
    <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}"/>
    <get src="${dynalink.download.base.url}.jar" dest="${versioned.dynalink.jar}" usetimestamp="true"/>
    <get src="${dynalink.download.base.url}-sources.jar" dest="${dynalink.dir}/dynalink-sources.jar" usetimestamp="true"/>
    <copy file="${versioned.dynalink.jar}" tofile="${dynalink.jar}" overwrite="true"/>
  </target>

  <target name="compile" depends="compile-asm, get-dynalink" 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">
      <compilerarg value="-Xlint:unchecked"/>
      <compilerarg value="-Xlint:deprecation"/>
      <compilerarg value="-XDignore.symbol.file"/>
    </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>
    <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" description="Creates nashorn.jar">
    <jar jarfile="${dist.jar}" manifest="${meta.inf.dir}/MANIFEST.MF" index="true" filesetmanifest="merge">
      <fileset dir="${build.classes.dir}"/>
      <zipfileset src="${dynalink.jar}"/>
      <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="javadoc" depends="compile-asm">
    <javadoc destdir="${dist.javadoc.dir}" use="yes" overview="src/overview.html" windowtitle="${nashorn.product.name} ${nashorn.version}">
      <classpath>
        <pathelement location="${build.classes.dir}"/>
        <pathelement location="${dynalink.jar}"/>
      </classpath>
      <fileset dir="${src.dir}" includes="**/*.java"/>
      <link href="http://docs.oracle.com/javase/7/docs/api"/>
      <link href="http://szegedi.github.com/dynalink/0.4/javadoc"/>
    </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"/>
  </target>

  <target name="generate-policy-file">
    <!-- Generating nashorn.policy file -->
    <echo message="grant codeBase &quot;file:/${basedir}/dist/nashorn.jar&quot; {" file="${build.dir}/nashorn.policy"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>

    <echo message="grant codeBase &quot;file:/${basedir}/build/test/classes&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>

    <echo message="grant codeBase &quot;file:/${basedir}/${file.reference.testng.jar}&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>

    <echo message="grant codeBase &quot;file:/${basedir}/test/script/basic/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>

    <echo message="grant codeBase &quot;file:/${basedir}/test/perf/*&quot; {" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="    permission java.security.AllPermission;" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="};" file="${build.dir}/nashorn.policy" append="true"/>
    <echo message="" file="${build.dir}/nashorn.policy" append="true"/>

    <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"/>
  </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>

  <target name="test" depends="jar, check-testng, check-external-tests, compile-test, generate-policy-file" if="testng.available">
    <java classname="${nashorn.shell.tool}" fork="true" dir="${test.script.dir}/representations" output="${build.dir}/output1.log" error="${build.dir}/err.log">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="-Dnashorn.fields.dual=true"/>
      <arg value="NASHORN-592a.js"/>
    </java>
    <java classname="${nashorn.shell.tool}" fork="true" dir="${test.script.dir}/representations" output="${build.dir}/output2.log" error="${build.dir}/err.log">
      <jvmarg line="${ext.class.path}"/>
      <arg value="NASHORN-592a.js"/>
    </java>
    <condition property="representation-ok">
      <filesmatch file1="${build.dir}/output1.log" file2="${build.dir}/output2.log"/>
    </condition>
    <fail unless="representation-ok">Representation test failed - output differs!</fail>
    <fileset id="test.classes" dir="${build.test.classes.dir}">
      <include name="**/access/*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="**/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} ${run.test.jvmsecurityargs}"/>
      <propertyset>
        <propertyref prefix="test-sys-prop."/>
        <mapper from="test-sys-prop.*" to="*" type="glob"/>
      </propertyset>
      <classpath>
          <pathelement path="${run.test.classpath}"/>
      </classpath>
    </testng>
  </target>

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

  <target name="test262" depends="jar, check-testng, check-external-tests, compile-test" 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}"/>
      <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" if="testng.available">
    <!-- use just build.test.classes.dir to avoid referring to TestNG -->
    <java classname="${parallel.test.runner}" dir="${basedir}" classpath="${build.test.classes.dir}" fork="true">
      <jvmarg line="${ext.class.path}"/>
      <jvmarg line="${run.test.jvmargs}"/>
      <syspropertyset>
          <propertyref prefix="test262-test-sys-prop."/>
          <mapper type="glob" from="test262-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}"/>
        <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}"/>
        <arg value="--print-code"/>
        <arg value="--verify-code"/>
        <arg value="--print-symbols"/>
        <jvmarg value="-Dnashorn.codegen.debug=true"/>
        <arg value="test.js"/>
    </java>
  </target>
</project>