org.jruby.embed.LocalVariableBehavior Java Examples

The following examples show how to use org.jruby.embed.LocalVariableBehavior. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RubyOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example #2
Source File: ScriptingEngine.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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;
}