本文整理汇总了Java中org.jruby.embed.LocalVariableBehavior类的典型用法代码示例。如果您正苦于以下问题:Java LocalVariableBehavior类的具体用法?Java LocalVariableBehavior怎么用?Java LocalVariableBehavior使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalVariableBehavior类属于org.jruby.embed包,在下文中一共展示了LocalVariableBehavior类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLocalScriptingContainer
import org.jruby.embed.LocalVariableBehavior; //导入依赖的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);
}
示例2: setup
import org.jruby.embed.LocalVariableBehavior; //导入依赖的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);
}
}
示例3: createCache
import org.jruby.embed.LocalVariableBehavior; //导入依赖的package包/类
private Properties createCache(File configFile, File cacheFile) {
ScriptingContainer container = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
container.runScriptlet(PathType.ABSOLUTE, configFile.getAbsolutePath());
@SuppressWarnings("unchecked")
BiVariableMap<String, Object> varMap = container.getVarMap();
@SuppressWarnings("unchecked")
Set<Map.Entry<String, Object>> entrySet = varMap.entrySet();
Properties props = new Properties();
for (Map.Entry<String, Object> en : entrySet) {
if (en.getValue() instanceof String) {
props.setProperty(en.getKey(), (String) en.getValue());
}
}
//save
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(cacheFile);
props.store(outputStream, "Compass config cache");
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IOUtils.closeQuietly(outputStream);
}
return props;
}
示例4: getScript
import org.jruby.embed.LocalVariableBehavior; //导入依赖的package包/类
public JavaEmbedUtils.EvalUnit getScript() throws FileNotFoundException {
if (this.unit == null) {
if (!this.configFile.exists()) {
throw new FileNotFoundException("Configuration file does not exist");
}
ScriptingContainer scriptingContainer = new ScriptingContainer(
LocalContextScope.THREADSAFE,
LocalVariableBehavior.PERSISTENT);
scriptingContainer.setOutput(new PrintStream(new NullOutputStream()));
StringBuilder script = new StringBuilder()
.append("require 'compass'\n")
.append("require 'compass/sass_compiler'\n")
.append("Compass.reset_configuration!\n")
.append("Compass.add_project_configuration configLocation\n")
// remove color codes since they cannot be proceeded correctly by IDE consoles
.append("Compass.configuration.color_output = false\n")
.append("Compass.configure_sass_plugin!\n")
.append("Compass.configuration.on_stylesheet_saved { |filename| callback_logger.onStylesheetSaved(filename) }\n")
.append("Compass.configuration.on_stylesheet_error { |filename, message| callback_logger.onStylesheetError(filename, message) }\n")
.append("Compass.configuration.on_sprite_saved { |filename| callback_logger.onSpriteSaved(filename) }\n")
.append("Dir.chdir(File.dirname(configLocation)) do\n")
.append(" Compass.sass_compiler.compile!\n")
.append("end\n");
scriptingContainer.put("configLocation", this.configFile.getAbsolutePath().replaceAll("\\\\", "/"));
scriptingContainer.put("callback_logger", callbackLogger);
this.unit = scriptingContainer.parse(script.toString());
}
return this.unit;
}
示例5: prepareInterpreter
import org.jruby.embed.LocalVariableBehavior; //导入依赖的package包/类
@Override
protected void prepareInterpreter() {
container = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.PERSISTENT);
setLoadPaths(getEngineOperations() != null ? getEngineOperations().getEngine() : null);
addSpecific();
PROCESSOR_CLASSES.forEach((interfaceClass, scriptClass) -> addImport(scriptClass, interfaceClass.getSimpleName()));
addImport(JRubyPlugin.class, Plugin.class.getSimpleName());
getStandardImportClasses().forEach(cls -> addImport(cls));
addImport(RubyUtils.class);
container.put(createVariableName(KnowledgeBaseConstants.VAR_ENGINE_OPERATIONS), getEngineOperations());
container.setErrorWriter(new JRubyLogErrorWriter());
}
示例6: init
import org.jruby.embed.LocalVariableBehavior; //导入依赖的package包/类
public void init() {
System.setProperty("org.jruby.embed.localcontext.scope", LocalContextScope.THREADSAFE.name().toLowerCase());
System.setProperty("org.jruby.embed.localvariable.behavior",
LocalVariableBehavior.TRANSIENT.name().toLowerCase());
isInitted = true;
}
示例7: createScriptingContainer
import org.jruby.embed.LocalVariableBehavior; //导入依赖的package包/类
/**
* createScriptingContainer
*
* @param scope
* @return
*/
private ScriptingContainer createScriptingContainer(LocalContextScope scope)
{
// ScriptingContainer result = new ScriptingContainer(scope, LocalVariableBehavior.PERSISTENT);
ScriptingContainer result = new ScriptingContainer(scope, LocalVariableBehavior.TRANSIENT);
try
{
File jrubyHome = null;
Bundle jruby = Platform.getBundle("org.jruby"); //$NON-NLS-1$
// try just exploding the jruby lib dir
URL url = FileLocator.find(jruby, new Path("lib"), null); //$NON-NLS-1$
if (url != null)
{
File lib = ResourceUtil.resourcePathToFile(url);
// Ok, now use the parent of exploded lib dir as JRuby Home
jrubyHome = lib.getParentFile();
}
else
{
// Ok, just assume the plugin is unpacked and pass the root of the plugin as JRuby Home
jrubyHome = FileLocator.getBundleFile(jruby);
}
result.setHomeDirectory(jrubyHome.getAbsolutePath());
// TODO Generate two containers? A global one for loading bundles, a threadsafe one for executing
// commands/snippets/etc?
// Pre-load 'ruble' framework files!
List<String> loadPaths = result.getLoadPaths();
loadPaths.addAll(0, getContributedLoadPaths());
result.setLoadPaths(loadPaths);
}
catch (IOException e)
{
String message = MessageFormat.format(Messages.ScriptingEngine_Error_Setting_JRuby_Home,
new Object[] { e.getMessage() });
IdeLog.logError(ScriptingActivator.getDefault(), message, e);
ScriptLogger.logError(message);
}
return result;
}