org.jruby.Ruby.loadFile()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(291)

本文整理了Java中org.jruby.Ruby.loadFile方法的一些代码示例,展示了Ruby.loadFile的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.loadFile方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:loadFile

Ruby.loadFile介绍

暂无

代码示例

代码示例来源:origin: com.proofpoint.platform/rack

  1. private void loadRubyScript(String scriptName)
  2. throws IOException
  3. {
  4. try (InputStream stream = Resources.getResource("proofpoint/" + scriptName).openStream()) {
  5. runtime.loadFile(scriptName, stream, false);
  6. }
  7. }

代码示例来源:origin: com.proofpoint.platform/rack-experimental

  1. @Inject
  2. public RackServlet(RackServletConfig config)
  3. throws IOException
  4. {
  5. Preconditions.checkNotNull(config);
  6. File rackScriptFile = new File(config.getRackConfigPath());
  7. Preconditions.checkArgument(rackScriptFile.canRead(), "Could not find rack script specified by [" + config.getRackConfigPath()
  8. + "] and resolved to [" + rackScriptFile.getAbsolutePath() + "]");
  9. runtime = JavaEmbedUtils.initialize(ImmutableList.of(rackScriptFile.getParentFile().getCanonicalPath()), createRuntimeConfig());
  10. // don't inherit system settings for gems
  11. RubyHash env = runtime.evalScriptlet("ENV").convertToHash();
  12. env.remove("GEM_HOME");
  13. env.remove("GEM_PATH");
  14. InputStream stream = Resources.getResource("proofpoint/rack.rb").openStream();
  15. try {
  16. runtime.loadFile("rack.rb", stream, false);
  17. }
  18. finally {
  19. stream.close();
  20. }
  21. IRubyObject builder = runtime.evalScriptlet("Proofpoint::RackServer::Builder.new");
  22. rackApplication = adapter.callMethod(builder, "build", new IRubyObject[] {
  23. javaToRuby(runtime, rackScriptFile.getCanonicalPath())
  24. });
  25. }

代码示例来源:origin: io.airlift/rack-experimental

  1. @Inject
  2. public RackServlet(RackServletConfig config)
  3. throws IOException
  4. {
  5. Preconditions.checkNotNull(config);
  6. File rackScriptFile = new File(config.getRackConfigPath());
  7. Preconditions.checkArgument(rackScriptFile.canRead(), "Could not find rack script specified by [" + config.getRackConfigPath()
  8. + "] and resolved to [" + rackScriptFile.getAbsolutePath() + "]");
  9. runtime = JavaEmbedUtils.initialize(ImmutableList.of(rackScriptFile.getParentFile().getCanonicalPath()), createRuntimeConfig());
  10. // don't inherit system settings for gems
  11. RubyHash env = runtime.evalScriptlet("ENV").convertToHash();
  12. env.remove("GEM_HOME");
  13. env.remove("GEM_PATH");
  14. InputStream stream = Resources.getResource("io/airlift/rack.rb").openStream();
  15. try {
  16. runtime.loadFile("rack.rb", stream, false);
  17. }
  18. finally {
  19. stream.close();
  20. }
  21. IRubyObject builder = runtime.evalScriptlet("Airlift::RackServer::Builder.new");
  22. rackApplication = adapter.callMethod(builder, "build", new IRubyObject[] {
  23. javaToRuby(runtime, rackScriptFile.getCanonicalPath())
  24. });
  25. }

代码示例来源:origin: io.airlift/rack

  1. @Inject
  2. public RackServlet(RackServletConfig config)
  3. throws IOException
  4. {
  5. Preconditions.checkNotNull(config);
  6. File rackScriptFile = new File(config.getRackConfigPath());
  7. Preconditions.checkArgument(rackScriptFile.canRead(), "Could not find rack script specified by [" + config.getRackConfigPath()
  8. + "] and resolved to [" + rackScriptFile.getAbsolutePath() + "]");
  9. runtime = JavaEmbedUtils.initialize(ImmutableList.of(rackScriptFile.getParentFile().getCanonicalPath()), createRuntimeConfig());
  10. // don't inherit system settings for gems
  11. RubyHash env = runtime.evalScriptlet("ENV").convertToHash();
  12. env.remove("GEM_HOME");
  13. env.remove("GEM_PATH");
  14. InputStream stream = Resources.getResource("io/airlift/rack.rb").openStream();
  15. try {
  16. runtime.loadFile("rack.rb", stream, false);
  17. }
  18. finally {
  19. stream.close();
  20. }
  21. IRubyObject builder = runtime.evalScriptlet("Airlift::RackServer::Builder.new");
  22. rackApplication = adapter.callMethod(builder, "build", new IRubyObject[] {
  23. javaToRuby(runtime, rackScriptFile.getCanonicalPath())
  24. });
  25. }

代码示例来源:origin: org.jruby/jruby-complete

  1. @Override
  2. public void load(Ruby runtime, boolean wrap) {
  3. InputStream ris = null;
  4. try {
  5. ris = resource.inputStream();
  6. if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) {
  7. runtime.compileAndLoadFile(scriptName, ris, wrap);
  8. } else {
  9. runtime.loadFile(scriptName, new LoadServiceResourceInputStream(ris), wrap);
  10. }
  11. } catch(IOException e) {
  12. throw runtime.newLoadError("no such file to load -- " + searchName, searchName);
  13. } finally {
  14. try {
  15. if (ris != null) ris.close();
  16. } catch (IOException ioE) { /* At least we tried.... */}
  17. }
  18. }
  19. }

代码示例来源:origin: org.jruby/jruby-core

  1. @Override
  2. public void load(Ruby runtime, boolean wrap) {
  3. InputStream ris = null;
  4. try {
  5. ris = resource.inputStream();
  6. if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) {
  7. runtime.compileAndLoadFile(scriptName, ris, wrap);
  8. } else {
  9. runtime.loadFile(scriptName, new LoadServiceResourceInputStream(ris), wrap);
  10. }
  11. } catch(IOException e) {
  12. throw runtime.newLoadError("no such file to load -- " + searchName, searchName);
  13. } finally {
  14. try {
  15. if (ris != null) ris.close();
  16. } catch (IOException ioE) { /* At least we tried.... */}
  17. }
  18. }
  19. }

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

  1. public void load(Ruby runtime, boolean wrap) {
  2. InputStream in = null;
  3. try {
  4. in = resource.getInputStream();
  5. String name = normalizeSeps(resource.getName());
  6. if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) {
  7. runtime.compileAndLoadFile(name, in, wrap);
  8. } else {
  9. java.io.File path = resource.getPath();
  10. if(path != null && !resource.isAbsolute()) {
  11. // Note: We use RubyFile's canonicalize rather than Java's,
  12. // because Java's will follow symlinks and result in __FILE__
  13. // being set to the target of the symlink rather than the
  14. // filename provided.
  15. name = normalizeSeps(canonicalize(path.getPath()));
  16. }
  17. runtime.loadFile(name, in, wrap);
  18. }
  19. } catch (IOException e) {
  20. throw runtime.newIOErrorFromException(e);
  21. } finally {
  22. try { in.close(); } catch (Exception ex) {}
  23. }
  24. }

代码示例来源:origin: org.jruby/jruby-complete

  1. public void load(Ruby runtime, boolean wrap) {
  2. InputStream in = null;
  3. try {
  4. in = resource.getInputStream();
  5. String name = resource.getName();
  6. if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) {
  7. runtime.compileAndLoadFile(name, in, wrap);
  8. } else {
  9. name = CompiledScriptLoader.getFilenameFromPathAndName(resource.getPath(), name, resource.isAbsolute());
  10. runtime.loadFile(name, new LoadServiceResourceInputStream(in), wrap);
  11. }
  12. } catch (IOException e) {
  13. throw runtime.newIOErrorFromException(e);
  14. } finally {
  15. try { in.close(); } catch (Exception ex) {}
  16. }
  17. }

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

  1. public void load(Ruby runtime, boolean wrap) {
  2. InputStream in = null;
  3. try {
  4. in = resource.getInputStream();
  5. String name = normalizeSeps(resource.getName());
  6. if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) {
  7. runtime.compileAndLoadFile(name, in, wrap);
  8. } else {
  9. java.io.File path = resource.getPath();
  10. if(path != null && !resource.isAbsolute()) {
  11. // Note: We use RubyFile's canonicalize rather than Java's,
  12. // because Java's will follow symlinks and result in __FILE__
  13. // being set to the target of the symlink rather than the
  14. // filename provided.
  15. name = normalizeSeps(canonicalize(path.getPath()));
  16. }
  17. runtime.loadFile(name, in, wrap);
  18. }
  19. } catch (IOException e) {
  20. throw runtime.newIOErrorFromException(e);
  21. } finally {
  22. try { in.close(); } catch (Exception ex) {}
  23. }
  24. }

代码示例来源:origin: org.jruby/jruby-core

  1. public void load(Ruby runtime, boolean wrap) {
  2. InputStream in = null;
  3. try {
  4. in = resource.getInputStream();
  5. String name = resource.getName();
  6. if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) {
  7. runtime.compileAndLoadFile(name, in, wrap);
  8. } else {
  9. name = CompiledScriptLoader.getFilenameFromPathAndName(resource.getPath(), name, resource.isAbsolute());
  10. runtime.loadFile(name, new LoadServiceResourceInputStream(in), wrap);
  11. }
  12. } catch (IOException e) {
  13. throw runtime.newIOErrorFromException(e);
  14. } finally {
  15. try { in.close(); } catch (Exception ex) {}
  16. }
  17. }

相关文章

Ruby类方法