-
-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reimpl of Kernel#` using Java 7 process APIs.
- Loading branch information
Showing
6 changed files
with
96 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'jruby' | ||
|
||
module JRuby | ||
# Implementations of key core process-launching methods using Java 7 process | ||
# launching APIs. | ||
module ProcessManager | ||
java_import org.jruby.RubyProcess | ||
java_import org.jruby.util.ShellLauncher | ||
java_import java.lang.ProcessBuilder | ||
java_import org.jruby.runtime.builtin.IRubyObject | ||
|
||
Redirect = ProcessBuilder::Redirect | ||
LaunchConfig = ShellLauncher::LaunchConfig | ||
JFile = java.io.File | ||
|
||
def self.`(command) | ||
command = command.to_str unless command.kind_of?(String) | ||
|
||
config = LaunchConfig.new(JRuby.runtime, [command].to_java(IRubyObject), false) | ||
|
||
if config.should_run_in_shell? | ||
config.verify_executable_for_shell | ||
else | ||
config.verifiy_executable_for_direct | ||
end | ||
|
||
pb = ProcessBuilder.new(config.exec_args) | ||
pb.redirect_input(Redirect::INHERIT) | ||
pb.environment(ShellLauncher.get_current_env(JRuby.runtime)) | ||
pb.directory(JFile.new(JRuby.runtime.current_directory)) | ||
process = pb.start | ||
|
||
pid = ShellLauncher.reflect_pid_from_process(process) | ||
out = process.input_stream | ||
result = out.to_io.read | ||
exit_value = process.wait_for | ||
|
||
status = RubyProcess::RubyStatus.newProcessStatus(JRuby.runtime, exit_value, pid) | ||
JRuby.runtime.current_context.last_exit_status = status | ||
|
||
result | ||
end | ||
end | ||
end | ||
|
||
module Kernel | ||
module_function | ||
def `(command) | ||
JRuby::ProcessManager.`(command) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters