checkstyle Misc Rules
checkstyle Nesting checkstyle GenericWhitespace checkstyle MethodParamPad checkstyle NoWhiteSpace checkstyle ParenPad Script checkstyle ParenPad
This commit is contained in:
committed by
Artem Bilan
parent
05cc7be644
commit
57f96bb759
@@ -22,18 +22,21 @@ import javax.script.ScriptEngine;
|
||||
import org.springframework.integration.scripting.ScriptExecutor;
|
||||
|
||||
/**
|
||||
* A {@link ScriptExecutor} that implements special handling required for Python to emulate behavior similar to other JSR223 scripting languages.
|
||||
* A {@link ScriptExecutor} that implements special handling required for Python to
|
||||
* emulate behavior similar to other JSR223 scripting languages.
|
||||
* <p>
|
||||
* Script evaluation using the Jython implementation results in a <code>null</code> return value for normal variable expressions such as
|
||||
* <code>x=2</code>. As a work around, it is necessary to get the value of 'x' explicitly following the script evaluation. This class performs
|
||||
* simple parsing on the last line of the script to obtain the variable name, if any, and return its value.
|
||||
* Script evaluation using the Jython implementation results in a <code>null</code> return
|
||||
* value for normal variable expressions such as <code>x=2</code>. As a work around, it is
|
||||
* necessary to get the value of 'x' explicitly following the script evaluation. This
|
||||
* class performs simple parsing on the last line of the script to obtain the variable
|
||||
* name, if any, and return its value.
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author Gary Russell
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
public class PythonScriptExecutor extends AbstractScriptExecutor {
|
||||
public class PythonScriptExecutor extends AbstractScriptExecutor {
|
||||
|
||||
public PythonScriptExecutor() {
|
||||
super("python");
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
public class RubyScriptExecutor extends DefaultScriptExecutor {
|
||||
public class RubyScriptExecutor extends DefaultScriptExecutor {
|
||||
|
||||
static {
|
||||
if (ClassUtils.isPresent("org.jruby.embed.jsr223.JRubyEngine", System.class.getClassLoader())) {
|
||||
|
||||
@@ -43,8 +43,8 @@ public class DeriveLanguageFromExtensionTests {
|
||||
|
||||
@Test
|
||||
public void testParseLanguage() {
|
||||
String langs[] = { "ruby", "Groovy", "ECMAScript", "python" };
|
||||
Class<?> executors[] = {
|
||||
String[] langs = { "ruby", "Groovy", "ECMAScript", "python" };
|
||||
Class<?>[] executors = {
|
||||
RubyScriptExecutor.class,
|
||||
DefaultScriptExecutor.class,
|
||||
DefaultScriptExecutor.class,
|
||||
@@ -71,7 +71,8 @@ public class DeriveLanguageFromExtensionTests {
|
||||
@Test
|
||||
public void testBadExtension() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail1-context.xml", this.getClass());
|
||||
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail1-context.xml", this.getClass())
|
||||
.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue(e.getMessage().contains("No suitable scripting engine found for extension 'xx'"));
|
||||
@@ -81,7 +82,8 @@ public class DeriveLanguageFromExtensionTests {
|
||||
@Test
|
||||
public void testNoExtension() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail2-context.xml", this.getClass());
|
||||
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail2-context.xml", this.getClass())
|
||||
.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertTrue(e.getMessage().contains("Unable to determine language for script 'foo'"));
|
||||
|
||||
@@ -46,23 +46,23 @@ public class PythonScriptExecutorTests {
|
||||
|
||||
@Test
|
||||
public void testLiteral() {
|
||||
Object obj = executor.executeScript(new StaticScriptSource("3+4") );
|
||||
Object obj = executor.executeScript(new StaticScriptSource("3+4"));
|
||||
assertEquals(7, obj);
|
||||
|
||||
obj = executor.executeScript(new StaticScriptSource("'hello,world'") );
|
||||
obj = executor.executeScript(new StaticScriptSource("'hello,world'"));
|
||||
assertEquals("hello,world", obj);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
public void test1() {
|
||||
Object obj = executor.executeScript(new StaticScriptSource("x=2") );
|
||||
Object obj = executor.executeScript(new StaticScriptSource("x=2"));
|
||||
assertEquals(2, obj);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
Object obj = executor.executeScript(new StaticScriptSource("def foo(y):\n\tx=y\n\treturn y\nz=foo(2)") );
|
||||
Object obj = executor.executeScript(new StaticScriptSource("def foo(y):\n\tx=y\n\treturn y\nz=foo(2)"));
|
||||
assertEquals(2, obj);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user