Merge
authorlana
Thu, 31 Mar 2016 08:59:59 -0700
changeset 36765 dc5b9649cb4a
parent 36763 67f1a9239b48 (current diff)
parent 36764 298caeee3757 (diff)
child 36766 22ae7151aae7
Merge
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/buildtools/nashorntask/README	Thu Mar 31 08:59:59 2016 -0700
@@ -0,0 +1,1 @@
+This project implements an ant task to run Nashorn scripts from ant projects.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/buildtools/nashorntask/build.xml	Thu Mar 31 08:59:59 2016 -0700
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2016, 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="nashorntask" default="all" basedir=".">
+  <target name="init">
+    <loadproperties srcFile="project.properties"/>
+  </target>
+
+  <target name="prepare" depends="init">
+    <mkdir dir="${build.classes.dir}"/>
+    <mkdir dir="${dist.dir}"/>
+  </target>
+
+  <target name="clean" depends="init">
+    <delete dir="${build.dir}"/>
+    <delete dir="${dist.dir}"/>
+  </target>
+
+  <target name="compile" depends="prepare" description="Compiles the nashorn ant tag sources">
+    <javac srcdir="${src.dir}"
+           destdir="${build.classes.dir}"
+           debug="${javac.debug}"
+           includeantruntime="true">
+      <compilerarg value="-Xlint:unchecked"/>
+      <compilerarg value="-Xlint:deprecation"/>
+    </javac>
+  </target>
+
+  <target name="jar" depends="compile" description="Creates nashorntask.jar">
+    <jar jarfile="${dist.jar}" basedir="${build.classes.dir}"/>
+  </target>
+
+  <target name="dist" depends="jar"/>
+
+  <target name="all" depends="dist" 
+    description="Builds sources and generates nashorntask.jar"/>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/buildtools/nashorntask/project.properties	Thu Mar 31 08:59:59 2016 -0700
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2016, 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.
+#
+application.title=nashorntask
+
+# source and target levels
+build.compiler=modern
+javac.source=1.8
+javac.target=1.8
+
+build.classes.dir=${build.dir}/classes
+
+# This directory is removed when the project is cleaned:
+build.dir=build
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/nashorntask.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+
+javac.debug=true
+src.dir=src
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/buildtools/nashorntask/src/jdk/nashorn/ant/NashornTask.java	Thu Mar 31 08:59:59 2016 -0700
@@ -0,0 +1,76 @@
+/*
+ * 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+package jdk.nashorn.ant;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.BuildException;
+
+/**
+ * This class implements an ant task to evaluate nashorn scripts
+ * from ant projects.
+ */
+public final class NashornTask extends Task {
+    // Underlying nashorn script engine
+    private final ScriptEngine engine;
+    // the current ant project
+    private Project project;
+    // the script evaluated by this task
+    private String script;
+
+    public NashornTask() {
+        final ScriptEngineManager m = new ScriptEngineManager();
+        this.engine = m.getEngineByName("nashorn");
+    }
+
+    @Override
+    public void setProject(Project proj) {
+        this.project = proj;
+    }
+
+    // set the script to be evaluated
+    public void addText(String text) {
+        this.script = text;
+    }
+
+    @Override
+    public void execute() {
+        // expose project as "project" variable
+        engine.put("project", project);
+        // expose this task as "self" variable
+        engine.put("self", this);
+
+        // evaluate specified script
+        try {
+            engine.eval(script);
+        } catch (final ScriptException se) {
+            throw new BuildException(se);
+        }
+    }
+}
--- a/nashorn/make/build-benchmark.xml	Thu Mar 31 01:13:34 2016 -0700
+++ b/nashorn/make/build-benchmark.xml	Thu Mar 31 08:59:59 2016 -0700
@@ -217,14 +217,20 @@
     <run-one cond="octane.benchmark.zlib" runtime="rhino"/>
   </target>
 
+  <target name="-define-nashorn-task">
+    <ant dir="${nashorntask.dir}" inheritAll="false"/>
+    <taskdef name="nashorn" classname="jdk.nashorn.ant.NashornTask" classpath="${nashorntask.dir}/dist/nashorntask.jar"/>
+  </target>
+
   <!--
       Benchmark runners for one or more benchmarks, single
       or multiple process
   -->
 
-  <target name="octane-process-separate" if="${octane-test-sys-prop.separate.process}">
+  <target name="octane-process-separate" if="${octane-test-sys-prop.separate.process}"
+      depends="-define-nashorn-task">
     <echo message="Running each benchmark in separate processes, starting new JVMs for each."/>
-    <script language="javascript"><![CDATA[
+    <nashorn><![CDATA[
       var props = [];
 
       for (var prop in project.getProperties()) {
@@ -257,7 +263,7 @@
         task.setDynamicAttribute("runtime", runtime);
 	task.perform();
       }
-    ]]></script>
+    ]]></nashorn>
   </target>
 
   <target name="octane-process-single" unless="${octane-test-sys-prop.separate.process}">
@@ -278,14 +284,8 @@
   -->
   <target name="octane-nashorn" depends="jar">
     <property name="runtime" value="nashorn"/>
-    <!--
-       Temporarily disabled because ant script tag is broken with
-       jdk9. See also: JDK-8152533.
-
-       <antcall target="octane-process-separate"/>
-       <antcall target="octane-process-single"/>
-    -->
-    <echo message="octane target temporarily disabled"/>
+    <antcall target="octane-process-separate"/>
+    <antcall target="octane-process-single"/>
   </target>
 
   <!-- alias for 'octane' -->
@@ -318,9 +318,7 @@
   <target name="run-octane-nashorn">
     <java classname="${nashorn.shell.tool}"
           classpath="${run.test.classpath}"
-          fork="true"
-          dir=".">
-      <jvmarg line="${boot.class.path}"/>
+          fork="true">
       <jvmarg line="${run.test.jvmargs.octane} -Xms${run.test.xms} -Xmx${run.test.xmx}"/>
       <!-- pass on all properties prefixed with 'nashorn' to the runtime -->
       <syspropertyset>
@@ -391,9 +389,7 @@
   <target name="sunspider-nashorn" depends="sunspider-init">
     <java classname="${nashorn.shell.tool}"
           classpath="${run.test.classpath}"
-          fork="true"
-          dir=".">
-      <jvmarg line="${boot.class.path}"/>
+          fork="true">
       <jvmarg line="${run.test.jvmargs} -Xmx${run.test.xmx}"/>
       <arg value="-timezone=PST"/>
       <arg value="--class-cache-size=50"/>
--- a/nashorn/make/project.properties	Thu Mar 31 01:13:34 2016 -0700
+++ b/nashorn/make/project.properties	Thu Mar 31 08:59:59 2016 -0700
@@ -47,6 +47,9 @@
 build.zip=${build.dir}/nashorn.zip
 build.gzip=${build.dir}/nashorn.tar.gz
 
+# project directory of <nashorn> ant task
+nashorntask.dir=buildtools/nashorntask
+
 # nashorn Shell tool
 nashorn.shell.tool=jdk.nashorn.tools.Shell
 
@@ -54,8 +57,6 @@
 nasgen.tool=jdk.nashorn.internal.tools.nasgen.Main
 
 nasgen.module.imports=\
-
-nasgen.module.imports=\
     java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED,\
     java.base/jdk.internal.org.objectweb.asm.util=ALL-UNNAMED