}
}
// Copied out from the main method of rhino
private static void loadRequireJsScripts(Context context, Scriptable globalScope, String requireJsPath) {
RequireBuilder rb = new RequireBuilder();
List<String> modulePath = Lists.newArrayList(requireJsPath);
List<URI> uris = new ArrayList<URI>();
if (modulePath != null) {
for (String path : modulePath) {
try {
URI uri = new URI(path);
if (!uri.isAbsolute()) {
// call resolve("") to canonify the path
uri = new File(path).toURI().resolve("");
}
if (!uri.toString().endsWith("/")) {
// make sure URI always terminates with slash to
// avoid loading from unintended locations
uri = new URI(uri + "/");
}
uris.add(uri);
} catch (URISyntaxException usx) {
throw new RuntimeException(usx);
}
}
}
rb.setModuleScriptProvider(
new SoftCachingModuleScriptProvider(
new UrlModuleSourceProvider(uris, null)));
Require require = rb.createRequire(context, globalScope);
require.install(globalScope);
}