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

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

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

Ruby.setCurrentDirectory介绍

暂无

代码示例

代码示例来源:origin: org.asciidoctor/asciidoctorj

  1. @Override
  2. public <T> T convertFile(File filename, Map<String, Object> options, Class<T> expectedResult) {
  3. this.rubyGemsPreloader.preloadRequiredLibraries(options);
  4. logger.fine(AsciidoctorUtils.toAsciidoctorCommand(options, filename.getAbsolutePath()));
  5. String currentDirectory = rubyRuntime.getCurrentDirectory();
  6. if (options.containsKey(Options.BASEDIR)) {
  7. rubyRuntime.setCurrentDirectory((String) options.get(Options.BASEDIR));
  8. }
  9. RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
  10. try {
  11. IRubyObject object = getAsciidoctorModule().callMethod("convert_file",
  12. rubyRuntime.newString(filename.getAbsolutePath()), rubyHash);
  13. if (NodeConverter.NodeType.DOCUMENT_CLASS.isInstance(object)) {
  14. // If a document is rendered to a file Asciidoctor returns the document, we return null
  15. return null;
  16. }
  17. return RubyUtils.rubyToJava(rubyRuntime, object, expectedResult);
  18. } catch(RaiseException e) {
  19. logger.severe(e.getMessage());
  20. throw new AsciidoctorCoreException(e);
  21. } finally {
  22. // we restore current directory to its original value.
  23. rubyRuntime.setCurrentDirectory(currentDirectory);
  24. }
  25. }

代码示例来源:origin: asciidoctor/asciidoctorj

  1. @Override
  2. public <T> T convertFile(File filename, Map<String, Object> options, Class<T> expectedResult) {
  3. this.rubyGemsPreloader.preloadRequiredLibraries(options);
  4. logger.fine(AsciidoctorUtils.toAsciidoctorCommand(options, filename.getAbsolutePath()));
  5. String currentDirectory = rubyRuntime.getCurrentDirectory();
  6. if (options.containsKey(Options.BASEDIR)) {
  7. rubyRuntime.setCurrentDirectory((String) options.get(Options.BASEDIR));
  8. }
  9. RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
  10. try {
  11. IRubyObject object = getAsciidoctorModule().callMethod("convert_file",
  12. rubyRuntime.newString(filename.getAbsolutePath()), rubyHash);
  13. if (NodeConverter.NodeType.DOCUMENT_CLASS.isInstance(object)) {
  14. // If a document is rendered to a file Asciidoctor returns the document, we return null
  15. return null;
  16. }
  17. return RubyUtils.rubyToJava(rubyRuntime, object, expectedResult);
  18. } catch(RaiseException e) {
  19. logger.severe(e.getMessage());
  20. throw new AsciidoctorCoreException(e);
  21. } finally {
  22. // we restore current directory to its original value.
  23. rubyRuntime.setCurrentDirectory(currentDirectory);
  24. }
  25. }

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

  1. /**
  2. * Changes a current directory to a given directory.
  3. * The current directory can be changed anytime.
  4. *
  5. * @since JRuby 1.5.0.
  6. *
  7. * @param directory a new directory to be set.
  8. */
  9. public void setCurrentDirectory(String directory) {
  10. if (provider.isRuntimeInitialized()) {
  11. provider.getRuntime().setCurrentDirectory(directory);
  12. } else {
  13. provider.getRubyInstanceConfig().setCurrentDirectory(directory);
  14. }
  15. }

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

  1. /**
  2. * Changes a current directory to a given directory.
  3. * The current directory can be changed anytime.
  4. *
  5. * @since JRuby 1.5.0.
  6. *
  7. * @param directory a new directory to be set.
  8. */
  9. public void setCurrentDirectory(String directory) {
  10. if (provider.isRuntimeInitialized()) {
  11. provider.getRuntime().setCurrentDirectory(directory);
  12. } else {
  13. provider.getRubyInstanceConfig().setCurrentDirectory(directory);
  14. }
  15. }

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

  1. /**
  2. * Changes a current directory to a given directory.
  3. * The current directory can be changed anytime.
  4. *
  5. * @since JRuby 1.5.0.
  6. *
  7. * @param directory a new directory to be set.
  8. */
  9. public void setCurrentDirectory(String directory) {
  10. if (provider.isRuntimeInitialized()) {
  11. provider.getRuntime().setCurrentDirectory(directory);
  12. } else {
  13. provider.getRubyInstanceConfig().setCurrentDirectory(directory);
  14. }
  15. }

代码示例来源:origin: org.asciidoctor/asciidoctorj

  1. rubyRuntime.setCurrentDirectory((String) options.get(Options.BASEDIR));
  2. } finally {
  3. rubyRuntime.setCurrentDirectory(currentDirectory);

代码示例来源:origin: asciidoctor/asciidoctorj

  1. rubyRuntime.setCurrentDirectory((String) options.get(Options.BASEDIR));
  2. } finally {
  3. rubyRuntime.setCurrentDirectory(currentDirectory);

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

  1. /**
  2. * Changes a current directory to a given directory.
  3. * The current directory can be changed anytime.
  4. *
  5. * @since JRuby 1.5.0.
  6. *
  7. * @param directory a new directory to be set.
  8. */
  9. public void setCurrentDirectory(String directory) {
  10. if (provider.isRuntimeInitialized()) {
  11. provider.getRuntime().setCurrentDirectory(directory);
  12. } else {
  13. provider.getRubyInstanceConfig().setCurrentDirectory(directory);
  14. }
  15. }

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

  1. /** Changes the current directory to <code>path</code> */
  2. @JRubyMethod(optional = 1, meta = true)
  3. public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
  4. Ruby runtime = context.runtime;
  5. RubyString path = args.length == 1 ?
  6. StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])) :
  7. getHomeDirectoryPath(context);
  8. String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
  9. checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
  10. adjustedPath = getExistingDir(runtime, adjustedPath).canonicalPath();
  11. IRubyObject result;
  12. if (block.isGiven()) {
  13. final String oldCwd = runtime.getCurrentDirectory();
  14. // FIXME: Don't allow multiple threads to do this at once
  15. runtime.setCurrentDirectory(adjustedPath);
  16. try {
  17. result = block.yield(context, path);
  18. } finally {
  19. getExistingDir(runtime, oldCwd); // needed in case the block deleted the oldCwd
  20. runtime.setCurrentDirectory(oldCwd);
  21. }
  22. } else {
  23. runtime.setCurrentDirectory(adjustedPath);
  24. result = runtime.newFixnum(0);
  25. }
  26. return result;
  27. }

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

  1. /** Changes the current directory to <code>path</code> */
  2. @JRubyMethod(optional = 1, meta = true)
  3. public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
  4. Ruby runtime = context.runtime;
  5. RubyString path = args.length == 1 ?
  6. StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])) :
  7. getHomeDirectoryPath(context);
  8. String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
  9. checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
  10. adjustedPath = getExistingDir(runtime, adjustedPath).canonicalPath();
  11. IRubyObject result;
  12. if (block.isGiven()) {
  13. final String oldCwd = runtime.getCurrentDirectory();
  14. // FIXME: Don't allow multiple threads to do this at once
  15. runtime.setCurrentDirectory(adjustedPath);
  16. try {
  17. result = block.yield(context, path);
  18. } finally {
  19. getExistingDir(runtime, oldCwd); // needed in case the block deleted the oldCwd
  20. runtime.setCurrentDirectory(oldCwd);
  21. }
  22. } else {
  23. runtime.setCurrentDirectory(adjustedPath);
  24. result = runtime.newFixnum(0);
  25. }
  26. return result;
  27. }

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

  1. if (block.isGiven()) {
  2. runtime.setCurrentDirectory(realPath);
  3. try {
  4. result = block.yield(context, path);
  5. } finally {
  6. dir = getDir(runtime, oldCwd, true);
  7. runtime.setCurrentDirectory(oldCwd);
  8. runtime.setCurrentDirectory(realPath);
  9. result = runtime.newFixnum(0);

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

  1. if (block.isGiven()) {
  2. runtime.setCurrentDirectory(realPath);
  3. try {
  4. result = block.yield(context, path);
  5. } finally {
  6. dir = getDir(runtime, oldCwd, true);
  7. runtime.setCurrentDirectory(oldCwd);
  8. runtime.setCurrentDirectory(realPath);
  9. result = runtime.newFixnum(0);

相关文章

Ruby类方法