本文整理汇总了Java中org.jruby.embed.ScriptingContainer类的典型用法代码示例。如果您正苦于以下问题:Java ScriptingContainer类的具体用法?Java ScriptingContainer怎么用?Java ScriptingContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScriptingContainer类属于org.jruby.embed包,在下文中一共展示了ScriptingContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ScriptManager
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
private ScriptManager(String path) {
this.basePath = path;
this.packages = new LinkedList<Package>();
this.ruby = new ScriptingContainer();
this.commands = new HashMap<String, TextCommand>();
this.items = new HashMap<String, ItemBehavior>();
this.mobiles = new HashMap<String, MobileBehavior>();
this.spells = new HashMap<Spell, SpellHandler>();
log.config("Using Ruby " + ruby.getCompatVersion());
Ruby.setThreadLocalRuntime(ruby.getProvider().getRuntime());
ruby.setCompileMode(CompileMode.FORCE);
ruby.runScriptlet("require 'yaml'");
ruby.runScriptlet("java_import " + ScriptAPI.class.getName());
ruby.runScriptlet("java_import " + ItemBehavior.class.getName());
ruby.runScriptlet("java_import " + MobileBehavior.class.getName());
ruby.runScriptlet("java_import " + TextCommand.class.getName());
ruby.runScriptlet("java_import " + SpellHandler.class.getName());
// Enumerations
ruby.runScriptlet("java_import " + Spell.class.getName());
ruby.runScriptlet("java_import " + Attribute.class.getName());
}
示例2: process
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
/**
* Transforms a sass content into css
* @param sassOptions sass framework options
* @param sassCss the Sass content to process.
*/
public String process(final SassOptions sassOptions,
final String sassCss) throws ScriptException {
if (Strings.isNullOrEmpty(sassCss)) return Strings.EMPTY;
SassOptions theSassOptions = sassOptions == null ? SassOptions.DEFAULT_OPTIONS
: sassOptions;
String scriptTemplate = _buildCompileScript(theSassOptions);
String theSassToBeCompiled = sassCss.replace("'","\"");
String theScript = Strings.create(theSassToBeCompiled.length() + scriptTemplate.length())
.add(scriptTemplate)
.replace("${SOURCE_SASS}",theSassToBeCompiled)
.asString();
log.info(theScript);
System.out.println(theScript);
ScriptingContainer rubyEngine = _getOrCreateRubyEngine();
String compiledCSS = rubyEngine.runScriptlet(theScript)
.toString();
return compiledCSS;
}
示例3: buildTimestampParserMap
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
private HashMap<String, TimestampParser> buildTimestampParserMap(ScriptingContainer jruby, List<ColumnConfig> columns, String joinedColumnPrefix, String timeZone)
{
final HashMap<String, TimestampParser> timestampParserMap = Maps.newHashMap();
for (ColumnConfig columnConfig: columns) {
if (Types.TIMESTAMP.equals(columnConfig.getType())) {
String format = columnConfig.getOption().get(String.class, "format");
DateTimeZone timezone = DateTimeZone.forID(timeZone);
TimestampParser parser = new TimestampParser(jruby, format, timezone);
String columnName = joinedColumnPrefix + columnConfig.getName();
timestampParserMap.put(columnName, parser);
}
}
return timestampParserMap;
}
示例4: JRubyJwtInstalled
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
public JRubyJwtInstalled() {
if (!setupOkSet) {
setupOk = false;
setupOkSet = true;
try {
String script =
"require \"rubygems\"\n" +
"require \"jwt\"\n" +
"require \"bouncy-castle-java\"\n" +
"require \"openssl\"";
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet(script);
setupOk = true;
}
catch (Exception e) {
System.out.println("jruby.home not set or JWT gem not available. JWT ruby integration tests will be skipped" + e.getMessage());
}
}
}
示例5: initializeJRubyRuntime
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
private void initializeJRubyRuntime() {
container = new ScriptingContainer(org.jruby.embed.LocalContextScope.SINGLETHREAD);
if (jobConf != null) {
container.getLoadPaths().add(jobConf.get(CONF_JRB_LOAD_PATH));
}
if (rbScriptParam.startsWith(MODE_METHOD_MARK)) {
mode = MODE.METHOD;
evaluateMethod = rbScriptParam.substring(1);
container.setAttribute(AttributeName.SHARING_VARIABLES, false);
receiver = container.runScriptlet(rbEnvScript);
} else {
mode = MODE.EVAL;
evalUnit = container.parse(rbScriptParam);
}
LOG.info("initialized JRuby runtime (" +
container.getCompatVersion() + ", " +
container.getCompileMode()
+ ")");
}
示例6: condition
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
/**
* Checks rule event condition by evaluating the defined knowledge base rule method.
*
* @param rule rule.
* @param event event.
* @return {@code true} if this condition is met.
*/
@Override
public boolean condition(Rule rule, Event event) {
ScriptingContainer scriptContainer =
((JRubyKnowledgeBaseInterpreter) rule.getKnowledgeBase().getInterpreter()).getScriptContainer();
Object result = scriptContainer.callMethod(proc, "call", rule, event);
if (!(result instanceof Boolean)) {
throw new IllegalArgumentException("Condition method must return boolean value");
}
return (Boolean) result;
}
示例7: createResource
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
@Before
public void createResource()
{
jruby = new ScriptingContainer();
thrown = new DataException("any");
Value[] kvs = new Value[2];
kvs[0] = ValueFactory.newString("k");
kvs[1] = ValueFactory.newString("v");
mapValue = ValueFactory.newMap(kvs);
parser = new TimestampParser(jruby, "%Y-%m-%d %H:%M:%S.%N", DateTimeZone.UTC);
}
示例8: execute
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
@Override
public ScriptExecutionResult execute(GameScript<EmbedEvalUnit> s, ScriptBindings bindings,
boolean returnResult) throws Exception {
PerThreadGameScript<EmbedEvalUnit> script = (PerThreadGameScript<EmbedEvalUnit>) s;
ScriptingContainer scriptingContainer = executorPool.getLocalScriptingContainer();
for (String variableName : bindings.keySet()) {
scriptingContainer.put(variableName, bindings.get(variableName));
}
if (!script.hasLocalScript()) {
script.putLocalScript(scriptingContainer.parse(script.getContent()));
}
try {
EmbedEvalUnit embedEvalUnit = script.getScript();
embedEvalUnit.run();
} catch (Exception e) {
if(e.getCause() instanceof ScriptSkippedException) {
throw new ScriptSkippedException();
} else {
throw e;
}
}
if (!returnResult) {
scriptingContainer.clear();
return null;
}
ScriptExecutionResult executionResult = new ScriptExecutionResult(scriptingContainer.getVarMap().getMap());
scriptingContainer.clear();
return executionResult;
}
示例9: getLocalScriptingContainer
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
public ScriptingContainer getLocalScriptingContainer() {
long threadId = Thread.currentThread().getId();
if (!threadCompilers.containsKey(threadId)) {
ScriptingContainer scriptingContainer = new ScriptingContainer(LocalContextScope.THREADSAFE,
LocalVariableBehavior.PERSISTENT);
scriptingContainer.setCompileMode(CompileMode.JIT);
threadCompilers.put(threadId, scriptingContainer);
}
return threadCompilers.get(threadId);
}
示例10: setup
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
@Override
public void setup(OperatorContext context)
{
sc = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
for (String s : setupScripts) {
EvalUnit unit = sc.parse(s);
unit.run();
}
if (type == Type.EVAL) {
unit = sc.parse(script);
}
}
示例11: open
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
@Override
public void open() throws InterpreterException {
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 properties 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());
}
}
}
示例12: loadConfiguration
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
/**
* Load the Haml viewer configuration for the view.
*
* @param configuration The configuration object
*/
public void loadConfiguration(Configuration configuration)
throws ConfigurationException {
List<String> loadPaths = new ArrayList<String>();
// SINGLETHREAD is not threadsafe: http://www.ruby-forum.com/topic/206056#new
container = new ScriptingContainer(LocalContextScope.THREADSAFE);
scriptingContainerConfiguration = configuration;
RubyInstanceConfig config = container.getProvider().getRubyInstanceConfig();
if (scriptingContainerConfiguration != null) {
jrubyhome = scriptingContainerConfiguration.getChildValue("jruby_home");
if (jrubyhome != null) {
config.setJRubyHome(jrubyhome);
loadPaths.add(jrubyhome);
}
String userHamlScript = scriptingContainerConfiguration.getChildValue("haml");
if (userHamlScript != null) {
haml_rb = userHamlScript; //just a bit of inversion of control
}
}
haml_rb_unit = container.parse(haml_rb);
log.info("haml enabled ... have fun!");
}
示例13: getScriptingContainer
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
/**
* getScriptingContainer
*
* @return
*/
public synchronized ScriptingContainer getScriptingContainer()
{
if (this._scriptingContainer == null)
{
this._scriptingContainer = this.createScriptingContainer(LocalContextScope.SINGLETON);
}
return this._scriptingContainer;
}
示例14: getInitializedScriptingContainer
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
public synchronized ScriptingContainer getInitializedScriptingContainer()
{
ScriptingContainer sc = getScriptingContainer();
if (!initialized)
{
sc.runScriptlet("require 'ruble'"); //$NON-NLS-1$
initialized = true;
}
return sc;
}
示例15: doContextInitialized
import org.jruby.embed.ScriptingContainer; //导入依赖的package包/类
public void doContextInitialized( Helper configor ) throws IOException
{
// TODO use IsolatedScriptingContainer
RubygemsGateway gateway = new DefaultRubygemsGateway(new ScriptingContainer());
File path = configor.getFile( "GEM_PROXY_STORAGE", "var/cache/rubygems/proxy" );
if ( path == null )
{
throw new RuntimeException( "no storage path given");
}
ProxyStorage storage = new CachingProxyStorage( path, new URL( "https://rubygems.org" ) );
RubygemsFileSystem rubygems = new LegacyRubygemsFileSystem( gateway, storage );
configor.register( RubygemsFileSystem.class.getName(), null, rubygems );
configor.register( Storage.class.getName(), null, storage );
}