Opened 8 years ago
Closed 8 years ago
#17806 closed enhancement (patchwelcome)
[patch][cla] Compatibility with JDK Nashorn javascript engine
Reported by: | Andrew Muraco | Owned by: | Colin Snover |
---|---|---|---|
Priority: | high | Milestone: | 1.10 |
Component: | BuildSystem | Version: | 1.8.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
Currently the build system is using Rhino, but due to performance enhancements in the JS execution engine included in Java 1.8+ we should support Nashorn, Rhino's replacement.
Here's what I had to add/change to make the dojo build system work with Nashorn
dojo/_base/configureRhino.js: missing "readFile" global function, line 20
+ if (typeof readFile !== "function") { + readFile = function(path,encoding){ + var f = new java.io.File(path); + return com.google.common.io.Files.toString(f,java.nio.charset.Charset.forName(encoding)); + }; + }
util/build/main.js: line 65
- has.add("is-windows", /indows/.test(environment["os.name"])); + has.add("is-windows", /indows/.test(java.lang.System.getProperty("os.name")));
util/build/rhino/fs.js: line 27
- os.write(contents); + os.write(contents,0,contents.length);
util/build/rhino/fs.js: line 49
- return (new java.io.File(path)).listFiles().map(function(item){ return (item.name+""); }); + return Array.prototype.map.call((new java.io.File(path)).listFiles(),function(item){ return (item.name+""); });
util/build/rhino/process.js: line 4
- return environment["user.dir"]; + return java.lang.System.getProperty("user.dir");
util/build/rhino/process.js: lines 17-34 (missing runCommand)
- for(var args = [], i = 0; i<arguments.length-3; i++){ - args.push(arguments[i]); + for(var args = new java.lang.String[arguments.length-3] , i = 0; i<arguments.length-3; i++){ + args[i] = (arguments[i]); } var errorMessage = arguments[i++], bc = arguments[i++], callback = arguments[i], - options = {output:""}; - args.push(options); + output; try{ - runCommand.apply(this, args); - callback && callback(0, options.output); + var ps = new java.lang.ProcessBuilder(args); + ps.redirectErrorStream(true); + var pr = ps.start(); + pr.waitFor(); + output = com.google.common.io.CharStreams.toString(new java.io.InputStreamReader(pr.getInputStream())) + callback && callback(0, output); }catch(e){ - bc.log("execFailed", ["message", errorMessage, "output", options.output+"", "error", e]); - callback && callback(-1, errorMessage + "\n" + options.output + "\n" + e); + bc.log("execFailed", ["message", errorMessage, "output", output+"", "error", e]); + callback && callback(-1, errorMessage + "\n" + output + "\n" + e);
util/build/transforms/writeOptimized.js: line 84
- JSSourceFilefromCode=java.lang.Class.forName('com.google.javascript.jscomp.JSSourceFile').getMethod('fromCode',[java.lang.String,java.lang.String]); - closurefromCode = function(filename,content){ - return JSSourceFilefromCode.invoke(null,[filename,content]); - }; + closurefromCode = com.google.javascript.jscomp.JSSourceFile.fromCode;
Some of the changes might require revision to work with both rhino and nashorn, but many changes should work with both.
Change History (6)
comment:1 Changed 8 years ago by
Milestone: | tbd → 1.10 |
---|---|
Priority: | undecided → high |
comment:2 Changed 8 years ago by
The changes to writeOptimized are probably the most troublesome, plus I think closureCompiler changed the class from JSSourceFile to just SourceFile? sometime in 2013, so there's quite a few permutations that should probably be handled.
The other changes all should work with Rhino, although I wrote a few of them using Guava utils, so that isn't ideal.
1.10 would be fantastic, but obviously it's not a blocker.
comment:3 Changed 8 years ago by
Owner: | set to Rawld Gill |
---|---|
Status: | new → assigned |
comment:4 Changed 8 years ago by
Summary: | Compatibility with JDK Nashorn javascript engine → [patch][cla] Compatibility with JDK Nashorn javascript engine |
---|
comment:5 Changed 8 years ago by
Owner: | changed from Rawld Gill to Colin Snover |
---|
comment:6 Changed 8 years ago by
Resolution: | → patchwelcome |
---|---|
Status: | assigned → closed |
Type: | defect → enhancement |
This is not a defect but an enhancement. The path forward for fast builds at the moment is Node.js, not Java. It’s not likely that Java will be a supported build environment for Dojo 2. However, an updated PR on GitHub? that continues to be compatible with Rhino will be considered if such a thing is possible.
Not sure we can address this for 1.10, but marking it so at least look at it for that release.