Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7845e582d994
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: db5015217234
Choose a head ref
  • 6 commits
  • 7 files changed
  • 1 contributor

Commits on May 20, 2018

  1. Copy the full SHA
    b3b1d52 View commit details
  2. Copy the full SHA
    f0a5949 View commit details
  3. Copy the full SHA
    4e8eccf View commit details
  4. Copy the full SHA
    7e5ea88 View commit details
  5. Copy the full SHA
    2ae38a0 View commit details
  6. Copy the full SHA
    db50152 View commit details
17 changes: 12 additions & 5 deletions core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java
Original file line number Diff line number Diff line change
@@ -32,11 +32,7 @@
package org.jruby.ext.jruby;

import org.jcodings.specific.ASCIIEncoding;
import org.jruby.Ruby;
import org.jruby.RubyBoolean;
import org.jruby.RubyClass;
import org.jruby.RubyModule;
import org.jruby.RubyString;
import org.jruby.*;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.ast.Node;
@@ -201,6 +197,17 @@ public static IRubyObject identity_hash(ThreadContext context, IRubyObject recv,
return context.runtime.newFixnum(System.identityHashCode(obj));
}

@JRubyMethod(name = "set_last_exit_status", module = true) // used from JRuby::ProcessManager
public static IRubyObject set_last_exit_status(ThreadContext context, IRubyObject recv,
IRubyObject status, IRubyObject pid) {
RubyProcess.RubyStatus processStatus = RubyProcess.RubyStatus.newProcessStatus(context.runtime,
status.convertToInteger().getLongValue(),
pid.convertToInteger().getLongValue()
);
context.setLastExitStatus(processStatus);
return processStatus;
}

@JRubyMethod(module = true, name = "parse", alias = "ast_for", required = 1, optional = 3)
public static IRubyObject parse(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
// def parse(content = nil, filename = DEFAULT_FILENAME, extra_position_info = false, lineno = 0, &block)
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/ext/jruby/JRubyUtilLibrary.java
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ public void load(Ruby runtime, boolean wrap) throws IOException {
RubyModule JRubyUtil = runtime.getOrCreateModule("JRuby").defineModuleUnder("Util");
JRubyUtil.defineAnnotatedMethods(JRubyUtilLibrary.class);
JRubyUtil.setConstant("SEPARATOR", runtime.newString(org.jruby.util.cli.ArgumentProcessor.SEPARATOR));
JRubyUtil.setConstant("ON_WINDOWS", runtime.newBoolean(org.jruby.platform.Platform.IS_WINDOWS));
}

@JRubyMethod(module = true)
@@ -105,15 +106,15 @@ public static IRubyObject getClassLoaderResources(IRubyObject recv, IRubyObject
}
}

@JRubyMethod(module = true) // for RubyGems' JRuby defaults
@JRubyMethod(meta = true) // for RubyGems' JRuby defaults
public static IRubyObject classpath_launcher(ThreadContext context, IRubyObject recv) {
final Ruby runtime = context.runtime;
String launcher = runtime.getInstanceConfig().getEnvironment().get("RUBY");
if ( launcher == null ) launcher = ClasspathLauncher.jrubyCommand(runtime);
return runtime.newString(launcher);
}

@JRubyMethod(name = "extra_gem_paths", module = true) // used from RGs' JRuby defaults
@JRubyMethod(name = "extra_gem_paths", meta = true) // used from RGs' JRuby defaults
public static IRubyObject extra_gem_paths(ThreadContext context, IRubyObject recv) {
final Ruby runtime = context.runtime;
final List<String> extraGemPaths = runtime.getInstanceConfig().getExtraGemPaths();
@@ -148,8 +149,8 @@ public static IRubyObject cache_stats(ThreadContext context, IRubyObject self) {
}

/**
* Return a list of files and extensions that JRuby treats as internal (or "built-in"), skipping load path and
* filesystem search.
* Return a list of files and extensions that JRuby treats as internal (or "built-in"),
* skipping load path and filesystem search.
*
* This was added for Bootsnap in https://github.com/Shopify/bootsnap/issues/162
*/
19 changes: 19 additions & 0 deletions core/src/main/java/org/jruby/javasupport/JavaUtilities.java
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.StringSupport;

@JRubyModule(name = "JavaUtilities")
public class JavaUtilities {
@@ -53,4 +54,22 @@ public static IRubyObject get_top_level_proxy_or_package(ThreadContext context,
public static IRubyObject get_proxy_or_package_under_package(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1) {
return Java.get_proxy_or_package_under_package(context, recv, arg0, arg1);
}

@JRubyMethod(name = "valid_java_identifier?", meta = true)
public static IRubyObject valid_java_identifier_p(ThreadContext context, IRubyObject recv, IRubyObject name) {
final String javaName = name.convertToString().decodeString();
return context.runtime.newBoolean(validJavaIdentifier(javaName));
}

private static boolean validJavaIdentifier(final String javaName) {
for (String frag : StringSupport.split(javaName, '.')) {
if (frag.length() == 0) return false;
if (!Character.isJavaIdentifierStart(frag.codePointAt(0))) return false;
for (int i = 1; i < frag.length(); i++) {
if (!Character.isJavaIdentifierPart(frag.codePointAt(i))) return false;
}
}
return true;
}

}
22 changes: 12 additions & 10 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Original file line number Diff line number Diff line change
@@ -232,19 +232,19 @@ public static String[] getModifiedEnv(Ruby runtime, Collection mergeEnv, boolean
// dup for JRUBY-6603 (avoid concurrent modification while we walk it)
RubyHash hash = null;
if (!clearEnv) {
hash = (RubyHash)runtime.getObject().getConstant("ENV").dup();
hash = (RubyHash) runtime.getObject().getConstant("ENV").dup();
}
String[] ret, ary;
String[] ret;

if (mergeEnv != null) {
ret = new String[hash.size() + mergeEnv.size()];
} else {
ret = new String[hash.size()];
}

int i=0;
int i = 0;
if (hash != null) {
for(Map.Entry<String, String> e : (Set<Map.Entry<String, String>>)hash.entrySet()) {
for (Map.Entry<String, String> e : (Set<Map.Entry<String, String>>)hash.entrySet()) {
// if the key is nil, raise TypeError
if (e.getKey() == null) {
throw runtime.newTypeError(runtime.getNil(), runtime.getStructClass());
@@ -253,7 +253,7 @@ public static String[] getModifiedEnv(Ruby runtime, Collection mergeEnv, boolean
if (e.getValue() == null) {
continue;
}
ret[i] = e.getKey() + "=" + e.getValue();
ret[i] = e.getKey() + '=' + e.getValue();
i++;
}
}
@@ -268,7 +268,7 @@ public static String[] getModifiedEnv(Ruby runtime, Collection mergeEnv, boolean
if (e.getValue() == null) {
continue;
}
ret[i] = e.getKey().toString() + "=" + e.getValue().toString();
ret[i] = e.getKey() + '=' + e.getValue();
i++;
}
} else if (mergeEnv instanceof RubyArray) {
@@ -286,21 +286,23 @@ public static String[] getModifiedEnv(Ruby runtime, Collection mergeEnv, boolean
if (e.eltOk(1) == null) {
continue;
}
ret[i] = e.eltOk(0).toString() + "=" + e.eltOk(1).toString();
ret[i] = e.eltOk(0).toString() + '=' + e.eltOk(1).toString();
i++;
}
}
}

ary = new String[i];
System.arraycopy(ret, 0, ary, 0, i);
return ary;
return arrayOfLength(ret, i);

} finally {
context.setEventHooksEnabled(traceEnabled);
}
}

private static String[] arrayOfLength(final String[] ary, final int len) {
return len == ary.length ? ary : Arrays.copyOf(ary, len);
}

private static boolean filenameIsPathSearchable(String fname, boolean forExec) {
boolean isSearchable = true;
if (fname.startsWith("/") ||
10 changes: 2 additions & 8 deletions core/src/main/ruby/jruby/java/core_ext/object.rb
Original file line number Diff line number Diff line change
@@ -36,16 +36,10 @@ def java_import(*import_classes)
import_classes.map do |import_class|
case import_class
when String
cc = java.lang.Character
valid_name = import_class.split(".").all? do |frag|
cc.java_identifier_start? frag[0].ord and
frag.each_char.all? {|c| cc.java_identifier_part? c.ord }
end
unless valid_name
unless JavaUtilities.valid_java_identifier?(import_class)
raise ArgumentError.new "not a valid Java identifier: #{import_class}"
end
# pull in the class
raise ArgumentError.new "must use jvm-style name: #{import_class}" if import_class.include? "::"
raise ArgumentError.new "must use jvm-style name: #{import_class}" if import_class.include?('::')
import_class = JavaUtilities.get_proxy_class(import_class)
when Module
if import_class.respond_to? "java_class"
18 changes: 7 additions & 11 deletions core/src/main/ruby/jruby/kernel/jruby/process_manager.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
module JRuby
# Implementations of key core process-launching methods using Java 7 process
# launching APIs.
# 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
java_import org.jruby.platform.Platform
java_import org.jruby.util.ShellLauncher

Redirect = ProcessBuilder::Redirect
LaunchConfig = ShellLauncher::LaunchConfig
@@ -15,9 +11,9 @@ module ProcessManager
def self.`(command)
command = command.to_str unless command.kind_of?(String)

config = LaunchConfig.new(JRuby.runtime, [command].to_java(IRubyObject), false)
config = LaunchConfig.new(JRuby.runtime, [command], false)

use_shell = Platform::IS_WINDOWS ? config.should_run_in_shell : false
use_shell = JRuby::Util::ON_WINDOWS ? config.should_run_in_shell : false
use_shell |= ShellLauncher.should_use_shell(command)

if use_shell
@@ -30,7 +26,8 @@ def self.`(command)
pb.redirect_input(Redirect::INHERIT)
pb.redirect_error(Redirect::INHERIT)
pb.environment(ShellLauncher.get_current_env(JRuby.runtime))
cwd = JRuby.runtime.current_directory.start_with?('uri:classloader:/') ? ENV_JAVA['user.dir'] : JRuby.runtime.current_directory
cwd = JRuby.runtime.current_directory
cwd = cwd.start_with?('uri:classloader:/') ? ENV_JAVA['user.dir'] : cwd
pb.directory(JFile.new(cwd))
process = pb.start

@@ -40,8 +37,7 @@ def self.`(command)
exit_value = process.wait_for

# RubyStatus uses real native status now, so we unshift Java's shifted exit status
status = RubyProcess::RubyStatus.newProcessStatus(JRuby.runtime, exit_value << 8, pid)
JRuby.runtime.current_context.last_exit_status = status
JRuby.set_last_exit_status(exit_value << 8, pid)

result.gsub(/\r\n/, "\n")
end
20 changes: 14 additions & 6 deletions test/jruby/test_system.rb
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@

require 'test/unit'
require 'rbconfig'
require 'open3'

class TestSystem < Test::Unit::TestCase

# JRUBY-5110
if RbConfig::CONFIG['host_os'] =~ /Windows|mswin/
def test_system_on_windows
@@ -14,18 +14,26 @@ def test_system_on_windows
end

# JRUBY-6960
def test_system_with_conflicting_dir
FileUtils.mkdir_p 'extra_path/java'
def test_system_with_conflicting_dir; require 'open3'
FileUtils.mkdir_p '6960-extra_path/java'

path = ENV['PATH']
ENV['PATH'] = "extra_path#{File::PATH_SEPARATOR}#{path}"
Open3.popen3('java -version') do |i, o, e, t|
if ENV['JAVA_HOME'] && defined? JRUBY_VERSION
unless path.split(File::PATH_SEPARATOR).include?(ENV['JAVA_HOME'])
path = "#{ENV['JAVA_HOME']}#{File::PATH_SEPARATOR}#{path}"
end
end

ENV['PATH'] = "6960-extra_path#{File::PATH_SEPARATOR}#{path}"
Open3.popen3("java -version") do |i, o, e, t|
out = e.read || ''
out = o.read if out.strip.empty?
puts out.inspect
assert_match(/java|openjdk/i, out)
assert_equal(t.value, 0)
end
ensure
FileUtils.rm_rf 'extra_path'
FileUtils.rm_rf '6960-extra_path'
ENV['PATH'] = path
end