Package org.mozilla.javascript.commonjs.module

Examples of org.mozilla.javascript.commonjs.module.RequireBuilder


        try {
            Context.enter();
            Context ctx = Context.getCurrentContext();
            ctx.setOptimizationLevel(-1);
            globalScope = ctx.initStandardObjects();
            RequireBuilder require = new RequireBuilder();
            require.setSandboxed(false);
            require.setModuleScriptProvider(new SoftCachingModuleScriptProvider(new ClasspathModuleSourceProvider()));
            require.createRequire(ctx, globalScope).install(globalScope);
            nodeScript = compile(ctx, "node.js");
            tscScript = compile(ctx, "tsc.js");
        } finally {
            Context.exit();
View Full Code Here


             * all the functions (importClass, importPackage) are available.
             * Also provide the security features similar to the bundled script engine.
             */
            topLevel = new TopLevelScope(AccessController.getContext(), cx, System.getSecurityManager() != null);
           
            requireBuilder = new RequireBuilder();           
            setModuleSourceProvider(moduleSourceProvider);
            requireBuilder.setSandboxed(false);

            new LazilyLoadedCtor(topLevel, "JSAdapter",
                "org.rhq.scripting.javascript.engine.JSAdapter",
View Full Code Here

        initialized = true;
    }

    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;
    }
View Full Code Here

        initialized = true;
    }

    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;
    }
View Full Code Here

        }
    }

    // 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);
    }
View Full Code Here

     * @return
     */
    @SuppressWarnings("unused")
    private Require createRequire() {
        Require require = null;
        RequireBuilder builder = getRequireBuilder();
        Context cx = CommonJSEngine.enterContext();
        try {
            require = builder.createRequire(cx, global);
        } finally {
            Context.exit();
        }
        return require;
    }
View Full Code Here

     */
    private RequireBuilder getRequireBuilder() {
        if (requireBuilder == null) {
            synchronized (this) {
                if (requireBuilder == null) {
                    requireBuilder = new RequireBuilder();
                    requireBuilder.setSandboxed(false);
                    List<URI> uris = new ArrayList<URI>();
                    if (modulePaths != null) {
                        for (String path : modulePaths) {
                            try {
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.commonjs.module.RequireBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.