Skip to content

Commit

Permalink
Showing 4 changed files with 42 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bin/jruby.bash
Original file line number Diff line number Diff line change
@@ -180,6 +180,12 @@ fi
# ----- Execute The Requested Command -----------------------------------------
JAVA_ENCODING=""

if [ -e "/dev/urandom" ]; then
# OpenJDK tries really hard to prevent you from using urandom.
# See https://bugs.openjdk.java.net/browse/JDK-6202721
JAVA_SECURITY_EGD="/dev/./urandom"
fi

declare -a java_args
declare -a ruby_args
mode=""
@@ -219,21 +225,13 @@ do
CP="$CP$CP_DELIMITER$2"
CLASSPATH=""
shift
elif [ "${val:0:3}" = "-G:" ]; then # Graal options
opt=${val:3}
case $opt in
+*)
opt="${opt:1}=true" ;;
-*)
opt="${opt:1}=false" ;;
esac
echo "$1 is deprecated - use -J-Dgraal.$opt instead" >&2
java_args=("${java_args[@]}" "-Dgraal.$opt")
else
if [ "${val:0:3}" = "-ea" ]; then
VERIFY_JRUBY="yes"
elif [ "${val:0:16}" = "-Dfile.encoding=" ]; then
JAVA_ENCODING=$val
elif [ "${val:0:20}" = "-Djava.security.egd=" ]; then
JAVA_SECURITY_EGD=$val
fi
java_args=("${java_args[@]}" "${1:2}")
fi
@@ -315,6 +313,12 @@ if [[ $darwin && -z "$JAVA_ENCODING" ]]; then
java_args=("${java_args[@]}" "-Dfile.encoding=UTF-8")
fi

# Force OpenJDK-based JVMs to use /dev/urandom for random number generation
# See https://github.com/jruby/jruby/issues/4685 among others.
if [[ -n "$JAVA_SECURITY_EGD" ]]; then
java_args=("${java_args[@]}" "-Djava.security.egd=$JAVA_SECURITY_EGD")
fi

# Append the rest of the arguments
ruby_args=("${ruby_args[@]}" "$@")

7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/javasupport/ext/JavaLang.java
Original file line number Diff line number Diff line change
@@ -70,6 +70,13 @@ public static void define(final Ruby runtime) {
final RubyModule byteArray = Java.getProxyClass(runtime, new byte[0].getClass());
byteArray.addMethod("ubyte_get", new UByteGet(byteArray));
byteArray.addMethod("ubyte_set", new UByteSet(byteArray));

final RubyModule String = Java.getProxyClass(runtime, java.lang.String.class);
String.defineAlias("to_str", "to_s");

final RubyModule Number = Java.getProxyClass(runtime, java.lang.Number.class);
Number.defineAlias("to_int", "longValue");
Number.defineAlias("to_f", "doubleValue");
}

@JRubyModule(name = "Java::JavaLang::Iterable", include = "Enumerable")
13 changes: 13 additions & 0 deletions spec/java_integration/addons/number_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require File.dirname(__FILE__) + "/../spec_helper"

describe "java.lang.Number subtypes" do
describe "passed to numeric-coercing methods" do
it "coerces successfully" do
expect([42][0.to_java]).to eq 42

m = Mutex.new
m.lock
m.sleep(0.01.to_java)
end
end
end
8 changes: 8 additions & 0 deletions spec/java_integration/addons/string_spec.rb
Original file line number Diff line number Diff line change
@@ -6,3 +6,11 @@
expect(wrapped.class).to eq java.lang.String
end
end

describe "java.lang.String" do
describe "passed to a String-coercing method" do
it "coerces successfully" do
expect("foo".concat("bar".to_java)).to eq "foobar"
end
end
end

0 comments on commit 26dcd8a

Please sign in to comment.