svn commit: r1854653 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1854653 - /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java

mthl
Author: mthl
Date: Sat Mar  2 17:09:54 2019
New Revision: 1854653

URL: http://svn.apache.org/viewvc?rev=1854653&view=rev
Log:
Improved: Rewrite ‘GroovyUtil#runScriptAtLocation’ (OFBIZ-10807)

The ‘GroovyUtil#runScriptAtLocation’ method has now a javadoc and is
rewritten as a simple ternary expression.

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java?rev=1854653&r1=1854652&r2=1854653&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/GroovyUtil.java Sat Mar  2 17:09:54 2019
@@ -192,15 +192,25 @@ public class GroovyUtil {
         return classLoader;
     }
 
-    public static Object runScriptAtLocation(String location, String methodName, Map<String, Object> context) throws GeneralException {
+    /**
+     * Runs a Groovy script with a context argument.
+     * <p>
+     * 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<String, Object> 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() {}