Skip to content

Commit 22d3272

Browse files
committed
updated for JRuby 1.1
1 parent 51577b2 commit 22d3272

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

org.springframework.context/src/main/java/org/springframework/scripting/jruby/JRubyScriptUtils.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.jruby.exceptions.JumpException;
3535
import org.jruby.exceptions.RaiseException;
3636
import org.jruby.javasupport.JavaEmbedUtils;
37-
import org.jruby.runtime.DynamicScope;
3837
import org.jruby.runtime.builtin.IRubyObject;
3938

4039
import org.springframework.core.NestedRuntimeException;
@@ -46,8 +45,7 @@
4645
/**
4746
* Utility methods for handling JRuby-scripted objects.
4847
*
49-
* <p>As of Spring 2.5, this class supports JRuby 0.9.9, 0.9.9 and 1.0.x.
50-
* <b>Note that there is no support for JRuby 1.1 at this point!</b>
48+
* <p>As of Spring 3.0, this class requires JRuby 1.1 or higher.
5149
*
5250
* @author Rob Harrop
5351
* @author Juergen Hoeller
@@ -56,11 +54,6 @@
5654
*/
5755
public abstract class JRubyScriptUtils {
5856

59-
// Determine whether the old JRuby 0.9 parse method is available (incompatible with 1.0)
60-
private final static Method oldParseMethod = ClassUtils.getMethodIfAvailable(
61-
Ruby.class, "parse", new Class[] {String.class, String.class, DynamicScope.class});
62-
63-
6457
/**
6558
* Create a new JRuby-scripted object from the given script source,
6659
* using the default {@link ClassLoader}.
@@ -85,23 +78,12 @@ public static Object createJRubyObject(String scriptSource, Class[] interfaces)
8578
public static Object createJRubyObject(String scriptSource, Class[] interfaces, ClassLoader classLoader) {
8679
Ruby ruby = initializeRuntime();
8780

88-
Node scriptRootNode = null;
89-
/* TODO: make this JRuby 1.1 compliant
90-
91-
Node scriptRootNode = (oldParseMethod != null ?
92-
(Node) ReflectionUtils.invokeMethod(oldParseMethod, ruby, new Object[] {scriptSource, "", null}) :
93-
ruby.parse(scriptSource, "", null, 0));
94-
*/
95-
IRubyObject rubyObject = null;
96-
/** TODO: make this JRuby 1.1 compliant
97-
IRubyObject rubyObject = ruby.eval(scriptRootNode);
98-
*/
81+
Node scriptRootNode = ruby.parseEval(scriptSource, "", null, 0);
82+
IRubyObject rubyObject = ruby.runNormally(scriptRootNode, false);
9983

10084
if (rubyObject instanceof RubyNil) {
10185
String className = findClassName(scriptRootNode);
102-
/** TODO: make this JRuby 1.1 compliant
103-
rubyObject = ruby.evalScript("\n" + className + ".new");
104-
*/
86+
rubyObject = ruby.evalScriptlet("\n" + className + ".new");
10587
}
10688
// still null?
10789
if (rubyObject instanceof RubyNil) {
@@ -141,21 +123,20 @@ private static ClassNode findClassNode(Node node) {
141123
if (node instanceof ClassNode) {
142124
return (ClassNode) node;
143125
}
144-
List children = node.childNodes();
145-
for (int i = 0; i < children.size(); i++) {
146-
Node child = (Node) children.get(i);
126+
List<Node> children = node.childNodes();
127+
for (Node child : children) {
147128
if (child instanceof ClassNode) {
148129
return (ClassNode) child;
149-
} else if (child instanceof NewlineNode) {
130+
}
131+
else if (child instanceof NewlineNode) {
150132
NewlineNode nn = (NewlineNode) child;
151133
Node found = findClassNode(nn.getNextNode());
152134
if (found instanceof ClassNode) {
153135
return (ClassNode) found;
154136
}
155137
}
156138
}
157-
for (int i = 0; i < children.size(); i++) {
158-
Node child = (Node) children.get(i);
139+
for (Node child : children) {
159140
Node found = findClassNode(child);
160141
if (found instanceof ClassNode) {
161142
return (ClassNode) found;
@@ -184,7 +165,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
184165
return (isProxyForSameRubyObject(args[0]) ? Boolean.TRUE : Boolean.FALSE);
185166
}
186167
else if (ReflectionUtils.isHashCodeMethod(method)) {
187-
return new Integer(this.rubyObject.hashCode());
168+
return this.rubyObject.hashCode();
188169
}
189170
else if (ReflectionUtils.isToStringMethod(method)) {
190171
String toStringResult = this.rubyObject.toString();

0 commit comments

Comments
 (0)