[java-support] branch master updated: Clean up class constructors, fill some gaps.

Scott Cantor cantor.2 at osu.edu
Wed Oct 16 10:58:45 EDT 2019


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch master
in repository java-support.

View the commit online:
http://git.shibboleth.net/view/?p=java-support.git;a=commit;h=874f7972d4eed9a8620986936c85745c7ff5d93a

The following commit(s) were added to refs/heads/master by this push:
       new  874f797   Clean up class constructors, fill some gaps.
874f797 is described below

commit 874f7972d4eed9a8620986936c85745c7ff5d93a
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Oct 16 10:58:14 2019 -0400

    Clean up class constructors, fill some gaps.
---
 .../java/support/scripting/EvaluableScript.java    | 89 ++++++++++++++++++++--
 1 file changed, 83 insertions(+), 6 deletions(-)

diff --git a/src/main/java/net/shibboleth/utilities/java/support/scripting/EvaluableScript.java b/src/main/java/net/shibboleth/utilities/java/support/scripting/EvaluableScript.java
index 2f68a2a..0c644a4 100644
--- a/src/main/java/net/shibboleth/utilities/java/support/scripting/EvaluableScript.java
+++ b/src/main/java/net/shibboleth/utilities/java/support/scripting/EvaluableScript.java
@@ -32,9 +32,11 @@ import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
 
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
 import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
+import net.shibboleth.utilities.java.support.resource.Resource;
 
 import com.google.common.io.Files;
 
@@ -61,7 +63,8 @@ public class EvaluableScript {
      * 
      * @throws ScriptException thrown if the scripting engine supports compilation and the script does not compile
      */
-    public EvaluableScript(@Nonnull @NotEmpty final String engineName, @Nonnull @NotEmpty final String scriptSource)
+    public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty final String engineName,
+            @ParameterName(name="scriptSource") @Nonnull @NotEmpty final String scriptSource)
             throws ScriptException {
         scriptLanguage =
                 Constraint.isNotNull(StringSupport.trimOrNull(engineName),
@@ -78,22 +81,64 @@ public class EvaluableScript {
      * 
      * @throws ScriptException thrown if the scripting engine supports compilation and the script does not compile
      */
-    public EvaluableScript(@Nonnull @NotEmpty final String scriptSource) throws ScriptException {
+    public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull @NotEmpty final String scriptSource)
+            throws ScriptException {
         this("javascript", scriptSource);
     }
 
     /**
-     * Constructor. The provided stream is <strong>not</strong> closed.
+     * Constructor.
      * 
      * @param engineName the JSR-223 scripting engine name
      * @param scriptSource the script source
      * 
      * @throws ScriptException thrown if the script source file can not be read or the scripting engine supports
      *             compilation and the script does not compile
+     *             
+     * @since 8.0.0
+     */
+    public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty final String engineName,
+            @ParameterName(name="scriptSource") @Nonnull final Resource scriptSource)
+            throws ScriptException {
+        scriptLanguage = Constraint.isNotNull(StringSupport.trimOrNull(engineName),
+                "Scripting language can not be null or empty");
+        
+        try (final InputStream in =
+                Constraint.isNotNull(scriptSource, "Script source can not be null or empty").getInputStream()) {
+            script = StringSupport.inputStreamToString(in, null);
+        } catch (final IOException e) {
+            throw new ScriptException(e);
+        }
+
+        initialize();
+    }
+
+    /**
+     * Constructor.
      * 
+     * @param scriptSource the script source
      * 
+     * @throws ScriptException thrown if the script source file can not be read or the scripting engine supports
+     *             compilation and the script does not compile
+     *             
+     * @since 8.0.0
      */
-    public EvaluableScript(@Nonnull @NotEmpty final String engineName, @Nonnull final InputStream scriptSource)
+    public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull final Resource scriptSource)
+            throws ScriptException {
+        this("javascript", scriptSource);
+    }
+    
+    /**
+     * Constructor. The provided stream is <strong>not</strong> closed.
+     * 
+     * @param engineName the JSR-223 scripting engine name
+     * @param scriptSource the script source
+     * 
+     * @throws ScriptException thrown if the script source file can not be read or the scripting engine supports
+     *             compilation and the script does not compile
+     */
+    public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty final String engineName,
+            @ParameterName(name="scriptSource") @Nonnull final InputStream scriptSource)
             throws ScriptException {
         scriptLanguage =
                 Constraint.isNotNull(StringSupport.trimOrNull(engineName),
@@ -107,6 +152,21 @@ public class EvaluableScript {
 
         initialize();
     }
+    
+    /**
+     * Constructor. The provided stream is <strong>not</strong> closed.
+     * 
+     * @param scriptSource the script source
+     * 
+     * @throws ScriptException thrown if the script source file can not be read or the scripting engine supports
+     *             compilation and the script does not compile
+     * 
+     * @since 8.0.0
+     */
+    public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull final InputStream scriptSource)
+            throws ScriptException {
+        this("javascript", scriptSource);
+    }
 
     /**
      * Constructor.
@@ -117,7 +177,8 @@ public class EvaluableScript {
      * @throws ScriptException thrown if the script source file can not be read or the scripting engine supports
      *             compilation and the script does not compile
      */
-    public EvaluableScript(@Nonnull @NotEmpty final String engineName, @Nonnull final File scriptSource)
+    public EvaluableScript(@ParameterName(name="engineName") @Nonnull @NotEmpty final String engineName,
+            @ParameterName(name="scriptSource") @Nonnull final File scriptSource)
             throws ScriptException {
         scriptLanguage =
                 Constraint.isNotNull(StringSupport.trimOrNull(engineName),
@@ -145,7 +206,22 @@ public class EvaluableScript {
 
         initialize();
     }
-
+    
+    /**
+     * Constructor.
+     * 
+     * @param scriptSource the script source
+     * 
+     * @throws ScriptException thrown if the script source file can not be read or the scripting engine supports
+     *             compilation and the script does not compile
+     *             
+     * @since 8.0.0
+     */
+    public EvaluableScript(@ParameterName(name="scriptSource") @Nonnull final File scriptSource)
+            throws ScriptException {
+        this("javascript", scriptSource);
+    }
+    
     /**
      * Gets the script source.
      * 
@@ -212,4 +288,5 @@ public class EvaluableScript {
             compiledScript = null;
         }
     }
+    
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list