Skip to content

Commit ec70db2

Browse files
committed
Merge branch 'simplify'
This branch switches the JRuby script language to lean on JRuby's built-in JSR-223 implementation, and fixes up the unit tests and templates to work as expected.
2 parents b96d319 + cccc731 commit ec70db2

File tree

5 files changed

+12
-304
lines changed

5 files changed

+12
-304
lines changed

src/main/java/org/scijava/plugins/scripting/jruby/JRubyBindings.java

Lines changed: 0 additions & 170 deletions
This file was deleted.

src/main/java/org/scijava/plugins/scripting/jruby/JRubyScriptEngine.java

Lines changed: 0 additions & 107 deletions
This file was deleted.

src/main/java/org/scijava/plugins/scripting/jruby/JRubyScriptLanguage.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/**
4141
* An adapter of the JRuby interpreter to the SciJava scripting interface.
4242
*
43-
* @author Johannes Schindelin
43+
* @author Curtis Rueden
4444
* @see ScriptEngine
4545
*/
4646
@Plugin(type = ScriptLanguage.class, name = "Ruby")
@@ -50,10 +50,4 @@ public JRubyScriptLanguage() {
5050
super("jruby");
5151
}
5252

53-
@Override
54-
public ScriptEngine getScriptEngine() {
55-
// TODO: Consider adapting the wrapped ScriptEngineFactory's ScriptEngine.
56-
return new JRubyScriptEngine();
57-
}
58-
5953
}

src/main/resources/script-templates/Ruby/Greeting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# the 'name' parameter from the user, and then display
77
# the 'greeting' output parameter, based on its type.
88

9-
greeting = "Hello, " + name + "!"
9+
$greeting = "Hello, " + $name + "!"

src/test/java/org/scijava/plugins/scripting/jruby/JRubyTest.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@
3636
import java.io.IOException;
3737
import java.util.concurrent.ExecutionException;
3838

39-
import javax.script.Bindings;
40-
import javax.script.ScriptContext;
4139
import javax.script.ScriptEngine;
4240
import javax.script.ScriptException;
4341

4442
import org.junit.Test;
4543
import org.scijava.Context;
46-
import org.scijava.plugins.scripting.jruby.JRubyScriptEngine;
4744
import org.scijava.script.ScriptLanguage;
4845
import org.scijava.script.ScriptModule;
4946
import org.scijava.script.ScriptService;
@@ -63,10 +60,8 @@ public void testBasic() throws InterruptedException, ExecutionException,
6360
final ScriptService scriptService = context.getService(ScriptService.class);
6461
final String script = "$x = 1 + 2;";
6562
final ScriptModule m = scriptService.run("add.rb", script, true).get();
66-
final ScriptEngine engine = (ScriptEngine) m.getReturnValue();
67-
final Object result = engine.get("$x");
68-
// NB: Result is of type org.jruby.RubyFixnum.
69-
assertEquals("3", result.toString());
63+
final Object result = m.getReturnValue();
64+
assertEquals(3L, result);
7065
}
7166

7267
@Test
@@ -76,18 +71,14 @@ public void testLocals() throws ScriptException {
7671

7772
final ScriptLanguage language = scriptService.getLanguageByExtension("rb");
7873
final ScriptEngine engine = language.getScriptEngine();
79-
assertEquals(JRubyScriptEngine.class, engine.getClass());
80-
engine.put("$hello", 17);
81-
assertEquals("17", engine.eval("$hello").toString());
82-
assertEquals("17", engine.get("$hello").toString());
83-
84-
final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
85-
bindings.clear();
86-
assertEquals("", engine.get("$hello").toString());
74+
final String engineClassName = engine.getClass().getName();
75+
assertEquals("org.jruby.embed.jsr223.JRubyEngine", engineClassName);
76+
engine.put("hello", 17);
77+
assertEquals(17L, engine.eval("$hello"));
78+
assertEquals(17, engine.get("hello"));
8779
}
8880

89-
// FIXME: This test currently fails due to input injection failure.
90-
// @Test
81+
@Test
9182
public void testParameters() throws InterruptedException, ExecutionException,
9283
IOException, ScriptException
9384
{
@@ -97,12 +88,12 @@ public void testParameters() throws InterruptedException, ExecutionException,
9788
final String script = "" + //
9889
"# @ScriptService ss\n" + //
9990
"# @OUTPUT String language\n" + //
100-
"language = ss.getLanguageByName(\"Ruby\").getLanguageName\n";
91+
"$language = $ss.getLanguageByName(\"ruby\").getLanguageName\n";
10192
final ScriptModule m = scriptService.run("hello.rb", script, true).get();
10293

10394
final Object actual = m.getOutput("language");
10495
final String expected =
105-
scriptService.getLanguageByName("Ruby").getLanguageName();
96+
scriptService.getLanguageByName("ruby").getLanguageName();
10697
assertEquals(expected, actual);
10798

10899
final Object result = m.getReturnValue();

0 commit comments

Comments
 (0)