本文整理匯總了Java中org.jruby.embed.ScriptingContainer.setOutput方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptingContainer.setOutput方法的具體用法?Java ScriptingContainer.setOutput怎麽用?Java ScriptingContainer.setOutput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jruby.embed.ScriptingContainer
的用法示例。
在下文中一共展示了ScriptingContainer.setOutput方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getScript
import org.jruby.embed.ScriptingContainer; //導入方法依賴的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;
}
示例2: JRubyWrapper
import org.jruby.embed.ScriptingContainer; //導入方法依賴的package包/類
/**
* Create a new JRuby wrapper.
* @param profile whether or not profiling is enabled
*/
public JRubyWrapper(boolean profile) {
rb = new ScriptingContainer(LocalContextScope.THREADSAFE);
rb.setCompatVersion(CompatVersion.RUBY1_9);
rb.setCurrentDirectory(Paths.get("").toAbsolutePath().toString()); // set working directory of scripts to working directory of application
@SuppressWarnings("unchecked")
Map<String, String> env = new HashMap<>(rb.getEnvironment());
env.put("GEM_PATH", Paths.get("lib/gems").toAbsolutePath().toString());
MewtwoMain.mewtwoLogger.info("Setting GEM_PATH of container to " + env.get("GEM_PATH"));
rb.setEnvironment(env);
ArrayList<String> loadPaths = new ArrayList<>();
File gemsFile = Paths.get("lib/gems").toFile();
File[] files = gemsFile.listFiles();
for(File child : files != null ? files : new File[0]) {
String subPath = Paths.get(child.getAbsolutePath()).resolve("lib").toString();
MewtwoMain.mewtwoLogger.info("Adding '" + subPath + "' to loadPaths");
loadPaths.add(subPath);
}
rb.setLoadPaths(loadPaths);
swOut = new StringWriter();
swErr = new StringWriter();
PrintWriter pwOut = new PrintWriter(swOut);
PrintWriter pwErr = new PrintWriter(swErr);
rb.setOutput(pwOut);
rb.setError(pwErr);
if(profile) {
rb.setProfile(RubyInstanceConfig.ProfilingMode.GRAPH);
try {
rb.setProfileOutput(new ProfileOutput(new File("profile.txt")));
} catch(IOException e) {
MewtwoMain.mewtwoLogger.error("Could not initialize JRuby profiler! Disabling profiling.");
}
}
long time = System.currentTimeMillis();
MewtwoMain.mewtwoLogger.info("Initializing ScriptingContainer - this might take a few seconds!");
rb.runScriptlet("require 'java'; Java::Meew0Mewtwo::MewtwoMain.mewtwoLogger.info('Hello world! This is JRuby')");
MewtwoMain.mewtwoLogger.info("ScriptingContainer successfully initialized in " +
(System.currentTimeMillis() - time) + " ms");
}