From 4af444183d98685a612d7be954e91a88306de2c1 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Sat, 2 Mar 2019 17:09:54 +0000 Subject: [PATCH] =?UTF-8?q?Improved:=20Rewrite=20=E2=80=98GroovyUtil#runSc?= =?UTF-8?q?riptAtLocation=E2=80=99=20(OFBIZ-10807)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ‘GroovyUtil#runScriptAtLocation’ method has now a javadoc and is rewritten as a simple ternary expression. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1854653 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/ofbiz/base/util/GroovyUtil.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java index e36ac545f4..77eac14dcf 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java @@ -192,15 +192,25 @@ public class GroovyUtil { return classLoader; } - public static Object runScriptAtLocation(String location, String methodName, Map context) throws GeneralException { + /** + * Runs a Groovy script with a context argument. + *

+ * A Groovy script can be either a stand-alone script or a method embedded in a script. + * + * @param location the location of the script file + * @param methodName the name of the method inside the script to be run, + * if it is {@code null} consider the script as stand-alone + * @param context the context of execution which is in the case + * of a method inside a script passed as an argument + * @return the invocation result + * @throws GeneralException when the script is not properly located + */ + public static Object runScriptAtLocation(String location, String methodName, Map context) + throws GeneralException { Script script = InvokerHelper.createScript(getScriptClassFromLocation(location), getBinding(context)); - Object result = null; - if (UtilValidate.isEmpty(methodName)) { - result = script.run(); - } else { - result = script.invokeMethod(methodName, new Object[] { context }); - } - return result; + return UtilValidate.isEmpty(methodName) + ? script.run() + : script.invokeMethod(methodName, new Object[] { context }); } private GroovyUtil() {}