本文整理汇总了Java中org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider类的典型用法代码示例。如果您正苦于以下问题:Java UrlModuleSourceProvider类的具体用法?Java UrlModuleSourceProvider怎么用?Java UrlModuleSourceProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UrlModuleSourceProvider类属于org.mozilla.javascript.commonjs.module.provider包,在下文中一共展示了UrlModuleSourceProvider类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadModulesFromIncludeDirs
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider; //导入依赖的package包/类
private static void loadModulesFromIncludeDirs(Context cx, Scriptable scope, List<File> requireDirList)
{
List<URI> uris = new ArrayList<URI>();
for (File dir : requireDirList) {
URI uri = dir.toURI();
uris.add(uri);
continue;
}
if (uris.isEmpty()) {
return;
}
RequireBuilder rb = new RequireBuilder();
rb.setModuleScriptProvider(new SoftCachingModuleScriptProvider(
new UrlModuleSourceProvider(uris, null)));
Require require = rb.createRequire(cx, scope);
require.install(scope);
return;
}
示例2: init
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider; //导入依赖的package包/类
public void init() throws URISyntaxException {
ctx = Context.enter();
try {
RequireBuilder builder = new RequireBuilder();
builder.setModuleScriptProvider(new SoftCachingModuleScriptProvider(
new UrlModuleSourceProvider(buildModulePaths(), null)));
topLevelScope = ctx.initStandardObjects();
builder.setSandboxed(false); // allows this to load scripts
Require require = builder.createRequire(ctx, topLevelScope);
exports = require.requireMain(ctx, jsxTransformerJS);
transform = (Function) exports.get("transform", topLevelScope);
} finally {
Context.exit();
}
}
示例3: installRequire
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider; //导入依赖的package包/类
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;
}
示例4: getSandboxedRequire
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider; //导入依赖的package包/类
private Require getSandboxedRequire(Context cx, Scriptable scope, boolean sandboxed)
throws URISyntaxException
{
return new Require(cx, cx.initStandardObjects(),
new StrongCachingModuleScriptProvider(
new UrlModuleSourceProvider(Collections.singleton(
getDirectory()), null)), null, null, true);
}
示例5: createRequire
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider; //导入依赖的package包/类
private static Require createRequire(File dir, Context cx, Scriptable scope)
throws URISyntaxException
{
return new Require(cx, scope, new StrongCachingModuleScriptProvider(
new UrlModuleSourceProvider(Collections.singleton(new URI(
"file:" + dir.getAbsolutePath().replace(File.separatorChar,'/') + "/")),
Collections.singleton(new URI(ComplianceTest.class.getResource(".").toExternalForm() + "/")))),
null, null, false);
}
示例6: getSandboxedRequire
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider; //导入依赖的package包/类
private Require getSandboxedRequire(Context cx, Scriptable scope, boolean sandboxed)
throws URISyntaxException
{
return new Require(cx, cx.initStandardObjects(),
new StrongCachingModuleScriptProvider(
new UrlModuleSourceProvider(Collections.singleton(
getDirectory()), null)), null, null, true);
}
示例7: createRequire
import org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider; //导入依赖的package包/类
private static Require createRequire(File dir, Context cx, Scriptable scope)
throws URISyntaxException
{
return new Require(cx, scope, new StrongCachingModuleScriptProvider(
new UrlModuleSourceProvider(
Collections.singleton(dir.getAbsoluteFile().toURI()),
Collections.singleton(new URI(ComplianceTest.class.getResource(".").toExternalForm() + "/")))),
null, null, false);
}