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

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

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

Ruby.setCurrentDirectory介绍

暂无

代码示例

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

@Override
public <T> T convertFile(File filename, Map<String, Object> options, Class<T> expectedResult) {
  this.rubyGemsPreloader.preloadRequiredLibraries(options);
  logger.fine(AsciidoctorUtils.toAsciidoctorCommand(options, filename.getAbsolutePath()));
  String currentDirectory = rubyRuntime.getCurrentDirectory();
  if (options.containsKey(Options.BASEDIR)) {
    rubyRuntime.setCurrentDirectory((String) options.get(Options.BASEDIR));
  }
  RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
  try {
    IRubyObject object = getAsciidoctorModule().callMethod("convert_file",
      rubyRuntime.newString(filename.getAbsolutePath()), rubyHash);
    if (NodeConverter.NodeType.DOCUMENT_CLASS.isInstance(object)) {
      // If a document is rendered to a file Asciidoctor returns the document, we return null
      return null;
    }
    return RubyUtils.rubyToJava(rubyRuntime, object, expectedResult);
  } catch(RaiseException e) {
    logger.severe(e.getMessage());
    throw new AsciidoctorCoreException(e);
  } finally {
    // we restore current directory to its original value.
    rubyRuntime.setCurrentDirectory(currentDirectory);
  }
}

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

@Override
public <T> T convertFile(File filename, Map<String, Object> options, Class<T> expectedResult) {
  this.rubyGemsPreloader.preloadRequiredLibraries(options);
  logger.fine(AsciidoctorUtils.toAsciidoctorCommand(options, filename.getAbsolutePath()));
  String currentDirectory = rubyRuntime.getCurrentDirectory();
  if (options.containsKey(Options.BASEDIR)) {
    rubyRuntime.setCurrentDirectory((String) options.get(Options.BASEDIR));
  }
  RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
  try {
    IRubyObject object = getAsciidoctorModule().callMethod("convert_file",
      rubyRuntime.newString(filename.getAbsolutePath()), rubyHash);
    if (NodeConverter.NodeType.DOCUMENT_CLASS.isInstance(object)) {
      // If a document is rendered to a file Asciidoctor returns the document, we return null
      return null;
    }
    return RubyUtils.rubyToJava(rubyRuntime, object, expectedResult);
  } catch(RaiseException e) {
    logger.severe(e.getMessage());
    throw new AsciidoctorCoreException(e);
  } finally {
    // we restore current directory to its original value.
    rubyRuntime.setCurrentDirectory(currentDirectory);
  }
}

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

/**
 * Changes a current directory to a given directory.
 * The current directory can be changed anytime.
 *
 * @since JRuby 1.5.0.
 *
 * @param directory a new directory to be set.
 */
public void setCurrentDirectory(String directory) {
  if (provider.isRuntimeInitialized()) {
    provider.getRuntime().setCurrentDirectory(directory);
  } else {
    provider.getRubyInstanceConfig().setCurrentDirectory(directory);
  }
}

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

/**
 * Changes a current directory to a given directory.
 * The current directory can be changed anytime.
 *
 * @since JRuby 1.5.0.
 *
 * @param directory a new directory to be set.
 */
public void setCurrentDirectory(String directory) {
  if (provider.isRuntimeInitialized()) {
    provider.getRuntime().setCurrentDirectory(directory);
  } else {
    provider.getRubyInstanceConfig().setCurrentDirectory(directory);
  }
}

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

/**
 * Changes a current directory to a given directory.
 * The current directory can be changed anytime.
 *
 * @since JRuby 1.5.0.
 *
 * @param directory a new directory to be set.
 */
public void setCurrentDirectory(String directory) {
  if (provider.isRuntimeInitialized()) {
    provider.getRuntime().setCurrentDirectory(directory);
  } else {
    provider.getRubyInstanceConfig().setCurrentDirectory(directory);
  }
}

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

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

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

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

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

/**
 * Changes a current directory to a given directory.
 * The current directory can be changed anytime.
 *
 * @since JRuby 1.5.0.
 *
 * @param directory a new directory to be set.
 */
public void setCurrentDirectory(String directory) {
  if (provider.isRuntimeInitialized()) {
    provider.getRuntime().setCurrentDirectory(directory);
  } else {
    provider.getRubyInstanceConfig().setCurrentDirectory(directory);
  }
}

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

/** Changes the current directory to <code>path</code> */
@JRubyMethod(optional = 1, meta = true)
public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
  Ruby runtime = context.runtime;
  RubyString path = args.length == 1 ?
    StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])) :
    getHomeDirectoryPath(context);
  String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
  checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
  
  adjustedPath = getExistingDir(runtime, adjustedPath).canonicalPath();
  IRubyObject result;
  if (block.isGiven()) {
    final String oldCwd = runtime.getCurrentDirectory();
    // FIXME: Don't allow multiple threads to do this at once
    runtime.setCurrentDirectory(adjustedPath);
    try {
      result = block.yield(context, path);
    } finally {
      getExistingDir(runtime, oldCwd); // needed in case the block deleted the oldCwd
      runtime.setCurrentDirectory(oldCwd);
    }
  } else {
    runtime.setCurrentDirectory(adjustedPath);
    result = runtime.newFixnum(0);
  }
  return result;
}

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

/** Changes the current directory to <code>path</code> */
@JRubyMethod(optional = 1, meta = true)
public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
  Ruby runtime = context.runtime;
  RubyString path = args.length == 1 ?
    StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])) :
    getHomeDirectoryPath(context);
  String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
  checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
  
  adjustedPath = getExistingDir(runtime, adjustedPath).canonicalPath();
  IRubyObject result;
  if (block.isGiven()) {
    final String oldCwd = runtime.getCurrentDirectory();
    // FIXME: Don't allow multiple threads to do this at once
    runtime.setCurrentDirectory(adjustedPath);
    try {
      result = block.yield(context, path);
    } finally {
      getExistingDir(runtime, oldCwd); // needed in case the block deleted the oldCwd
      runtime.setCurrentDirectory(oldCwd);
    }
  } else {
    runtime.setCurrentDirectory(adjustedPath);
    result = runtime.newFixnum(0);
  }
  return result;
}

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

if (block.isGiven()) {
  runtime.setCurrentDirectory(realPath);
  try {
    result = block.yield(context, path);
  } finally {
    dir = getDir(runtime, oldCwd, true);
    runtime.setCurrentDirectory(oldCwd);
  runtime.setCurrentDirectory(realPath);
  result = runtime.newFixnum(0);

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

if (block.isGiven()) {
  runtime.setCurrentDirectory(realPath);
  try {
    result = block.yield(context, path);
  } finally {
    dir = getDir(runtime, oldCwd, true);
    runtime.setCurrentDirectory(oldCwd);
  runtime.setCurrentDirectory(realPath);
  result = runtime.newFixnum(0);

相关文章

Ruby类方法