commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r988273 - in /commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require: ./ require.xml require2.xml require3.xml require4.xml testLoad.js
Date Mon, 23 Aug 2010 19:44:48 GMT
Author: jbeard
Date: Mon Aug 23 19:44:48 2010
New Revision: 988273

URL: http://svn.apache.org/viewvc?rev=988273&view=rev
Log:
Added some experiments for using Rhino's built-in load() function in Ant script contexts,
as well as importing RequireJS modules.

Added:
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require.xml
  (with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require2.xml
  (with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require3.xml
  (with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require4.xml
  (with props)
    commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/testLoad.js
  (with props)

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require.xml?rev=988273&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require.xml
(added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require.xml
Mon Aug 23 19:44:48 2010
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<!--
+This file shows one attempt to use Rhino script elements with RequireJS
+modules. This example shows my naive attempt to implement a load function.
+
+Note that this example DOES NOT WORK, as any local variables
+declared in the script to be loaded (such as top-level variable "require"
+in RequireJS) is contained within the scope of the load function when eval'd.
+-->
+<project default="hello" name="helloworld" basedir=".">
+
+	<target name="hello">
+		<script language="javascript" manager="bsf">
+			<classpath>
+				<fileset dir="../../../lib/java/" includes="js.jar"/>
+				<fileset dir="../../../lib/build-java/" includes="*.jar"></fileset>
+			</classpath><![CDATA[
+
+			//define load in global scope
+			function readFile(path){
+				stream = new java.io.FileInputStream(new java.io.File(path));
+				fc = stream.getChannel();
+				bb = fc.map(java.nio.channels.FileChannel.MapMode.READ_ONLY, 0, fc.size());
+				return java.nio.charset.Charset.defaultCharset().decode(bb).toString();
+			}
+
+			load = function(path){
+				eval(String(readFile(path)))
+			}
+
+
+			echo = helloworld.createTask("echo");
+
+			var contents = readFile('hello.js')
+			echo.setMessage(contents);
+			echo.perform();
+
+			load('hello.js')
+
+			echo.perform();
+
+		]]></script>	
+	</target>
+</project>
+
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require2.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require2.xml?rev=988273&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require2.xml
(added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require2.xml
Mon Aug 23 19:44:48 2010
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<!--
+This file shows one attempt to use Rhino script elements with RequireJS
+modules. This example shows my attempts to use Continuations to implement
+a load() function. 
+
+Note that this example DOES NOT WORK, as the script is not run in interpreted mode.
+-->
+<project default="hello" name="helloworld" basedir=".">
+
+	<target name="hello">
+		<script language="javascript" manager="bsf">
+			<classpath>
+				<fileset dir="../../../lib/java/" includes="js.jar"/>
+				<fileset dir="../../../lib/build-java/" includes="*.jar"></fileset>
+			</classpath><![CDATA[
+
+			(function(){
+
+				//define load in global scope
+				function readFile(path){
+					stream = new java.io.FileInputStream(new java.io.File(path));
+					fc = stream.getChannel();
+					bb = fc.map(java.nio.channels.FileChannel.MapMode.READ_ONLY, 0, fc.size());
+					return java.nio.charset.Charset.defaultCharset().decode(bb).toString();
+				}
+
+				function call_with_current_continuation() {
+				    var kont = new Continuation();
+				    return kont;
+				}
+
+				var evalString = null, afterEval = null;
+				var beforeEval = call_with_current_continuation();
+				if(evalString){
+					eval(evalString);
+					evalString=null;
+					afterEval(null);
+				}
+				load = function(str){
+					evalString = str;
+					afterEval = call_with_current_continuation();
+					if(afterEval instanceof Continuation){
+						beforeEval(beforeEval);
+					}else{
+						return;
+					}
+				}
+
+				print = function(str){
+					var echo = helloworld.createTask("echo");
+					echo.setMessage(str);
+					echo.perform();
+				}
+
+				var absoluteScriptDir = "../../../";
+
+				var pathToDojoBase = absoluteScriptDir + "lib/test-js/dojo-release-1.4.2-src/dojo/";
+
+				//this is a bit weird, but we define this here in case we need to load dojo later using
the RequireJS loader
+				djConfig = {
+					"baseUrl" : pathToDojoBase 
+				}
+
+				var pathToRequireJsDir = absoluteScriptDir + "lib/js/requirejs/";
+
+				load("../../../lib/js/requirejs/require.js");
+
+				/*
+				load(pathToRequireJsDir + "require/rhino.js");
+				load(pathToRequireJsDir + "require/text.js");
+				load(pathToRequireJsDir + "require/xml.js");
+				*/
+
+				load("../../../lib/test-js/dojo-release-1.4.2-src/dojo/dojo.js")
+
+				print(dojo)
+				//print(require)
+			})();
+
+		]]></script>	
+	</target>
+</project>
+
+
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require3.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require3.xml?rev=988273&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require3.xml
(added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require3.xml
Mon Aug 23 19:44:48 2010
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<!--
+This file shows one attempt to use Rhino script elements with RequireJS
+modules. This attempt does work.
+-->
+<project default="hello" name="helloworld" basedir=".">
+	<target name="hello">
+	<script language="javascript" manager="bsf">
+		<classpath>
+		<fileset dir="../../../lib/java/" includes="js.jar"/>
+		<fileset dir="../../../lib/build-java/" includes="*.jar"></fileset>
+		</classpath><![CDATA[
+			importPackage(java.lang, java.util, java.io);
+			System.out.println("Hello from JavaScript!!");
+			//create shell, execute something and grab global
+			var shell = org.mozilla.javascript.tools.shell.Main;
+			var args = ["-e","var a='STRING';"];
+			shell.exec(args);
+			var shellGlobal = shell.global;
+
+			//grab functions from shell global and place in current global
+			var load=shellGlobal.load;
+			var print=shellGlobal.print;
+			var defineClass=shellGlobal.defineClass;
+			var deserialize=shellGlobal.deserialize;
+			var doctest=shellGlobal.doctest;
+			var gc=shellGlobal.gc;
+			var help=shellGlobal.help;
+			var loadClass=shellGlobal.loadClass;
+			var quit=shellGlobal.quit;
+			var readFile=shellGlobal.readFile;
+			var readUrl=shellGlobal.readUrl;
+			var runCommand=shellGlobal.runCommand;
+			var seal=shellGlobal.seal;
+			var serialize=shellGlobal.serialize;
+			var spawn=shellGlobal.spawn;
+			var sync=shellGlobal.sync;
+			var toint32=shellGlobal.toint32;
+			var version=shellGlobal.version;
+			var environment=shellGlobal.environment;
+
+			//test your bad self
+			//load("test.js");
+
+
+			var absoluteScriptDir = "../../../";
+
+			var pathToDojoBase = absoluteScriptDir + "lib/test-js/dojo-release-1.4.2-src/dojo/";
+
+			//this is a bit weird, but we define this here in case we need to load dojo later using
the RequireJS loader
+			djConfig = {
+				"baseUrl" : pathToDojoBase 
+			}
+
+			var pathToRequireJsDir = absoluteScriptDir + "lib/js/requirejs/";
+
+			load("../../../lib/js/requirejs/require.js");
+
+			load(pathToRequireJsDir + "require/rhino.js");
+			load(pathToRequireJsDir + "require/text.js");
+			load(pathToRequireJsDir + "require/xml.js");
+
+			load("../../../lib/test-js/dojo-release-1.4.2-src/dojo/dojo.js")
+
+			print(dojo)
+			print(require)
+
+		]]></script>
+	</target>
+</project>
+
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require3.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require4.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require4.xml?rev=988273&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require4.xml
(added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require4.xml
Mon Aug 23 19:44:48 2010
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+<!--
+This file shows one attempt to use Rhino script elements with RequireJS
+modules. This is like the example in require4.xml, but uses a macro
+to automate the process of loading the Rhino global objects into the current
+global scope.
+-->
+<project default="hello2" name="helloworld" basedir=".">
+	<macrodef name="rhinoscript">
+		<text name="text"/>
+
+		<sequential>
+			<script language="javascript" manager="bsf">
+				<classpath>
+				<fileset dir="../../../lib/java/" includes="js.jar"/>
+				<fileset dir="../../../lib/build-java/" includes="*.jar"></fileset>
+				</classpath><![CDATA[
+					importPackage(java.lang, java.util, java.io);
+					//System.out.println("Hello from JavaScript!!");
+					//create shell, execute something and grab global
+					var shell = org.mozilla.javascript.tools.shell.Main;
+					var args = ["-e","var a='STRING';"];
+					shell.exec(args);
+					var shellGlobal = shell.global;
+
+					//grab functions from shell global and place in current global
+					var load=shellGlobal.load;
+					var print=shellGlobal.print;
+					var defineClass=shellGlobal.defineClass;
+					var deserialize=shellGlobal.deserialize;
+					var doctest=shellGlobal.doctest;
+					var gc=shellGlobal.gc;
+					var help=shellGlobal.help;
+					var loadClass=shellGlobal.loadClass;
+					var quit=shellGlobal.quit;
+					var readFile=shellGlobal.readFile;
+					var readUrl=shellGlobal.readUrl;
+					var runCommand=shellGlobal.runCommand;
+					var seal=shellGlobal.seal;
+					var serialize=shellGlobal.serialize;
+					var spawn=shellGlobal.spawn;
+					var sync=shellGlobal.sync;
+					var toint32=shellGlobal.toint32;
+					var version=shellGlobal.version;
+					var environment=shellGlobal.environment;
+	
+					@{text}
+			]]></script>
+		</sequential>
+	</macrodef>
+	
+	<target name="hello">
+		<rhinoscript>
+			print("Hello World!")
+		</rhinoscript>
+	</target>
+
+	<target name="hello2">
+		<rhinoscript>
+
+			//test your bad self
+			//load("test.js");
+
+
+			var absoluteScriptDir = "../../../";
+
+			var pathToDojoBase = absoluteScriptDir + "lib/test-js/dojo-release-1.4.2-src/dojo/";
+
+			//this is a bit weird, but we define this here in case we need to load dojo later using
the RequireJS loader
+			djConfig = {
+				"baseUrl" : pathToDojoBase 
+			}
+
+			var pathToRequireJsDir = absoluteScriptDir + "lib/js/requirejs/";
+
+			load("../../../lib/js/requirejs/require.js");
+
+			load(pathToRequireJsDir + "require/rhino.js");
+			load(pathToRequireJsDir + "require/text.js");
+			load(pathToRequireJsDir + "require/xml.js");
+
+			load("../../../lib/test-js/dojo-release-1.4.2-src/dojo/dojo.js")
+
+			print(dojo)
+			print(require)
+
+		</rhinoscript>
+	</target>
+</project>
+
+

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/require4.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/testLoad.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/testLoad.js?rev=988273&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/testLoad.js
(added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/testLoad.js
Mon Aug 23 19:44:48 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+/*
+	this file is to test a technique for creating a load function in Rhino
+*/
+(function(){
+
+	myLoadLocal = function(str){
+		eval(str);
+	}
+
+	function call_with_current_continuation() {
+	    var kont = new Continuation();
+	    return kont;
+	}
+
+	var evalString = null, afterEval = null;
+	var beforeEval = call_with_current_continuation();
+	if(evalString){
+		eval(evalString);
+		evalString=null;
+		afterEval(null);
+	}
+	myLoadContinuation = function(str){
+		evalString = str;
+		afterEval = call_with_current_continuation();
+		if(afterEval instanceof Continuation){
+			beforeEval(beforeEval);
+		}else{
+			return;
+		}
+	}
+
+	myLoadLocal("var foo=1;"); 
+	print(typeof foo);	//should be undefined
+
+	myLoadContinuation("var bar=2;"); 
+	print(typeof bar);	//should be number
+	print(bar);		//should be 2
+
+	//see if it works again
+	myLoadContinuation("var bat=3;"); 
+	print(typeof bat);	//should be number
+	print(bat);		//should be 3
+
+})()

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/test/ant-rhino-integration/require/testLoad.js
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message