You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jb...@apache.org on 2010/06/19 21:43:17 UTC
svn commit: r956276 - in
/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie: build.js
src/javascript/scxml/cgf/SCXMLCompiler.js src/javascript/scxml/cgf/main.js
test/testBrowserTransform.html
Author: jbeard
Date: Sat Jun 19 19:43:17 2010
New Revision: 956276
URL: http://svn.apache.org/viewvc?rev=956276&view=rev
Log:
Hooking up other backends. Changed the compiler API to be asynchronous
Modified:
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html
Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js?rev=956276&r1=956275&r2=956276&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/build.js Sat Jun 19 19:43:17 2010
@@ -198,64 +198,73 @@ require.def("build",
var sc,fpath,label,name;
- sc = SCXMLCompiler.compile({
- inFiles:[pathToTest].map(xmlUtil.parseFromPath),
- backend:backend,
- beautify:true,
- verbose:false,
- log:compileLog,
- ie:false
- })
-
- //write him to builddir
- label = backend + scxmlTest + "StateChart";
- name = label + ".js";
- fpath = buildDir + "/" + name;
-
- //add to scriptsGenerated for later
- scriptsGenerated.push({
- label : label,
- name : name,
- code : sc,
- path : fpath,
- backend : backend,
- scxmlTest : scxmlTest,
- ie : false
- });
-
- print("Writing statechart " + scxmlTest + " to " + fpath);
-
- utilFile.writeFile(sc,fpath);
-
- //compile with nomap and noforeach
- sc = SCXMLCompiler.compile({
- inFiles:[pathToTest].map(xmlUtil.parseFromPath),
- backend:backend,
- beautify:true,
- verbose:false,
- log:compileLog,
- ie:true
- })
-
- //write him to builddir
- label = backend + scxmlTest + "StateChartIE";
- name = label + ".js";
- fpath = buildDir + "/" + name;
-
- //add to scriptsGenerated for later
- scriptsGenerated.push({
- label : label,
- name : name,
- code : sc,
- path : fpath,
- backend : backend,
- scxmlTest : scxmlTest,
- ie : true
- });
-
- print("Writing statechart " + scxmlTest + " to " + fpath);
+ SCXMLCompiler.compile({
+ inFiles:[pathToTest].map(xmlUtil.parseFromPath),
+ backend:backend,
+ beautify:true,
+ verbose:false,
+ log:compileLog,
+ ie:false
+ },
+ function(scArr){
+ sc = scArr[0];
+
+ //write him to builddir
+ label = backend + scxmlTest + "StateChart";
+ name = label + ".js";
+ fpath = buildDir + "/" + name;
+
+ //add to scriptsGenerated for later
+ scriptsGenerated.push({
+ label : label,
+ name : name,
+ code : sc,
+ path : fpath,
+ backend : backend,
+ scxmlTest : scxmlTest,
+ ie : false
+ });
+
+ print("Writing statechart " + scxmlTest + " to " + fpath);
+
+ utilFile.writeFile(sc,fpath);
+
+ //compile with nomap and noforeach
+ SCXMLCompiler.compile({
+ inFiles:[pathToTest].map(xmlUtil.parseFromPath),
+ backend:backend,
+ beautify:true,
+ verbose:false,
+ log:compileLog,
+ ie:true
+ },
+ function(scArr){
+ sc = scArr[0];
+
+ //write him to builddir
+ label = backend + scxmlTest + "StateChartIE";
+ name = label + ".js";
+ fpath = buildDir + "/" + name;
+
+ //add to scriptsGenerated for later
+ scriptsGenerated.push({
+ label : label,
+ name : name,
+ code : sc,
+ path : fpath,
+ backend : backend,
+ scxmlTest : scxmlTest,
+ ie : true
+ });
+
+ print("Writing statechart " + scxmlTest + " to " + fpath);
+
+ utilFile.writeFile(sc,fpath);
+ }
+ )
+ }
+ )
- utilFile.writeFile(sc,fpath);
}
}
},
Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js?rev=956276&r1=956275&r2=956276&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/SCXMLCompiler.js Sat Jun 19 19:43:17 2010
@@ -29,14 +29,12 @@ require.def("src/javascript/scxml/cgf/SC
//TODO: conditional require
[
- "src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator",
"src/javascript/scxml/cgf/Transformer",
"src/javascript/scxml/cgf/util/base",
//small hack. RequireJS seems to resolve the path differently between Rhino and browser
require.isBrowser ? "/lib/js/beautify.js" : "lib/js/beautify.js"],
function(
- StatePatternStatechartGenerator,
Transformer,
base
){
@@ -52,31 +50,38 @@ require.def("src/javascript/scxml/cgf/SC
log
verbose
*/
- function compile(options){
+ function compile(options,callback){
if(!options.inFiles) return false;
- var toReturn = options.inFiles.map(function(xmlFile){
+ if(options.ie){
+ options.noMap = options.noForEach = options.noIndexOf = true;
+ }
+
+ var backendModuleToImport =
+ ({
+ state:"src/javascript/scxml/cgf/backends/js/StatePatternStatechartGenerator",
+ table:"src/javascript/scxml/cgf/backends/js/StateTableStatechartGenerator",
+ "switch":"src/javascript/scxml/cgf/backends/js/SwitchyardStatechartGenerator"
+ })[options.backend];
+
+ require([backendModuleToImport],function(backend){
- if(options.ie){
- options.noMap = options.noForEach = options.noIndexOf = true;
- }
+ var toReturn = options.inFiles.map(function(xmlFile){
- var ir = Transformer(xmlFile,StatePatternStatechartGenerator.transformations,null,"xml");
- var transformedJs = Transformer(ir,StatePatternStatechartGenerator.code,options,"text");
+ var ir = Transformer(xmlFile,backend.transformations,null,"xml");
+ var transformedJs = Transformer(ir,backend.code,options,"text");
- //optionally beautify it
- if(options.beautify){
- transformedJs = js_beautify(transformedJs);
- }
+ //optionally beautify it
+ if(options.beautify){
+ transformedJs = js_beautify(transformedJs);
+ }
- return transformedJs;
+ return transformedJs;
+ });
+
+ callback(toReturn);
});
-
- if(toReturn.length == 1){
- return toReturn[0];
- }else{
- return toReturn;
- }
+
};
return {
Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js?rev=956276&r1=956275&r2=956276&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/src/javascript/scxml/cgf/main.js Sat Jun 19 19:43:17 2010
@@ -39,15 +39,6 @@ require.def("src/javascript/scxml/cgf/ma
"src/javascript/scxml/cgf/util/xml"],
function(SCXMLCompiler,cmdLineUtil,xmlUtil){
- function parseXMLFromPath(path){
- var file = new java.io.File(path);
- var dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- var db = dbf.newDocumentBuilder();
- var doc = db.parse(file);
- return doc;
- }
-
return function(args){
var optionsMap = {
@@ -61,19 +52,15 @@ require.def("src/javascript/scxml/cgf/ma
log : true,
verbose : true
}
-
+debugger;
var parsedOptionsMap = cmdLineUtil.parseCommandLine(optionsMap,args);
- parsedOptionsMap.inFiles = parsedOptionsMap.args.map(xmlUtil.parseFromString);
+ parsedOptionsMap.inFiles = parsedOptionsMap.args.map(xmlUtil.parseFromPath);
delete parsedOptionsMap.args;
//TODO: parse paths in inFiles into documents
- var scArr = SCXMLCompiler.compile(parsedOptionsMap);
-
- if(parsedOptionsMap.inFiles.length > 1){
+ var scArr = SCXMLCompiler.compile(parsedOptionsMap,function(scArr){
scArr.forEach(function(sc){print(sc)});
- }else{
- print(scArr);
- }
+ });
}
});
Modified: commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html?rev=956276&r1=956275&r2=956276&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html (original)
+++ commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/test/testBrowserTransform.html Sat Jun 19 19:43:17 2010
@@ -32,22 +32,24 @@
doXHR("http://localhost:8081/test/kitchen_sink/KitchenSink_executableContent.xml",
function(KitchenSink_executableContent){
- var transformedJs = compiler.compile({
+ compiler.compile({
inFiles:[KitchenSink_executableContent],
backend:backend,
beautify:true,
verbose:false,
log:compileLog,
ie:false
- });
+ }, function(scArr){
+ var transformedJs = scArr[0];
- console.log(transformedJs);
+ console.log(transformedJs);
- //eval
- eval(transformedJs);
- window.StatechartExecutionContext = StatechartExecutionContext;
- dojo.require("doh.runner");
- doh.run();
+ //eval
+ eval(transformedJs);
+ window.StatechartExecutionContext = StatechartExecutionContext;
+ dojo.require("doh.runner");
+ doh.run();
+ });
});
}
);