use of org.mozilla.javascript.commonjs.module.RequireBuilder in project hackpad by dropbox.
the class PipeThread method installRequire.
public Require installRequire(Context cx, List<String> modulePath, boolean sandboxed) {
RequireBuilder rb = new RequireBuilder();
rb.setSandboxed(sandboxed);
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(cx, this);
require.install(this);
return require;
}
Aggregations