Search in sources :

Example 1 with ScriptingContainer

use of org.jruby.embed.ScriptingContainer in project zeppelin by apache.

the class HbaseInterpreter method open.

@Override
public void open() {
    this.scriptingContainer = new ScriptingContainer(LocalContextScope.SINGLETON);
    this.writer = new StringWriter();
    scriptingContainer.setOutput(this.writer);
    if (!Boolean.parseBoolean(getProperty(HBASE_TEST_MODE))) {
        String hbase_home = getProperty(HBASE_HOME);
        String ruby_src = getProperty(HBASE_RUBY_SRC);
        Path abs_ruby_src = Paths.get(hbase_home, ruby_src).toAbsolutePath();
        logger.info("Home:" + hbase_home);
        logger.info("Ruby Src:" + ruby_src);
        File f = abs_ruby_src.toFile();
        if (!f.exists() || !f.isDirectory()) {
            throw new InterpreterException("HBase ruby sources is not available at '" + abs_ruby_src + "'");
        }
        logger.info("Absolute Ruby Source:" + abs_ruby_src.toString());
        // hirb.rb:41 requires the following system property to be set.
        Properties sysProps = System.getProperties();
        sysProps.setProperty(HBASE_RUBY_SRC, abs_ruby_src.toString());
        Path abs_hirb_path = Paths.get(hbase_home, "bin/hirb.rb");
        try {
            FileInputStream fis = new FileInputStream(abs_hirb_path.toFile());
            this.scriptingContainer.runScriptlet(fis, "hirb.rb");
            fis.close();
        } catch (IOException e) {
            throw new InterpreterException(e.getCause());
        }
    }
}
Also used : Path(java.nio.file.Path) ScriptingContainer(org.jruby.embed.ScriptingContainer) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with ScriptingContainer

use of org.jruby.embed.ScriptingContainer in project sass-java by darrinholst.

the class Compiler method compile.

public void compile() {
    initialize();
    new ScriptingContainer().runScriptlet(buildCompileScript());
}
Also used : ScriptingContainer(org.jruby.embed.ScriptingContainer)

Example 3 with ScriptingContainer

use of org.jruby.embed.ScriptingContainer in project sass-java by darrinholst.

the class Compiler method initialize.

private void initialize() {
    if (!initialized) {
        new ScriptingContainer().runScriptlet(buildInitializationScript());
        initialized = true;
    }
}
Also used : ScriptingContainer(org.jruby.embed.ScriptingContainer)

Example 4 with ScriptingContainer

use of org.jruby.embed.ScriptingContainer in project spring-security-oauth by spring-projects.

the class RubyJwtIntegrationTests method canDecodeRubyHmacSignedToken.

@Test
public void canDecodeRubyHmacSignedToken() throws Exception {
    ScriptingContainer container = new ScriptingContainer();
    container.put("@token", "xxx");
    String script = "require \"jwt\"\n" + "@token = JWT.encode({\"some\" => \"payload\"}, \"secret\", \"HS256\")\n" + "puts @token";
    container.runScriptlet(script);
    String token = (String) container.get("@token");
    Jwt jwt = JwtHelper.decodeAndVerify(token, hmac);
    assertEquals(TEST_CLAIMS, jwt.getClaims());
    container.terminate();
}
Also used : ScriptingContainer(org.jruby.embed.ScriptingContainer) Test(org.junit.Test)

Example 5 with ScriptingContainer

use of org.jruby.embed.ScriptingContainer in project spring-security-oauth by spring-projects.

the class RubyJwtIntegrationTests method rubyCanDecodeHmacSignedToken.

@Test
public void rubyCanDecodeHmacSignedToken() throws Exception {
    Jwt jwt = JwtHelper.encode(TEST_CLAIMS, hmac);
    ScriptingContainer container = new ScriptingContainer();
    container.put("@token", jwt.getEncoded());
    container.put("@claims", "");
    String script = "require \"jwt\"\n" + "@claims = JWT.decode(@token, \"secret\", \"HS256\")[0].to_json\n" + "puts @claims";
    container.runScriptlet(script);
    assertEquals(TEST_CLAIMS, container.get("@claims"));
}
Also used : ScriptingContainer(org.jruby.embed.ScriptingContainer) Test(org.junit.Test)

Aggregations

ScriptingContainer (org.jruby.embed.ScriptingContainer)5 Test (org.junit.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Path (java.nio.file.Path)1 Properties (java.util.Properties)1