You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by sg...@apache.org on 2015/08/22 10:16:00 UTC

svn commit: r1697080 - in /turbine/fulcrum/trunk: resourcemanager/ script/ script/src/java/org/apache/fulcrum/script/ script/src/java/org/apache/fulcrum/script/impl/ script/src/test/ script/src/test/org/apache/fulcrum/script/ script/src/test/scripts/gr...

Author: sgoeschl
Date: Sat Aug 22 08:15:59 2015
New Revision: 1697080

URL: http://svn.apache.org/r1697080
Log:
Updating the "fulcrum-script" component.

Added:
    turbine/fulcrum/trunk/script/pom.xml
    turbine/fulcrum/trunk/script/src/test/scripts/js/Shutdown.js
    turbine/fulcrum/trunk/script/src/test/scripts/js/Startup.js
Modified:
    turbine/fulcrum/trunk/resourcemanager/pom.xml
    turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/ScriptService.java
    turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptBaseService.java
    turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptEngineEntry.java
    turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptRunnableImpl.java
    turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptServiceImpl.java
    turbine/fulcrum/trunk/script/src/test/TestGroovyComponentConfig.xml
    turbine/fulcrum/trunk/script/src/test/TestRhinoComponentConfig.xml
    turbine/fulcrum/trunk/script/src/test/TestRoleConfig.xml
    turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/AbstractScriptTest.java
    turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/GroovyTest.java
    turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/RhinoTest.java
    turbine/fulcrum/trunk/script/src/test/scripts/groovy/Avalon.groovy
    turbine/fulcrum/trunk/script/src/test/scripts/groovy/NamespaceDemo3.groovy
    turbine/fulcrum/trunk/script/src/test/scripts/groovy/RuntimeError.groovy
    turbine/fulcrum/trunk/script/src/test/scripts/js/Avalon.js
    turbine/fulcrum/trunk/script/src/test/scripts/js/NamespaceDemo3.js
    turbine/fulcrum/trunk/script/src/test/scripts/js/RuntimeError.js
    turbine/fulcrum/trunk/script/src/test/scripts/js/locator/bar/foo.js
    turbine/fulcrum/trunk/script/src/test/scripts/js/locator/foo.js

Modified: turbine/fulcrum/trunk/resourcemanager/pom.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/resourcemanager/pom.xml?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/resourcemanager/pom.xml (original)
+++ turbine/fulcrum/trunk/resourcemanager/pom.xml Sat Aug 22 08:15:59 2015
@@ -7,6 +7,7 @@
     </parent>
 
     <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.fulcrum</groupId>
     <artifactId>fulcrum-resourcemanager</artifactId>
     <version>1.0.2-SNAPSHOT</version>
     <name>Fulcrum ResourceManager</name>

Added: turbine/fulcrum/trunk/script/pom.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/pom.xml?rev=1697080&view=auto
==============================================================================
--- turbine/fulcrum/trunk/script/pom.xml (added)
+++ turbine/fulcrum/trunk/script/pom.xml Sat Aug 22 08:15:59 2015
@@ -0,0 +1,103 @@
+<?xml version="1.0"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <artifactId>turbine-parent</artifactId>
+       <groupId>org.apache.turbine</groupId>
+       <version>3</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.fulcrum</groupId>
+  <artifactId>fulcrum-script</artifactId>
+  <version>1.0.1-SNAPSHOT</version>
+  <name>Fulcrum Script Component</name>
+  <inceptionYear>2004</inceptionYear>
+  <description>A JSR 223 scripting Avalon component</description>
+  <url>http://turbine.apache.org/fulcrum/fulcrum-script</url>
+		
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/turbine/fulcrum/trunk/script</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/turbine/fulcrum/trunk/script</developerConnection>
+    <url>http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script</url>
+  </scm>
+
+  <distributionManagement>
+    <site>
+      <id>apache.website</id>
+      <name>Fulcrum Website</name>
+      <url>http://turbine.apache.org/fulcrum/fulcrum-script/</url>
+    </site>    
+  </distributionManagement>
+	
+  <developers>
+    <developer>
+      <name>Siegfried Goeschl</name>
+      <id>sgoeschl</id>
+      <email>sgoeschl@apache.org</email>
+      <organization />
+      <roles>
+        <role>Java Developer</role>
+      </roles>
+    </developer>
+  </developers>
+
+  <dependencies>
+        <dependency>
+            <groupId>org.apache.fulcrum</groupId>
+            <artifactId>fulcrum-resourcemanager</artifactId>
+            <version>1.0.2-SNAPSHOT</version>
+        </dependency>
+        <!-- Testing dependencies -->
+        <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy-all</artifactId>
+            <version>2.4.4</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy-jsr223</artifactId>
+            <version>2.4.4</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.fulcrum</groupId>
+            <artifactId>fulcrum-testcontainer</artifactId>
+            <version>1.0.6</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.fulcrum</groupId>
+            <artifactId>fulcrum-yaafi</artifactId>
+            <version>1.0.6</version>
+            <scope>test</scope>
+        </dependency>    
+  </dependencies>
+
+  <build>
+    <sourceDirectory>${basedir}/src/java</sourceDirectory>
+    <testSourceDirectory>${basedir}/src/test</testSourceDirectory>
+  </build>
+ 
+
+  <properties>
+    <turbine.site.path>fulcrum/fulcrum-script</turbine.site.path>
+  </properties>
+	
+</project>
\ No newline at end of file

Modified: turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/ScriptService.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/ScriptService.java?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/ScriptService.java (original)
+++ turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/ScriptService.java Sat Aug 22 08:15:59 2015
@@ -19,12 +19,12 @@ package org.apache.fulcrum.script;
  * under the License.
  */
 
+import java.io.IOException;
 import javax.script.Bindings;
 import javax.script.ScriptContext;
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
-import java.io.IOException;
 
 /**
  * An Avalon service to execute scripts based on JSR-223.
@@ -49,7 +49,7 @@ public interface ScriptService
      * @param scriptName the name of the script
      * @return true if the script exists
      */
-    boolean exists( String scriptName );
+    boolean exists(String scriptName);
 
     /**
      * Executes the specified script. The default ScriptContext
@@ -60,7 +60,7 @@ public interface ScriptService
      * @throws IOException loading the script failed
      * @throws ScriptException if an error occurrs during script execution.
      */
-    Object eval( String scriptName ) throws IOException, ScriptException;
+    Object eval(String scriptName) throws IOException, ScriptException;
 
     /**
      * Executes the script using the Namespace argument
@@ -71,9 +71,9 @@ public interface ScriptService
      * @param bindings The binding of attributes
      * @return result from the executed script
      * @throws IOException loading the script failed
-     * @throws ScriptException if an error occurrs during script execution.
+     * @throws ScriptException if an error occurs during script execution.
      */
-    Object eval( String scriptName, Bindings bindings ) throws IOException, ScriptException;
+    Object eval(String scriptName, Bindings bindings) throws IOException, ScriptException;
 
     /**
      * Causes the immediate execution of the script. State left in the engine
@@ -85,9 +85,9 @@ public interface ScriptService
      * @param context The ScriptContext passed to the script engine.
      * @return result from the executed script
      * @throws IOException loading the script failed
-     * @throws ScriptException if an error occurrs during script execution.
+     * @throws ScriptException if an error occurs during script execution.
      */
-    Object eval( String scriptName, ScriptContext context ) throws IOException, ScriptException;
+    Object eval(String scriptName, ScriptContext context) throws IOException, ScriptException;
 
     /**
      * Calls a procedure compiled during a previous script execution,
@@ -99,7 +99,7 @@ public interface ScriptService
      * @throws ScriptException if an error occurrs during script execution
      * @throws NoSuchMethodException If method with given name or matching argument types cannot be found.
      */
-    Object call( String name, Object[] args ) throws ScriptException, NoSuchMethodException;
+    Object call(String name, Object[] args) throws ScriptException, NoSuchMethodException;
 
     /**
      * Return an object implementing the given interface. It
@@ -111,5 +111,5 @@ public interface ScriptService
      * @param clazz the interface to implement
      * @return an scripted object implementing the given interface.
      */
-    Object getInterface( Class clazz );
+    Object getInterface(Class clazz);
 }

Modified: turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptBaseService.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptBaseService.java?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptBaseService.java (original)
+++ turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptBaseService.java Sat Aug 22 08:15:59 2015
@@ -55,16 +55,16 @@ public abstract class ScriptBaseService
     /** context key for temporary directory */
     private final static String URN_AVALON_TEMP = "impl.workDir";
 
-    /** The context supplied by the avalon framework */
+    /** The context supplied by the Avalon framework */
     private Context context;
 
-    /** The service manager supplied by the avalon framework */
+    /** The service manager supplied by the Avalon framework */
     private ServiceManager serviceManager;
 
-    /** The configuraton supplied by the avalon framework */
+    /** The configuration supplied by the Avalon framework */
     private Configuration configuration;
 
-    /** The parameters supplied by the avalon framework */
+    /** The parameters supplied by the Avalon framework */
     private Parameters parameters;
 
     /** the Avalon application directory */
@@ -86,9 +86,9 @@ public abstract class ScriptBaseService
      */
     public void contextualize(Context context) throws ContextException
     {
-        this.context        = context;
+        this.context = context;
         this.applicationDir = (File) context.get(URN_AVALON_HOME);
-        this.tempDir        = (File) context.get(URN_AVALON_TEMP);
+        this.tempDir = (File) context.get(URN_AVALON_TEMP);
     }
 
     /**

Modified: turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptEngineEntry.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptEngineEntry.java?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptEngineEntry.java (original)
+++ turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptEngineEntry.java Sat Aug 22 08:15:59 2015
@@ -20,8 +20,9 @@ package org.apache.fulcrum.script.impl;
  */
 
 import java.util.List;
-
+import javax.script.Bindings;
 import javax.script.ScriptEngine;
+import javax.script.SimpleBindings;
 
 /**
  * An entry of the script engine.
@@ -49,7 +50,16 @@ public class ScriptEngineEntry
     private ScriptEngine scriptEngine;
 
     /** a list of scripts to execute during initialization */
-    private List scriptList;
+    private List preLoadedScripts;
+
+    /** a list of scripts to execute during startup */
+    private List startupScripts;
+
+    /** a list of scripts to execute during shutdown */
+    private List shutdownScripts;
+
+    /** the script engine bindings after executing the pre-loaded scripts */
+    private Bindings defaultBindings;
 
     /**
      * Constructor
@@ -80,6 +90,7 @@ public class ScriptEngineEntry
         this.isCompiled = isCompiled;
         this.location = location;
         this.scriptEngine = scriptEngine;
+        this.defaultBindings = new SimpleBindings();
     }
 
     /**
@@ -117,7 +128,8 @@ public class ScriptEngineEntry
     /**
      * @return Returns the script extension
      */
-    public String getExtension() {
+    public String getExtension()
+    {
         return extension;
     }
 
@@ -130,19 +142,51 @@ public class ScriptEngineEntry
     }
 
     /**
-     * @return Returns the scriptList.
+     * @return Returns the pre-loaded scripts.
      */
-    public List getScriptList()
+    public List getPreLoadedScripts()
     {
-        return scriptList;
+        return preLoadedScripts;
     }
 
     /**
-     * @param scriptList The scriptList to set.
+     * @param scriptList The list of pre-loaded scripts
      */
-    public void setScriptList(List scriptList)
+    public void setPreloadScripts(List scriptList)
+    {
+        Validate.notNull(scriptList, "preLoadedScripts");
+        this.preLoadedScripts = scriptList;
+    }
+
+    public List getStartupScripts()
+    {
+        return startupScripts;
+    }
+
+    public void setStartupScripts(List startupScripts)
+    {
+        Validate.notNull(startupScripts, "startupScripts");
+        this.startupScripts = startupScripts;
+    }
+
+    public List getShutdownScripts()
+    {
+        return shutdownScripts;
+    }
+
+    public void setShutdownScripts(List shutdownScripts)
+    {
+        Validate.notNull(shutdownScripts, "shutdownScripts");
+        this.shutdownScripts = shutdownScripts;
+    }
+
+    public Bindings getDefaultBindings()
+    {
+        return defaultBindings;
+    }
+
+    public void setDefaultBindings(Bindings defaultBindings)
     {
-        Validate.notNull(scriptList, "scriptList");
-        this.scriptList = scriptList;
+        this.defaultBindings = defaultBindings;
     }
 }

Modified: turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptRunnableImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptRunnableImpl.java?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptRunnableImpl.java (original)
+++ turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptRunnableImpl.java Sat Aug 22 08:15:59 2015
@@ -45,7 +45,7 @@ public class ScriptRunnableImpl implemen
     /** the result of the execution */
     private Object result;
 
-    /** the execption thrown by the scipt if any */
+    /** the exception thrown by the script if any */
     private Exception exception;
 
     /**

Modified: turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptServiceImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptServiceImpl.java?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptServiceImpl.java (original)
+++ turbine/fulcrum/trunk/script/src/java/org/apache/fulcrum/script/impl/ScriptServiceImpl.java Sat Aug 22 08:15:59 2015
@@ -34,6 +34,7 @@ import javax.script.ScriptContext;
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
+import javax.script.SimpleBindings;
 
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.activity.Initializable;
@@ -64,7 +65,7 @@ public class ScriptServiceImpl
     /** the script manager */
     private ScriptEngineManager scriptEngineManager;
 
-    /** the mapof scripting engines to use */
+    /** the map of scripting engines to use */
     private HashMap scriptEngineMap;
 
     /** maps from a script name to a script */
@@ -136,10 +137,6 @@ public class ScriptServiceImpl
             this.getLogger().error(msg);
             throw new ConfigurationException(msg);
         }
-
-        // evaluate the scripts defined in the onLoad section
-
-        this.preloadScripts();
     }
 
     /**
@@ -149,6 +146,14 @@ public class ScriptServiceImpl
     {
         ScriptAvalonContext avalonContext = this.createScriptAvalonContext();
         this.scriptEngineManager.put("avalonContext", avalonContext);
+
+        // evaluate the scripts defined in the onLoad section
+
+        this.onPreloadScripts();
+
+        // execute the startup scripts
+
+        this.onStartupScripts();
     }
 
     /**
@@ -169,6 +174,10 @@ public class ScriptServiceImpl
      */
     public void dispose()
     {
+        // execute the shutdown scripts
+
+        this.onShutdownScripts();
+
         super.dispose();
         this.scriptCache.clear();
         this.scriptCache = null;
@@ -210,7 +219,7 @@ public class ScriptServiceImpl
 
     }
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.fulcrum.script.ScriptService#eval(java.lang.String, javax.script.ScriptContext)
      */
     public Object eval(String scriptName, ScriptContext context)
@@ -298,7 +307,7 @@ public class ScriptServiceImpl
      * @param args the arguments for the script method
      * @return a scripting object implementing the given interface
      * @throws ScriptException script execution failed
-     * @throws NoSuchMethodException the script method was nout found
+     * @throws NoSuchMethodException the script method was not found
      */
     private Object call(String engineName, String name, Object[] args)
     	throws ScriptException, NoSuchMethodException
@@ -354,8 +363,8 @@ public class ScriptServiceImpl
         ScriptEngineEntry scriptEngineEntry = this.getScriptEngineEntry(engineName);
         String location = scriptEngineEntry.getLocation();
 
-        String result = null;
-        byte[] scriptContent = null;
+        String result;
+        byte[] scriptContent;
         String[] scriptContext = {};
 
         scriptContent = this.getResourceManagerService().read(
@@ -372,15 +381,15 @@ public class ScriptServiceImpl
      * Creates a compiled script.
      *
      * @param engineName the script engine to use
-     * @param scriptName the name of the scipt to compile
-     * @param scriptContent the name  scipt to compile
+     * @param scriptName the name of the script to compile
+     * @param scriptContent the name  script to compile
      * @return the compiled script
      * @throws ScriptException failed to compile the script
      */
     private CompiledScript compileScript( String engineName, String scriptName, String scriptContent )
         throws ScriptException
     {
-        CompiledScript result = null;
+        CompiledScript result;
 
         try
         {
@@ -420,7 +429,7 @@ public class ScriptServiceImpl
     private Object doEval( ScriptCacheEntry scriptCacheEntry, Bindings binding, ScriptContext scriptContext )
         throws ScriptException
     {
-        Object result = null;
+        Object result;
         String scriptName = scriptCacheEntry.getScriptName();
         ScriptEngineEntry scriptEngineEntry = this.getScriptEngineEntry(scriptCacheEntry.getEngineName());
         ScriptEngine scriptEngine = scriptEngineEntry.getScriptEngine();
@@ -487,13 +496,13 @@ public class ScriptServiceImpl
      * @param name the name of the script method
      * @param args the script method parameters
      * @return the result of the script invocation
-     * @throws ScriptException if an error occurrs during invocation of the method.
+     * @throws ScriptException if an error occurs during invocation of the method.
      * @throws NoSuchMethodException if method with given name or matching argument types cannot be found.
      */
     private Object doCall( String engineName, String name, Object[] args )
     	throws ScriptException, NoSuchMethodException
     {
-        Object result = null;
+        Object result;
         ScriptEngineEntry scriptEngineEntry = this.getScriptEngineEntry(engineName);
         ScriptEngine scriptEngine = scriptEngineEntry.getScriptEngine();
         Invocable invocable = (Invocable) scriptEngine;
@@ -537,7 +546,7 @@ public class ScriptServiceImpl
      */
     private Object doGetInterface( String engineName, Class clazz )
     {
-        Object result = null;
+        Object result;
         ScriptEngineEntry scriptEngineEntry = this.getScriptEngineEntry(engineName);
         ScriptEngine scriptEngine = scriptEngineEntry.getScriptEngine();
         Invocable invocable = (Invocable) scriptEngine;
@@ -573,7 +582,7 @@ public class ScriptServiceImpl
      */
     private ScriptAvalonContext createScriptAvalonContext()
     {
-        ScriptAvalonContextImpl result = null;
+        ScriptAvalonContextImpl result;
 
         ScriptServiceManagerImpl scriptServiceManager = new ScriptServiceManagerImpl(
             this.getServiceManager(),
@@ -621,7 +630,7 @@ public class ScriptServiceImpl
         String engineName = this.getEngineName(scriptName);
         ScriptCacheEntry scriptCacheEntry = null;
         ScriptEngineEntry scriptEngineEntry = this.getScriptEngineEntry(engineName);
-        String plainScript = null;
+        String plainScript;
         CompiledScript compiledScript = null;
         boolean isInCache = false;
 
@@ -697,22 +706,44 @@ public class ScriptServiceImpl
 
         ScriptEngineEntry result = new ScriptEngineEntry(name, extension, isCached, isCompiled, location, scriptEngine);
 
-        // evaluate the given scripts
+        // collect the names of the 'pre-loaded' scripts
+
+        ArrayList preloadScripts = new ArrayList();
+        Configuration[] preloadScriptListConfiguration = configuration.getChild("preload").getChildren("script");
+        for( int i=0; i<preloadScriptListConfiguration.length; i++ )
+        {
+            preloadScripts.add(preloadScriptListConfiguration[i].getValue());
+        }
+
+        result.setPreloadScripts(preloadScripts);
 
-        ArrayList scriptList = new ArrayList();
-        Configuration[] scriptListConfiguration = configuration.getChild("preLoad").getChildren("script");
-        for( int i=0; i<scriptListConfiguration.length; i++ )
+        // collect the names of the 'startup' scripts
+
+        ArrayList startupScripts = new ArrayList();
+        Configuration[] startupScriptListConfiguration = configuration.getChild("startup").getChildren("script");
+        for( int i=0; i<startupScriptListConfiguration.length; i++ )
         {
-            scriptList.add(scriptListConfiguration[i].getValue());
+            startupScripts.add(startupScriptListConfiguration[i].getValue());
         }
 
-        result.setScriptList(scriptList);
+        result.setStartupScripts(startupScripts);
+
+        // collect the names of the 'shutdown' scripts
+
+        ArrayList shutdownScripts = new ArrayList();
+        Configuration[] shutdownScriptListConfiguration = configuration.getChild("shutdown").getChildren("script");
+        for( int i=0; i< shutdownScriptListConfiguration.length; i++ )
+        {
+            shutdownScripts.add(shutdownScriptListConfiguration[i].getValue());
+        }
+
+        result.setShutdownScripts(shutdownScripts);
 
         return result;
     }
 
     /**
-     * @param engineName the name of the scriptng engine
+     * @param engineName the name of the scripting engine
      * @return the ScriptEngineEntry
      */
     private ScriptEngineEntry getScriptEngineEntry( String engineName)
@@ -770,7 +801,7 @@ public class ScriptServiceImpl
             }
         }
 
-        throw new IllegalArgumentException("Unknow script extension : " + extension);
+        throw new IllegalArgumentException("Unknown script extension : " + extension);
     }
 
     /**
@@ -804,18 +835,21 @@ public class ScriptServiceImpl
     }
 
     /**
-     * Preload the scripts defined in the onLoad section
+     * Pre-load the scripts defined in the onLoad section.
      */
-    private void preloadScripts()
+    private void onPreloadScripts()
     {
+        getLogger().debug("Executing the pre-loaded scripts");
+
         Iterator iter = this.getScriptEngineMap().keySet().iterator();
 
         while( iter.hasNext() )
         {
+            Bindings scriptEngineDefaultBindings = new SimpleBindings();
             String engineName = (String) iter.next();
             ScriptEngineEntry scriptEngineEntry = this.getScriptEngineEntry(engineName);
             ScriptEngine scriptEngine = scriptEngineEntry.getScriptEngine();
-            Object[] scriptList = scriptEngineEntry.getScriptList().toArray();
+            Object[] scriptList = scriptEngineEntry.getPreLoadedScripts().toArray();
 
             for( int i=0; i<scriptList.length; i++ )
             {
@@ -825,6 +859,7 @@ public class ScriptServiceImpl
                 {
                     String plainScript = this.loadScript(engineName, scriptName);
                     scriptEngine.eval(plainScript);
+                    scriptEngineDefaultBindings.putAll(scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE));
                 }
                 catch (Exception e)
                 {
@@ -833,6 +868,78 @@ public class ScriptServiceImpl
                     throw new RuntimeException(msg);
                 }
             }
+
+            scriptEngineEntry.setDefaultBindings(scriptEngineDefaultBindings);
+        }
+    }
+
+    /**
+     * Execute the startup scripts
+     */
+    private void onStartupScripts()
+    {
+        getLogger().debug("Executing the startup scripts");
+
+        Iterator iter = this.getScriptEngineMap().keySet().iterator();
+
+        while( iter.hasNext() )
+        {
+            String engineName = (String) iter.next();
+            ScriptEngineEntry scriptEngineEntry = this.getScriptEngineEntry(engineName);
+            Object[] scriptList = scriptEngineEntry.getStartupScripts().toArray();
+
+            for( int i=0; i<scriptList.length; i++ )
+            {
+                String scriptName = scriptList[i].toString();
+
+                try
+                {
+                    this.eval(scriptName);
+                }
+                catch (Exception e)
+                {
+                    String msg = "Unable to execute the following startup script : " + scriptName;
+                    this.getLogger().error(msg, e);
+                    throw new RuntimeException(msg);
+                }
+            }
         }
+
+        getLogger().debug("Finished executing the startup scripts");
     }
+
+    /**
+     * Execute the shutdown scripts.
+     */
+    private void onShutdownScripts()
+    {
+        getLogger().debug("Executing the shutdown scripts");
+
+        Iterator iter = this.getScriptEngineMap().keySet().iterator();
+
+        while( iter.hasNext() )
+        {
+            String engineName = (String) iter.next();
+            ScriptEngineEntry scriptEngineEntry = this.getScriptEngineEntry(engineName);
+            Object[] scriptList = scriptEngineEntry.getShutdownScripts().toArray();
+
+            for( int i=0; i<scriptList.length; i++ )
+            {
+                String scriptName = scriptList[i].toString();
+
+                try
+                {
+                    this.eval(scriptName);
+                }
+                catch (Throwable t)
+                {
+                    String msg = "Unable to execute the following shutdown script : " + scriptName;
+                    this.getLogger().error(msg, t);
+                }
+            }
+        }
+
+        getLogger().debug("Finished executing the shutdown scripts");
+    }
+
 }

Modified: turbine/fulcrum/trunk/script/src/test/TestGroovyComponentConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/TestGroovyComponentConfig.xml?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/TestGroovyComponentConfig.xml (original)
+++ turbine/fulcrum/trunk/script/src/test/TestGroovyComponentConfig.xml Sat Aug 22 08:15:59 2015
@@ -20,49 +20,49 @@
 
 <componentConfig>
 
-    <!--
-      ResourceManagerService
+  <!--
+    ResourceManagerService
+    
+    domain := one or more domain definitions
+    domain@name := the name of a domain
+    domain@type := an optional implementation class - defaults to FileResourceManager
+    domain/suffix := the extension of the resources to manage
+    domain/location := the location were the resources reside
+    domain/useLocator := enable/disable the locator feature
+  -->
+  <ResourceManagerService>
+    <domain name="groovy">
+      <suffix>groovy</suffix>
+      <location>./src/test/scripts/groovy</location>
+      <useLocator>true</useLocator>
+    </domain>
+  </ResourceManagerService>
+
+	<!--
+		ScriptService
+
+		scriptEngines := the list of available script engines
+		scriptEngines/scriptEngine := configuration of a single script engine
+		scriptEngines/scriptEngine/name := the name of the script engine
+		scriptEngines/scriptEngine/isCached := cache the scripts or reload it each time from the ResourceManagerService
+		scriptEngines/scriptEngine/isCompiled := precompile the script (if supported by the scripting engine)
+		scriptEngines/scriptEngine/location := the associated domain name of ResourceManagerService
+		scriptEngines/scriptEngine/preLoad := a list of scripts to load on startup
+		scriptEngines/scriptEngine/preLoad/script := a single script to load on startup
+	-->
+
+  <ScriptService>
+  	<scriptEngines>
+  		<scriptEngine>
+  			<name>groovy</name>
+  			<isCached>true</isCached>
+  			<isCompiled>true</isCompiled>
+  			<location>groovy</location>
+  		</scriptEngine>
+  	</scriptEngines>
+  	<scriptConfiguration>
+  	  <isDebug>true</isDebug>
+  	</scriptConfiguration>
+  </ScriptService>
 
-      domain := one or more domain definitions
-      domain@name := the name of a domain
-      domain@type := an optional implementation class - defaults to FileResourceManager
-      domain/suffix := the extension of the resources to manage
-      domain/location := the location were the resources reside
-      domain/useLocator := enable/disable the locator feature
-    -->
-    <ResourceManagerService>
-        <domain name="groovy">
-            <suffix>groovy</suffix>
-            <location>./src/test/scripts/groovy</location>
-            <useLocator>true</useLocator>
-        </domain>
-    </ResourceManagerService>
-
-    <!--
-         ScriptService
-
-         scriptEngines := the list of available script engines
-         scriptEngines/scriptEngine := configuration of a single script engine
-         scriptEngines/scriptEngine/name := the name of the script engine
-         scriptEngines/scriptEngine/isCached := cache the scripts or reload it each time from the ResourceManagerService
-         scriptEngines/scriptEngine/isCompiled := precompile the script (if supported by the scripting engine)
-         scriptEngines/scriptEngine/location := the associated domain name of ResourceManagerService
-         scriptEngines/scriptEngine/preLoad := a list of scripts to load on startup
-         scriptEngines/scriptEngine/preLoad/script := a single script to load on startup
-     -->
-
-    <ScriptService>
-        <scriptEngines>
-            <scriptEngine>
-                <name>groovy</name>
-                <isCached>true</isCached>
-                <isCompiled>true</isCompiled>
-                <location>groovy</location>
-            </scriptEngine>
-        </scriptEngines>
-        <scriptConfiguration>
-            <isDebug>true</isDebug>
-        </scriptConfiguration>
-    </ScriptService>
-
-</componentConfig>
+</componentConfig>
\ No newline at end of file

Modified: turbine/fulcrum/trunk/script/src/test/TestRhinoComponentConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/TestRhinoComponentConfig.xml?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/TestRhinoComponentConfig.xml (original)
+++ turbine/fulcrum/trunk/script/src/test/TestRhinoComponentConfig.xml Sat Aug 22 08:15:59 2015
@@ -48,26 +48,37 @@
 		scriptEngines/scriptEngine/isCached := cache the scripts or reload it each time from the ResourceManagerService
 		scriptEngines/scriptEngine/isCompiled := precompile the script (if supported by the scripting engine)
 		scriptEngines/scriptEngine/location := the associated domain name of ResourceManagerService
-		scriptEngines/scriptEngine/preLoad := a list of scripts to load on startup
-		scriptEngines/scriptEngine/preLoad/script := a single script to load on startup
+		scriptEngines/scriptEngine/preload := a list of scripts to load on startup
+		scriptEngines/scriptEngine/preload/script := a single script to load on startup
+		scriptEngines/scriptEngine/startup := a list of scripts to execute during service startup
+		scriptEngines/scriptEngine/startup/script := a single script to execute during service startup
+		scriptEngines/scriptEngine/shutdown := a list of scripts to execute during service disposal
+		scriptEngines/scriptEngine/shutdown/script := a single script to execute during service disposal 		
 	-->
 
   <ScriptService>
   	<scriptEngines>
-  		<scriptEngine>
-  			<name>javascript</name>
-            <extension>js</extension>
-            <isCached>true</isCached>
-  			<isCompiled>true</isCompiled>
-  			<location>js</location>
-  			<preLoad>
+      <scriptEngine>
+  		  <name>javascript</name>
+        <extension>js</extension>
+        <isCached>true</isCached>
+        <isCompiled>true</isCompiled>
+  	    <location>js</location>
+  	    <preload>
   		    <script>InvocableIntf.js</script>
-  			</preLoad>
-  		</scriptEngine>
+  	    </preload>
+        <startup>
+          <script>Startup.js</script>
+          <script>Startup.js</script>
+        </startup>
+        <shutdown>
+          <script>Shutdown.js</script>
+        </shutdown>                    
+      </scriptEngine>
   	</scriptEngines>
   	<scriptConfiguration>
   	  <isDebug>true</isDebug>
   	</scriptConfiguration>
   </ScriptService>
-
-</componentConfig>
+  
+</componentConfig>
\ No newline at end of file

Modified: turbine/fulcrum/trunk/script/src/test/TestRoleConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/TestRoleConfig.xml?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/TestRoleConfig.xml (original)
+++ turbine/fulcrum/trunk/script/src/test/TestRoleConfig.xml Sat Aug 22 08:15:59 2015
@@ -36,4 +36,4 @@
         description="Handles the execution of scripts"
      />
 
-</role-list>
+</role-list>
\ No newline at end of file

Modified: turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/AbstractScriptTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/AbstractScriptTest.java?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/AbstractScriptTest.java (original)
+++ turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/AbstractScriptTest.java Sat Aug 22 08:15:59 2015
@@ -20,7 +20,6 @@ package org.apache.fulcrum.script;
  */
 
 import java.util.Hashtable;
-
 import javax.script.ScriptContext;
 import javax.script.ScriptEngine;
 import javax.script.ScriptException;
@@ -40,9 +39,9 @@ public abstract class AbstractScriptTest
     protected ScriptService scriptService;
 
     /**
-     * Defines the testcase name for JUnit.
+     * Defines the test case name for JUnit.
      *
-     * @param name the testcase's name.
+     * @param name the test case name.
      */
     public AbstractScriptTest(String name)
     {
@@ -62,13 +61,13 @@ public abstract class AbstractScriptTest
      */
     public void testCompilableInterface() throws Exception
     {
-        for (int i=0; i<3; i++)
+        for (int i = 0; i < 3; i++)
         {
             SimpleBindings args = new SimpleBindings();
-            args.put("count",new Integer(i));
-            args.put("currentTime",new Long(System.currentTimeMillis()));
+            args.put("count", new Integer(i));
+            args.put("currentTime", new Long(System.currentTimeMillis()));
             this.scriptService.eval("CompilableInterface", args);
-		}
+        }
     }
 
     /**
@@ -78,66 +77,76 @@ public abstract class AbstractScriptTest
      */
     public void testHelloWorld() throws Exception
     {
-       this.scriptService.eval("HelloWorld");
+        this.scriptService.eval("HelloWorld");
     }
 
     /**
      * Taken from the JSR 223 reference implementation. This test
-     * does not work with the "small" interpreter.
+     * does not work with the "small" bsh interpreter. The scope
+     * of the test is to expose a script over a Java interface
+     * where the underlying implementation keeps state.
      *
      * @throws Exception the test failed
      */
     public void testInvocableIntf() throws Exception
     {
         MyInterface myInterface = (MyInterface) scriptService.getInterface(
-            MyInterface.class
-            );
+                MyInterface.class
+        );
 
-		System.out.println("Initial value for X: " + myInterface.getX());
-		myInterface.setX("New string");
-		System.out.println("Current value for X: " + myInterface.getX());
-		System.out.println("\nInitial value for Y: " + myInterface.getY());
-		myInterface.setY(100);
-		System.out.println("Current value for Y: " + myInterface.getY());
+        System.out.println("Initial value for X: " + myInterface.getX());
+        assertEquals("X string", myInterface.getX());
+        myInterface.setX("New string");
+        System.out.println("Current value for X: " + myInterface.getX());
+        assertEquals("New string", myInterface.getX());
+
+        System.out.println("\nInitial value for Y: " + myInterface.getY());
+        assertEquals("5", myInterface.getY().toString());
+        myInterface.setY(100);
+        System.out.println("Current value for Y: " + myInterface.getY());
+        assertEquals("100", myInterface.getY().toString());
     }
 
     /**
      * Taken from the JSR 223 reference implementation.
      *
-     * @throws Exception the test failed 
+     * @throws Exception the test failed
      */
     public void testNamespaceDemo2() throws Exception
     {
         ScriptEngine eng = this.scriptService.getScriptEngine();
 
-		//create two simple namespaces
-		SimpleBindings eNamespace = new SimpleBindings();
-		eNamespace.put("key", new Testobj("Original engine scope."));
-		SimpleBindings cNamespace = new SimpleBindings();
-		cNamespace.put("key", new Testobj("Original ENGINE_SCOPE in context."));
-
-		//use external namespace instead of the default one
-		eng.setBindings(eNamespace,ScriptContext.ENGINE_SCOPE);
-		System.out.println("Starting value of key in engine scope is \"" + eng.get("key") + "\"");
-
-		//execute script using the namespace
-		this.scriptService.eval("NamespaceDemo2");
-		System.out.println("Ending value of key in engine scope is \"" + eng.get("key") + "\"");
-
-		//create a scriptcontext and set its engine scope namespace
-		ScriptContext ctxt = new SimpleScriptContext();
-		ctxt.setBindings(cNamespace, ScriptContext.ENGINE_SCOPE);
-
-		this.scriptService.eval("NamespaceDemo2", ctxt);
-		System.out.println("Ending value of key in engine scope is \"" + eng.get("key") + "\"");
-		System.out.println("Ending value of key in ENGINE_SCOPE of context is " +
-			ctxt.getAttribute("key",ScriptContext.ENGINE_SCOPE));
+        // create two simple namespaces
+        SimpleBindings eNamespace = new SimpleBindings();
+        eNamespace.put("key", new Testobj("Original engine scope."));
+        SimpleBindings cNamespace = new SimpleBindings();
+        cNamespace.put("key", new Testobj("Original ENGINE_SCOPE in context."));
+
+        // use external namespace instead of the default one
+        eng.setBindings(eNamespace, ScriptContext.ENGINE_SCOPE);
+        System.out.println("Starting value of key in engine scope is \"" + eng.get("key") + "\"");
+        assertEquals("Testobj containing Original engine scope.", eng.get("key").toString().trim());
+
+        //execute script using the namespace
+        this.scriptService.eval("NamespaceDemo2");
+        System.out.println("Ending value of key in engine scope is \"" + eng.get("key") + "\"");
+        assertEquals("new value", eng.get("key"));
+
+        // create a scriptcontext and set its engine scope namespace
+        ScriptContext ctxt = new SimpleScriptContext();
+        ctxt.setBindings(cNamespace, ScriptContext.ENGINE_SCOPE);
+
+        this.scriptService.eval("NamespaceDemo2", ctxt);
+        System.out.println("Ending value of key in engine scope is \"" + eng.get("key") + "\"");
+        assertEquals("new value", eng.get("key"));
+        System.out.println("Ending value of key in ENGINE_SCOPE of context is " + ctxt.getAttribute("key", ScriptContext.ENGINE_SCOPE));
+        assertEquals("new value", ctxt.getAttribute("key", ScriptContext.ENGINE_SCOPE));
     }
 
     /**
      * Taken from the JSR 223 reference implementation.
      *
-     * @throws Exception the test failed 
+     * @throws Exception the test failed
      */
     public void testNamespaceDemo3() throws Exception
     {
@@ -152,14 +161,18 @@ public abstract class AbstractScriptTest
         n.put("state", new Integer(STATE1));
 
         //create a new thread to run script
-        Thread t = new Thread(new Runnable(){
-          public void run() {
-            try {
-              scriptService.eval("NamespaceDemo3");
-            } catch (Exception e) {
-              e.printStackTrace();
+        Thread t = new Thread(new Runnable()
+        {
+            public void run()
+            {
+                try
+                {
+                    scriptService.eval("NamespaceDemo3");
+                } catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
             }
-          }
         });
         t.start();
 
@@ -170,7 +183,7 @@ public abstract class AbstractScriptTest
         n.put("state", new Integer(STATE2));
         t.join();
         System.out.println("Script has executed.. current state is " +
-            n.get("state"));
+                n.get("state"));
     }
 
     /**
@@ -181,9 +194,9 @@ public abstract class AbstractScriptTest
     public void testAvalonContext() throws Exception
     {
         SimpleBindings args = new SimpleBindings();
-        args.put("bar",new Integer(2));
+        args.put("bar", new Integer(2));
         Object result = this.scriptService.eval("Avalon", args);
-        System.out.println("RESULT ==> " +  result);
+        System.out.println("RESULT ==> " + result);
     }
 
     /**
@@ -194,17 +207,16 @@ public abstract class AbstractScriptTest
     public void testPerformance() throws Exception
     {
         long startTime = System.currentTimeMillis();
-        for( int i=0; i<500; i++ )
+        for (int i = 0; i < 500; i++)
         {
             this.testHelloWorld();
             this.testCompilableInterface();
-            this.testNamespaceDemo2();
             this.testAvalonContext();
         }
         long endTime = System.currentTimeMillis();
         long duration = endTime - startTime;
 
-        System.out.println("=== Exceution took " + duration + " ms ===");
+        System.out.println("=== Execution took " + duration + " ms ===");
     }
 
     /**
@@ -227,32 +239,32 @@ public abstract class AbstractScriptTest
     {
         Hashtable args0 = new Hashtable();
         args0.put("foo", new Double(0));
-        ScriptRunnable runnable0 = new ScriptRunnableImpl( this.scriptService, "MultiThreaded", args0 );
+        ScriptRunnable runnable0 = new ScriptRunnableImpl(this.scriptService, "MultiThreaded", args0);
 
         Hashtable args1 = new Hashtable();
         args1.put("foo", new Double(1));
-        ScriptRunnable runnable1 = new ScriptRunnableImpl( this.scriptService, "MultiThreaded", args1 );
-        Thread thread1 = new Thread(runnable1,"Thread1");
+        ScriptRunnable runnable1 = new ScriptRunnableImpl(this.scriptService, "MultiThreaded", args1);
+        Thread thread1 = new Thread(runnable1, "Thread1");
 
         Hashtable args2 = new Hashtable();
         args2.put("foo", new Double(2));
-        ScriptRunnable runnable2 = new ScriptRunnableImpl( this.scriptService, "MultiThreaded", args2 );
-        Thread thread2 = new Thread(runnable2,"Thread2");
+        ScriptRunnable runnable2 = new ScriptRunnableImpl(this.scriptService, "MultiThreaded", args2);
+        Thread thread2 = new Thread(runnable2, "Thread2");
 
         thread1.start();
         thread2.start();
         runnable0.run();
 
-        assertTrue( runnable0.getResult() == runnable0.getResult() );
-        assertTrue( runnable1.getResult() == runnable1.getResult() );
-        assertTrue( runnable2.getResult() == runnable2.getResult() );
+        assertTrue(runnable0.getResult() == runnable0.getResult());
+        assertTrue(runnable1.getResult() == runnable1.getResult());
+        assertTrue(runnable2.getResult() == runnable2.getResult());
 
         thread1.join();
         thread2.join();
 
-        assertEquals( new Double(0), args0.get("foo") );
-        assertEquals( new Double(2), args1.get("foo") );
-        assertEquals( new Double(4), args2.get("foo") );
+        assertEquals(new Double(0), args0.get("foo"));
+        assertEquals(new Double(2), args1.get("foo"));
+        assertEquals(new Double(4), args2.get("foo"));
     }
 
     /**
@@ -266,15 +278,14 @@ public abstract class AbstractScriptTest
         {
             this.scriptService.eval("RuntimeError");
             fail("Expected ScriptException");
-        }
-        catch (ScriptException e)
+        } catch (ScriptException e)
         {
             // expected
         }
     }
 
     /**
-     * Tests the call() method of an Invocable.
+     * Tests the call() method of an Invocable (e.g. InvocableIntf.js).
      *
      * @throws Exception the test failed
      */
@@ -282,9 +293,12 @@ public abstract class AbstractScriptTest
     {
         String newX = "New X String";
         String oldX = (String) this.scriptService.call("getX", new Object[0]);
-        this.scriptService.call("setX", new Object[]{newX} );
+        assertFalse(newX.equals(oldX));
+        this.scriptService.call("setX", new Object[]{newX});
         newX = (String) this.scriptService.call("getX", new Object[0]);
-        this.scriptService.call("setX", new Object[]{oldX} );
+        this.scriptService.call("setX", new Object[]{oldX});
+        String currX = (String) this.scriptService.call("getX", new Object[0]);
+        assertFalse(currX.equals(newX));
     }
 
     /**

Modified: turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/GroovyTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/GroovyTest.java?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/GroovyTest.java (original)
+++ turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/GroovyTest.java Sat Aug 22 08:15:59 2015
@@ -54,21 +54,18 @@ public class GroovyTest extends Abstract
     {
         TestSuite suite = new TestSuite("GroovyTest");
 
-        if(System.getProperty("fulcrum.script.groovyEnabled") != null)
-        {
-            // tests from the JSR-223 Reference implementation
-            suite.addTest( new GroovyTest("testCompilableInterface") );
-            suite.addTest( new GroovyTest("testHelloWorld") );
-            suite.addTest( new GroovyTest("testNamespaceDemo2") );
-            suite.addTest( new GroovyTest("testNamespaceDemo3") );
+        suite.addTest(new GroovyTest("testHelloWorld"));
+        suite.addTest(new GroovyTest("testAvalonContext"));
+        suite.addTest(new GroovyTest("testExists"));
+        suite.addTest(new GroovyTest("testPerformance"));
+        suite.addTest(new GroovyTest("testMultithreadingScript"));
+        suite.addTest(new GroovyTest("testRuntimeErrorScript"));
 
-            suite.addTest( new GroovyTest("testAvalonContext") );
-            suite.addTest( new GroovyTest("testExists") );
-            suite.addTest( new GroovyTest("testPerformance") );
-            suite.addTest( new GroovyTest("testMultithreadingScript") );
-            suite.addTest( new GroovyTest("testRuntimeErrorScript") );
+        // tests from the JSR-223 Reference implementation
+        suite.addTest(new GroovyTest("testCompilableInterface"));
+        suite.addTest(new GroovyTest("testNamespaceDemo2"));
+        suite.addTest(new GroovyTest("testNamespaceDemo3"));
 
-        }
         return suite;
     }
 }

Modified: turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/RhinoTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/RhinoTest.java?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/RhinoTest.java (original)
+++ turbine/fulcrum/trunk/script/src/test/org/apache/fulcrum/script/RhinoTest.java Sat Aug 22 08:15:59 2015
@@ -19,6 +19,9 @@ package org.apache.fulcrum.script;
  * under the License.
  */
 
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -50,23 +53,42 @@ public class RhinoTest extends AbstractS
      */
     public static Test suite()
     {
-        TestSuite suite= new TestSuite("RhinoTest");
+        TestSuite suite = new TestSuite("RhinoTest");
+
+        suite.addTest(new RhinoTest("testDirectInvocation"));
+
+        suite.addTest(new RhinoTest("testHelloWorld"));
+        suite.addTest(new RhinoTest("testAvalonContext"));
+        suite.addTest(new RhinoTest("testExists"));
+        suite.addTest(new RhinoTest("testPerformance"));
+        suite.addTest(new RhinoTest("testMultithreadingScript"));
+        suite.addTest(new RhinoTest("testRuntimeErrorScript"));
+        suite.addTest(new RhinoTest("testCall"));
+        suite.addTest(new RhinoTest("testLocatorFunctionality"));
 
         // tests from the JSR-223 Reference implementation
-        suite.addTest( new RhinoTest("testHelloWorld") );
-        suite.addTest( new RhinoTest("testCompilableInterface") );
-        suite.addTest( new RhinoTest("testNamespaceDemo2") );
-        suite.addTest( new RhinoTest("testNamespaceDemo3") );
-        suite.addTest( new RhinoTest("testInvocableIntf") );
-
-        suite.addTest( new RhinoTest("testAvalonContext") );
-        suite.addTest( new RhinoTest("testExists") );
-        suite.addTest( new RhinoTest("testPerformance") );
-        suite.addTest( new RhinoTest("testMultithreadingScript") );
-        suite.addTest( new RhinoTest("testRuntimeErrorScript") );
-        suite.addTest( new RhinoTest("testCall") );
-        suite.addTest( new RhinoTest("testLocatorFunctionality") );
+        suite.addTest(new RhinoTest("testCompilableInterface"));
+        suite.addTest(new RhinoTest("testInvocableIntf"));
+        suite.addTest(new RhinoTest("testNamespaceDemo2"));
+        suite.addTest(new RhinoTest("testNamespaceDemo3"));
 
         return suite;
     }
+
+    /**
+     * A quick test case for directly evaluating a script using the
+     * plain JDK 1.6 or 1.7 implementation.
+     */
+    public void testDirectInvocation() throws Exception
+    {
+        ScriptEngineManager factory = new ScriptEngineManager();
+        ScriptEngine engine = factory.getEngineByName("JavaScript");
+        engine.put("n", 10);
+        String script =
+                "function fib(n){ return n < 2 ? n : fib(n-1) + fib(n-2); }\n" +
+                        "fib(n);"; // this will be returned
+
+        Number result = (Number) engine.eval(script);
+        assertEquals(55.0, result);
+    }
 }

Modified: turbine/fulcrum/trunk/script/src/test/scripts/groovy/Avalon.groovy
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/groovy/Avalon.groovy?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/groovy/Avalon.groovy (original)
+++ turbine/fulcrum/trunk/script/src/test/scripts/groovy/Avalon.groovy Sat Aug 22 08:15:59 2015
@@ -41,4 +41,4 @@ assert( props.size() == 0 );
 
 int result = foo*10;
 
-return result;
+return result;
\ No newline at end of file

Modified: turbine/fulcrum/trunk/script/src/test/scripts/groovy/NamespaceDemo3.groovy
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/groovy/NamespaceDemo3.groovy?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/groovy/NamespaceDemo3.groovy (original)
+++ turbine/fulcrum/trunk/script/src/test/scripts/groovy/NamespaceDemo3.groovy Sat Aug 22 08:15:59 2015
@@ -32,6 +32,8 @@ while (loop == 1) {
 	if (state == 2) {
 		loop = 0
 	}
+
+	Thread.sleep(100);
 }
 println("-----End of script-----\n");
 

Modified: turbine/fulcrum/trunk/script/src/test/scripts/groovy/RuntimeError.groovy
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/groovy/RuntimeError.groovy?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/groovy/RuntimeError.groovy (original)
+++ turbine/fulcrum/trunk/script/src/test/scripts/groovy/RuntimeError.groovy Sat Aug 22 08:15:59 2015
@@ -17,4 +17,4 @@
  * under the License.
  */
 
-println(foobar);
+println(foobar);
\ No newline at end of file

Modified: turbine/fulcrum/trunk/script/src/test/scripts/js/Avalon.js
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/js/Avalon.js?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/js/Avalon.js (original)
+++ turbine/fulcrum/trunk/script/src/test/scripts/js/Avalon.js Sat Aug 22 08:15:59 2015
@@ -56,4 +56,4 @@ function testMe(aBar)
   var result = foo*10;
 
   return result;
-}
+}
\ No newline at end of file

Modified: turbine/fulcrum/trunk/script/src/test/scripts/js/NamespaceDemo3.js
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/js/NamespaceDemo3.js?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/js/NamespaceDemo3.js (original)
+++ turbine/fulcrum/trunk/script/src/test/scripts/js/NamespaceDemo3.js Sat Aug 22 08:15:59 2015
@@ -5,7 +5,7 @@
  * regarding copyright ownership.  The ASF licenses this file
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
+ * with the License.  You may obtain a copy of the License at                                                                                                                 ~
  *
  *   http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,21 +17,30 @@
  * under the License.
  */
 
-print("\n-----Starting script");
+importClass(Packages.java.lang.Thread);
+
+println("\n-----Starting script");
 
 var initial = parseInt(state);
-print("In script....Initial state is " + initial);
+println("In script....Initial state is " + initial);
 var loop = 1;
-while (loop == 1) {
-	print("Script continues at state = " + state);
-	if (parseInt(state) != initial) {
-		print("State changed (state = " + state + "). Exit script.");
-		loop = 0;
-	}
-	//it may take the script engine too long to start
-	if (parseInt(state)==2) {
-		loop = 0;
-	}
-}
-print("-----End of script-----\n");
+while (loop == 1)
+{
+
+    println("Script continues at state = " + state);
 
+    if (parseInt(state) != initial)
+    {
+        println("State changed (state = " + state + "). Exit script.");
+        loop = 0;
+    }
+
+    //it may take the script engine too long to start
+    if (parseInt(state) == 2)
+    {
+        loop = 0;
+    }
+
+    Thread.sleep(100)
+}
+println("-----End of script-----\n");

Modified: turbine/fulcrum/trunk/script/src/test/scripts/js/RuntimeError.js
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/js/RuntimeError.js?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/js/RuntimeError.js (original)
+++ turbine/fulcrum/trunk/script/src/test/scripts/js/RuntimeError.js Sat Aug 22 08:15:59 2015
@@ -17,4 +17,4 @@
  * under the License.
  */
 
-print(foobar);
+print(foobar);
\ No newline at end of file

Added: turbine/fulcrum/trunk/script/src/test/scripts/js/Shutdown.js
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/js/Shutdown.js?rev=1697080&view=auto
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/js/Shutdown.js (added)
+++ turbine/fulcrum/trunk/script/src/test/scripts/js/Shutdown.js Sat Aug 22 08:15:59 2015
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+ 
+avalonContext.getLogger().info("Executing a shutdown script ...");
\ No newline at end of file

Added: turbine/fulcrum/trunk/script/src/test/scripts/js/Startup.js
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/js/Startup.js?rev=1697080&view=auto
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/js/Startup.js (added)
+++ turbine/fulcrum/trunk/script/src/test/scripts/js/Startup.js Sat Aug 22 08:15:59 2015
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+var counter  = 1;
+avalonContext.getLogger().info("Executing a startup script : " + counter);
+counter = counter + 1;
\ No newline at end of file

Modified: turbine/fulcrum/trunk/script/src/test/scripts/js/locator/bar/foo.js
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/js/locator/bar/foo.js?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/js/locator/bar/foo.js (original)
+++ turbine/fulcrum/trunk/script/src/test/scripts/js/locator/bar/foo.js Sat Aug 22 08:15:59 2015
@@ -16,9 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-testMe();
 
-function testMe(aBar)
+function testMe() 
 {
   return "locator/bar/foo.js";
 }
+
+testMe();
+

Modified: turbine/fulcrum/trunk/script/src/test/scripts/js/locator/foo.js
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/script/src/test/scripts/js/locator/foo.js?rev=1697080&r1=1697079&r2=1697080&view=diff
==============================================================================
--- turbine/fulcrum/trunk/script/src/test/scripts/js/locator/foo.js (original)
+++ turbine/fulcrum/trunk/script/src/test/scripts/js/locator/foo.js Sat Aug 22 08:15:59 2015
@@ -16,9 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-testMe();
 
-function testMe(aBar)
+function testMe() 
 {
   return "locator/foo.js";
 }
+
+testMe();
+