You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/04/10 21:43:16 UTC

[groovy] branch master updated: GROOVY-10023: Remove BSF module from Groovy 4 (closes #1550)

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new d9a6e3a  GROOVY-10023: Remove BSF module from Groovy 4 (closes #1550)
d9a6e3a is described below

commit d9a6e3afd708f110f1291545129d89f19121579e
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Apr 9 16:43:49 2021 +1000

    GROOVY-10023: Remove BSF module from Groovy 4 (closes #1550)
---
 gradle/verification-metadata.xml                   |  10 --
 settings.gradle                                    |   1 -
 src/spec/doc/core-getting-started.adoc             |   2 +-
 src/spec/doc/guide-integrating.adoc                |   2 -
 subprojects/groovy-bsf/build.gradle                |  34 ----
 .../codehaus/groovy/bsf/CachingGroovyEngine.java   | 127 --------------
 .../java/org/codehaus/groovy/bsf/GroovyEngine.java | 160 ------------------
 .../main/java/org/codehaus/groovy/bsf/package.html |  29 ----
 .../groovy-bsf/src/spec/doc/_integrating-bsf.adoc  |  86 ----------
 .../groovy-bsf/src/spec/test/BSFSpecTest.java      |  78 ---------
 .../test/java/org/codehaus/groovy/bsf/BSFTest.java | 186 ---------------------
 .../java/org/codehaus/groovy/bsf/CacheBSFTest.java | 119 -------------
 .../resources/groovy/script/MapFromList.groovy     |  38 -----
 13 files changed, 1 insertion(+), 871 deletions(-)

diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml
index 9dcde2d..28fddfc 100644
--- a/gradle/verification-metadata.xml
+++ b/gradle/verification-metadata.xml
@@ -262,11 +262,6 @@
             <pgp value="32d98ffd50617f6ed7e6abd236feecf06c2da10b"/>
          </artifact>
       </component>
-      <component group="bsf" name="bsf" version="2.4.0">
-         <artifact name="bsf-2.4.0.jar">
-            <sha512 value="cf2ff6ea53cd13ea842cad398f1be24539bec68a5cbbd088492adab50bc782cde6d9f4c0b6a24deaeee537809c90631c43f9a680ff2826c28ccf1b39380954e3" origin="Generated by Gradle because artifact wasn't signed"/>
-         </artifact>
-      </component>
       <component group="cglib" name="cglib-nodep" version="2.1_3">
          <artifact name="cglib-nodep-2.1_3.jar">
             <sha512 value="86a49c4a7d9d609636f8a7c42d40dca96e20ec4f3ec182bb0aa6ee5c8233234d399086f1342198b5048f7a36db402f1b956fbf74220192ec4aa39880c8ff2381" origin="Generated by Gradle because artifact wasn't signed"/>
@@ -874,11 +869,6 @@
             <sha512 value="4ee088bebe52aaa71e76ca58ad2eda56e79718affd83ca0337febd8658ad8e8afc157428a29ea02dc448ba508bcacc957efea4e6fa121e41fa009de64e15bc4f" origin="Generated by Gradle because artifact wasn't signed"/>
          </artifact>
       </component>
-      <component group="org.codehaus.groovy" name="groovy-bsf" version="3.0.5">
-         <artifact name="groovy-bsf-3.0.5.jar">
-            <sha512 value="a5ccc811573f431240ec0e64318689a18f91c4e889eb4eef76a2ba83fb90cbf50980cd6bd2c5426bd61d5586077ee38a0ffa7f9f134314eaecc132a927f2cccd" origin="Generated by Gradle because artifact wasn't signed"/>
-         </artifact>
-      </component>
       <component group="org.codehaus.groovy" name="groovy-cli-commons" version="3.0.5">
          <artifact name="groovy-cli-commons-3.0.5.jar">
             <sha512 value="daf8e5a56be32c284cdaded8f89e3fd01b4d0f5f141d3347986eb8e2f9d7d4407533749d19031aac57eeaca66ea7e8b357e763f47a93e180bdbae7d9b10ecd2a" origin="Generated by Gradle because artifact wasn't signed"/>
diff --git a/settings.gradle b/settings.gradle
index d5ff3c1..0c7e7f4 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -34,7 +34,6 @@ def subprojects = [
         'groovy-ant',
         'groovy-astbuilder',
         'groovy-binary',
-        'groovy-bsf',
         'groovy-bom',
         'groovy-cli-commons',
         'groovy-cli-picocli',
diff --git a/src/spec/doc/core-getting-started.adoc b/src/spec/doc/core-getting-started.adoc
index 5ac78cc..bafed35 100644
--- a/src/spec/doc/core-getting-started.adoc
+++ b/src/spec/doc/core-getting-started.adoc
@@ -77,7 +77,7 @@ If you wish to embed Groovy in your application, you may just prefer to point to
 |<groupId>org.codehaus.groovy</groupId> +
 <artifactId>groovy-$module</artifactId> +
 <version>{groovy-full-version}</version>
-|"$module" stands for the different optional groovy modules "ant", "bsf", "console", "docgenerator", "groovydoc", "groovysh", "jmx", "json", "jsr223", "servlet", "sql", "swing", "test", "testng" and "xml". Example: <artifactId>groovy-sql</artifactId>
+|"$module" stands for the different optional groovy modules "ant", "console", "docgenerator", "groovydoc", "groovysh", "jmx", "json", "jsr223", "servlet", "sql", "swing", "test", "testng" and "xml". Example: <artifactId>groovy-sql</artifactId>
 
 |&#39;org.codehaus.groovy:groovy-all:{groovy-full-version}'
 |<groupId>org.codehaus.groovy</groupId> +
diff --git a/src/spec/doc/guide-integrating.adoc b/src/spec/doc/guide-integrating.adoc
index b4d29de..59affb9 100644
--- a/src/spec/doc/guide-integrating.adoc
+++ b/src/spec/doc/guide-integrating.adoc
@@ -323,8 +323,6 @@ stub generation is done, for the joint compiler.
 
 However, overriding `CompilationUnit` is not recommended and should only be done if no other standard solution works.
 
-include::../../../subprojects/groovy-bsf/src/spec/doc/_integrating-bsf.adoc[leveloffset=+1]
-
 include::../../../subprojects/groovy-jsr223/src/spec/doc/_integrating-jsr223.adoc[leveloffset=+1]
 
 
diff --git a/subprojects/groovy-bsf/build.gradle b/subprojects/groovy-bsf/build.gradle
deleted file mode 100644
index c003970..0000000
--- a/subprojects/groovy-bsf/build.gradle
+++ /dev/null
@@ -1,34 +0,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.
- */
-plugins {
-    id 'org.apache.groovy-library'
-}
-
-dependencies {
-    api('bsf:bsf:2.4.0') {  // GroovyEngine...
-        exclude(group: 'commons-logging', module: 'commons-logging')
-    }
-    implementation 'commons-logging:commons-logging:1.2'
-    api rootProject // GroovyEngine#getEvalShell
-    testImplementation project(':groovy-test')
-}
-
-groovyLibrary {
-    optionalModule()
-}
\ No newline at end of file
diff --git a/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/CachingGroovyEngine.java b/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/CachingGroovyEngine.java
deleted file mode 100644
index 6c518e7..0000000
--- a/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/CachingGroovyEngine.java
+++ /dev/null
@@ -1,127 +0,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.
- */
-package org.codehaus.groovy.bsf;
-
-import groovy.lang.Binding;
-import groovy.lang.GroovyClassLoader;
-import groovy.lang.GroovyShell;
-import groovy.lang.Script;
-import org.apache.bsf.BSFDeclaredBean;
-import org.apache.bsf.BSFException;
-import org.apache.bsf.BSFManager;
-import org.apache.bsf.util.BSFFunctions;
-import org.codehaus.groovy.control.CompilerConfiguration;
-import org.codehaus.groovy.runtime.InvokerHelper;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * A Caching implementation of the GroovyEngine
- */
-public class CachingGroovyEngine extends GroovyEngine {
-    private static final Logger LOG = Logger.getLogger(CachingGroovyEngine.class.getName());
-    private static final Object[] EMPTY_ARGS = new Object[]{new String[]{}};
-
-    private Map<Object, Class> evalScripts;
-    private Map<Object, Class> execScripts;
-    private Binding context;
-    private GroovyClassLoader loader;
-
-    /**
-     * Evaluate an expression.
-     */
-    @Override
-    public Object eval(String source, int lineNo, int columnNo, Object script) throws BSFException {
-        try {
-            Class scriptClass = evalScripts.get(script);
-            if (scriptClass == null) {
-                scriptClass = loader.parseClass(script.toString(), source);
-                evalScripts.put(script, scriptClass);
-            } else {
-                LOG.fine("eval() - Using cached script...");
-            }
-            //can't cache the script because the context may be different.
-            //but don't bother loading parsing the class again
-            Script s = InvokerHelper.createScript(scriptClass, context);
-            return s.run();
-        } catch (Exception e) {
-            throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
-        }
-    }
-
-    /**
-     * Execute a script.
-     */
-    @Override
-    public void exec(String source, int lineNo, int columnNo, Object script) throws BSFException {
-        try {
-            //          shell.run(script.toString(), source, EMPTY_ARGS);
-
-            Class scriptClass = execScripts.get(script);
-            if (scriptClass == null) {
-                scriptClass = loader.parseClass(script.toString(), source);
-                execScripts.put(script, scriptClass);
-            } else {
-                LOG.fine("exec() - Using cached version of class...");
-            }
-            InvokerHelper.invokeMethod(scriptClass, "main", EMPTY_ARGS);
-        } catch (Exception e) {
-            LOG.log(Level.WARNING, "BSF trace", e);
-            throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
-        }
-    }
-
-    /**
-     * Initialize the engine.
-     */
-    @Override
-    public void initialize(final BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
-        super.initialize(mgr, lang, declaredBeans);
-        ClassLoader parent = mgr.getClassLoader();
-        if (parent == null)
-            parent = GroovyShell.class.getClassLoader();
-        setLoader(mgr, parent);
-        execScripts = new HashMap<>();
-        evalScripts = new HashMap<>();
-        context = shell.getContext();
-        // create a shell
-        // register the mgr with object name "bsf"
-        context.setVariable("bsf", new BSFFunctions(mgr, this));
-        int size = declaredBeans.size();
-        for (int i = 0; i < size; i++) {
-            declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private void setLoader(final BSFManager mgr, final ClassLoader finalParent) {
-        this.loader =
-                (GroovyClassLoader) AccessController.doPrivileged((PrivilegedAction) () -> {
-                    CompilerConfiguration configuration = new CompilerConfiguration();
-                    configuration.setClasspath(mgr.getClassPath());
-                    return new GroovyClassLoader(finalParent, configuration);
-                });
-    }
-}
diff --git a/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java b/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java
deleted file mode 100644
index 3570e24..0000000
--- a/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/GroovyEngine.java
+++ /dev/null
@@ -1,160 +0,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.
- */
-package org.codehaus.groovy.bsf;
-
-import groovy.lang.Closure;
-import groovy.lang.GroovyShell;
-import org.apache.bsf.BSFDeclaredBean;
-import org.apache.bsf.BSFException;
-import org.apache.bsf.BSFManager;
-import org.apache.bsf.util.BSFEngineImpl;
-import org.apache.bsf.util.BSFFunctions;
-import org.codehaus.groovy.runtime.InvokerHelper;
-
-import java.util.Vector;
-
-/**
- * A BSF Engine for the <a href="http://groovy-lang.org/">Groovy</a> scripting language.
- * <p>
- * It's inspired from the Jython engine
- */
-public class GroovyEngine extends BSFEngineImpl {
-    protected GroovyShell shell;
-
-    /*
-     * Convert a non java class name to a java classname
-     * This is used to convert a script name to a name
-     * that can be used as a classname with the script is
-     * loaded in GroovyClassloader#load()
-     * The method simply replaces any invalid characters
-     * with "_".
-     */
-    private static String convertToValidJavaClassname(String inName) {
-        if (inName == null) return "_";
-        if (inName.startsWith("scriptdef_")) inName = inName.substring(10);
-        if (inName.isEmpty()) return "_";
-
-        StringBuilder output = new StringBuilder(inName.length());
-        boolean firstChar = true;
-        for (int i = 0; i < inName.length(); ++i) {
-            char ch = inName.charAt(i);
-            if (firstChar && !Character.isJavaIdentifierStart(ch)) {
-                ch = '_';
-            } else if (!firstChar
-                    && !(Character.isJavaIdentifierPart(ch) || ch == '.')) {
-                ch = '_';
-            }
-            firstChar = (ch == '.');
-            output.append(ch);
-        }
-        return output.toString();
-    }
-
-    /**
-     * Allow an anonymous function to be declared and invoked
-     */
-    @Override
-    public Object apply(String source, int lineNo, int columnNo, Object funcBody, Vector paramNames,
-                        Vector arguments) throws BSFException {
-        Object object = eval(source, lineNo, columnNo, funcBody);
-        if (object instanceof Closure) {
-            // lets call the function
-            Closure closure = (Closure) object;
-            return closure.call(arguments.toArray());
-        }
-        return object;
-    }
-
-    /**
-     * Call the named method of the given object.
-     */
-    @Override
-    public Object call(Object object, String method, Object[] args) throws BSFException {
-        return InvokerHelper.invokeMethod(object, method, args);
-    }
-
-    /**
-     * Evaluate an expression.
-     */
-    @Override
-    public Object eval(String source, int lineNo, int columnNo, Object script) throws BSFException {
-        try {
-            source = convertToValidJavaClassname(source);
-            return getEvalShell().evaluate(script.toString(), source);
-        } catch (Exception e) {
-            throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
-        }
-    }
-
-    /**
-     * Execute a script.
-     */
-    @Override
-    public void exec(String source, int lineNo, int columnNo, Object script) throws BSFException {
-        try {
-            // use evaluate to pass in the BSF variables
-            source = convertToValidJavaClassname(source);
-            getEvalShell().evaluate(script.toString(), source);
-        } catch (Exception e) {
-            throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
-        }
-    }
-
-    /**
-     * Initialize the engine.
-     */
-    @Override
-    public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException {
-        super.initialize(mgr, lang, declaredBeans);
-
-        // create a shell
-        shell = new GroovyShell(mgr.getClassLoader());
-
-        // register the mgr with object name "bsf"
-        shell.setVariable("bsf", new BSFFunctions(mgr, this));
-
-        int size = declaredBeans.size();
-        for (int i = 0; i < size; i++) {
-            declareBean((BSFDeclaredBean) declaredBeans.elementAt(i));
-        }
-    }
-
-    /**
-     * Declare a bean
-     */
-    @Override
-    public void declareBean(BSFDeclaredBean bean) throws BSFException {
-        shell.setVariable(bean.name, bean.bean);
-    }
-
-    /**
-     * Undeclare a previously declared bean.
-     */
-    @Override
-    public void undeclareBean(BSFDeclaredBean bean) throws BSFException {
-        shell.setVariable(bean.name, null);
-    }
-
-    /**
-     * @return a newly created GroovyShell using the same variable scope but a new class loader
-     */
-    protected GroovyShell getEvalShell() {
-        return new GroovyShell(shell);
-    }
-}
diff --git a/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/package.html b/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/package.html
deleted file mode 100644
index a8bf7300..0000000
--- a/subprojects/groovy-bsf/src/main/java/org/codehaus/groovy/bsf/package.html
+++ /dev/null
@@ -1,29 +0,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.
-
--->
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <title>package org.codehaus.groovy.bsf.*</title>
-  </head>
-  <body>
-    <p>Defines the BSF Engine for using Groovy inside any BSF application.</p>
-  </body>
-</html>
diff --git a/subprojects/groovy-bsf/src/spec/doc/_integrating-bsf.adoc b/subprojects/groovy-bsf/src/spec/doc/_integrating-bsf.adoc
deleted file mode 100644
index 26bbb27..0000000
--- a/subprojects/groovy-bsf/src/spec/doc/_integrating-bsf.adoc
+++ /dev/null
@@ -1,86 +0,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.
-
-//////////////////////////////////////////
-
-= Bean Scripting Framework
-
-WARNING: The https://commons.apache.org/proper/commons-bsf/[Bean Scripting Framework] is an attempt to create an API
-to allow calling scripting languages from Java. It hasn't been updated for long and abandoned in favor of the
-standard <<jsr223,JSR-223>> API.
-
-The BSF engine for Groovy is implemented by the `org.codehaus.groovy.bsf.GroovyEngine` class. However, that fact is
-normally hidden away by the BSF APIs. You just treat Groovy like any of the other scripting languages via the BSF
-API.
-
-NOTE: Since Groovy has its own native support for integration with Java, you only need to worry about BSF if you also
-want to also be able to call other languages, e.g. https://www.jruby.org/[JRuby] or if you want to remain very
-loosely coupled from your scripting language.
-
-== Getting started
-
-Provided you have Groovy and BSF jars in your classpath, you can use the
-following Java code to run a sample Groovy script:
-
-[source,java]
--------------------------------------------------------------------------------
-include::../test/BSFSpecTest.java[tags=bsf_simple,indent=0]
--------------------------------------------------------------------------------
-
-== Passing in variables
-
-BSF lets you pass beans between Java and your scripting language. You
-can _register_/_unregister_ beans which makes them known to BSF. You can
-then use BSF methods to _lookup_ beans as required. Alternatively, you
-can _declare_/_undeclare_ beans. This will register them but also make
-them available for use directly in your scripting language. This second
-approach is the normal approach used with Groovy. Here is an example:
-
-[source,java]
------------------------------------------------------------------------
-include::../test/BSFSpecTest.java[tags=bsf_variable_passing,indent=0]
------------------------------------------------------------------------
-
-== Other calling options
-
-The previous examples used the _eval_ method. BSF makes multiple methods
-available for your use (see the
-https://commons.apache.org/proper/commons-bsf/manual.html[BSF documentation] for more
-details). One of the other available methods is _apply_. It allows you
-to define an anonymous function in your scripting language and apply
-that function to arguments. Groovy supports this function using
-closures. Here is an example:
-
-[source,java]
---------------------------------------------------------------------------------
-include::../test/BSFSpecTest.java[tags=bsf_apply,indent=0]
---------------------------------------------------------------------------------
-
-== Access to the scripting engine
-
-Although you don’t normally need it, BSF does provide a hook that lets
-you get directly to the scripting engine. One of the functions which the
-engine can perform is to invoke a single method call on an object. Here
-is an example:
-
-[source,java]
---------------------------------------------------------------------------
-include::../test/BSFSpecTest.java[tags=bsf_access,indent=0]
---------------------------------------------------------------------------
-
diff --git a/subprojects/groovy-bsf/src/spec/test/BSFSpecTest.java b/subprojects/groovy-bsf/src/spec/test/BSFSpecTest.java
deleted file mode 100644
index d81be0e..0000000
--- a/subprojects/groovy-bsf/src/spec/test/BSFSpecTest.java
+++ /dev/null
@@ -1,78 +0,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.
- */
-import org.apache.bsf.BSFEngine;
-import org.apache.bsf.BSFException;
-import org.apache.bsf.BSFManager;
-import org.junit.Test;
-
-import java.util.List;
-import java.util.Vector;
-
-import static org.junit.Assert.assertEquals;
-
-public class BSFSpecTest {
-    @Test
-    public void testSimpleIntegration() throws BSFException {
-        // tag::bsf_simple[]
-        String myScript = "println('Hello World')\n  return [1, 2, 3]";
-        BSFManager manager = new BSFManager();
-        List answer = (List) manager.eval("groovy", "myScript.groovy", 0, 0, myScript);
-        assertEquals(3, answer.size());
-        // end::bsf_simple[]
-    }
-
-    @Test
-    public void testVariablePassing() throws BSFException {
-        // tag::bsf_variable_passing[]
-        BSFManager manager = new BSFManager();
-        manager.declareBean("xyz", 4, Integer.class);
-        Object answer = manager.eval("groovy", "test.groovy", 0, 0, "xyz + 1");
-        assertEquals(5, answer);
-        // end::bsf_variable_passing[]
-    }
-
-    @Test
-    public void testApply() throws BSFException {
-        // tag::bsf_apply[]
-        BSFManager manager = new BSFManager();
-        Vector<String> ignoreParamNames = null;
-        Vector<Integer> args = new Vector<>();
-        args.add(2);
-        args.add(5);
-        args.add(1);
-        Integer actual = (Integer) manager.apply("groovy", "applyTest", 0, 0,
-                "def summer = { a, b, c -> a * 100 + b * 10 + c }", ignoreParamNames, args);
-        assertEquals(251, actual.intValue());
-        // end::bsf_apply[]
-    }
-
-    @Test
-    public void testAccess() throws BSFException {
-        // tag::bsf_access[]
-        BSFManager manager = new BSFManager();
-        BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
-        manager.declareBean("myvar", "hello", String.class);
-        Object myvar = manager.lookupBean("myvar");
-        String result = (String) bsfEngine.call(myvar, "reverse", new Object[0]);
-        assertEquals("olleh", result);
-        // end::bsf_access[]
-    }
-
-
-}
diff --git a/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/BSFTest.java b/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/BSFTest.java
deleted file mode 100644
index f8c0490..0000000
--- a/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/BSFTest.java
+++ /dev/null
@@ -1,186 +0,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.
- */
-package org.codehaus.groovy.bsf;
-
-import junit.framework.TestCase;
-import org.apache.bsf.BSFEngine;
-import org.apache.bsf.BSFException;
-import org.apache.bsf.BSFManager;
-import org.codehaus.groovy.runtime.ResourceGroovyMethods;
-
-import java.io.File;
-import java.util.List;
-import java.util.Vector;
-
-/**
- * Tests the BSF integration.
- */
-public class BSFTest extends TestCase {
-    private static final Class ENGINE = GroovyEngine.class;
-
-    protected BSFManager manager;
-
-    protected void setUp() throws Exception {
-        BSFManager.registerScriptingEngine("groovy", ENGINE.getName(), new String[]{"groovy", "gy"});
-        manager = new BSFManager();
-    }
-
-    public void testScriptDefPrefixRemoval() throws Exception {
-        manager.exec("groovy","scriptdef_foo", 0, 0, "assert bsf != null && this.class.name.equals('foo')");
-        manager.exec("groovy","scriptdef_", 0, 0, "assert bsf != null && this.class.name.equals('_')");
-    }
-
-    public void testInvalidName() throws Exception {
-        manager.exec("groovy", null, 0, 0, "assert bsf != null");
-        manager.exec("groovy", "", 0, 0, "assert bsf != null");
-        manager.exec("groovy", "-", 0, 0, "assert bsf != null");
-    }
-
-    public void testCompileErrorWithExec() throws Exception {
-        try {
-            manager.exec("groovy", "dummy", 0, 0, "assert assert");
-            fail("Should have caught compile exception");
-        } catch (BSFException e) {
-            assertTrue("e.getMessage() should contain CompilationError: " + e.getMessage(),
-                    e.getMessage().contains("CompilationError"));
-        }
-    }
-
-    public void testCompileErrorWithEval() throws Exception {
-        try {
-            manager.eval("groovy", "dummy", 0, 0, "assert assert");
-            fail("Should have caught compile exception");
-        } catch (BSFException e) {
-            assertTrue("e.getMessage() should contain CompilationError: " + e.getMessage(),
-                    e.getMessage().contains("CompilationError"));
-        }
-    }
-
-    public void testExec() throws Exception {
-        manager.exec("groovy", "Test1.groovy", 0, 0, "assert bsf != null , 'should have a bsf variable'");
-    }
-
-    public void testApplyWithClosure() throws Exception {
-        Vector ignoreParamNames = null;
-        Vector ignoreArgs = null;
-        Integer actual = (Integer) manager.apply("groovy", "applyTest", 0, 0,
-                "251", ignoreParamNames, ignoreArgs);
-        assertEquals(251, actual.intValue());
-    }
-
-    public void testApply() throws Exception {
-        Vector ignoreParamNames = null;
-        Vector<Integer> args = new Vector<>();
-        args.add(2);
-        args.add(5);
-        args.add(1);
-        Integer actual = (Integer) manager.apply("groovy", "applyTest", 0, 0,
-                "def summer = { a, b, c -> a * 100 + b * 10 + c }", ignoreParamNames, args);
-        assertEquals(251, actual.intValue());
-    }
-
-    public void testBracketName() throws Exception {
-        manager.exec("groovy", "Test1<groovy>", 0, 0, "assert bsf != null , 'should have a bsf variable'");
-    }
-
-    public void testEval() throws Exception {
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0, "return [1, 2, 3]");
-        assertTrue("Should return a list: " + answer, answer instanceof List);
-        List list = (List) answer;
-        assertEquals("List should be of right size", 3, list.size());
-    }
-
-    public void testTwoEvalsWithSameName() throws Exception {
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0, "return 'cheese'");
-        assertEquals("cheese", answer);
-        answer = manager.eval("groovy", "Test1.groovy", 0, 0, "return 'gromit'");
-        assertEquals("gromit", answer);
-    }
-
-    public void testExecBug() throws Exception {
-        for (int i = 0; i < 10; i++) {
-            manager.exec("groovy", "Test1.groovy", 0, 0, "assert true");
-            manager.exec("groovy", "Test1.groovy", 0, 0, "assert true");
-        }
-    }
-
-    public void testBsfVariables() throws Exception {
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0,
-                "assert this.bsf != null\n  return this.bsf");
-        assertTrue("Should have an answer", answer != null);
-    }
-
-    public void testNotFoundVariables() throws Exception {
-        manager.registerBean("x", 4);
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0,
-                "def valueOfX = this.bsf.lookupBean('y'); assert valueOfX == null");
-        assertNull("Undeclared beans should yield null", answer);
-    }
-
-    public void testRegisteredVariables() throws Exception {
-        manager.registerBean("x", 4);
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0,
-                "def valueOfX = this.bsf.lookupBean('x'); assert valueOfX == 4; valueOfX + 1");
-        assertEquals("Incorrect return", 5, answer);
-    }
-
-    public void testUnregisteredVariables() throws Exception {
-        manager.registerBean("x", 4);
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0,
-                "def valueOfX = this.bsf.lookupBean('x'); assert valueOfX == 4; valueOfX + 1");
-        assertEquals("Incorrect return", 5, answer);
-        manager.unregisterBean("x");
-        // have to lookup registered beans
-        answer = manager.eval("groovy", "Test1.groovy", 0, 0,
-                "def valueOfX = this.bsf.lookupBean('x'); assert valueOfX == null");
-        assertNull("Unregistered beans should yield null", answer);
-    }
-
-    public void testDeclaredVariables() throws Exception {
-        manager.declareBean("xyz", 4, Integer.class);
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0, "xyz + 1");
-        assertEquals("Incorrect return", 5, answer);
-    }
-
-    public void testUndeclaredVariables() throws Exception {
-        manager.declareBean("abc", 4, Integer.class);
-        // declared beans should just be available
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0, "abc + 1");
-        assertEquals("Incorrect return", 5, answer);
-        manager.undeclareBean("abc");
-        answer = manager.eval("groovy", "Test1.groovy", 0, 0, "abc");
-        assertNull("Undeclared beans should yield null", answer);
-    }
-
-    public void testCall() throws Exception {
-        BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
-        manager.declareBean("myvar", "hello", String.class);
-        Object myvar = manager.lookupBean("myvar");
-        String result = (String) bsfEngine.call(myvar, "reverse", new Object[]{});
-        assertEquals("olleh", result);
-    }
-
-    public void testExecFile() throws Exception {
-        execScript("src/test/resources/groovy/script/MapFromList.groovy");
-    }
-
-    protected void execScript(String fileName) throws Exception {
-        manager.exec("groovy", fileName, 0, 0, ResourceGroovyMethods.getText(new File(fileName)));
-    }
-}
diff --git a/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/CacheBSFTest.java b/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/CacheBSFTest.java
deleted file mode 100644
index 0e012a4..0000000
--- a/subprojects/groovy-bsf/src/test/java/org/codehaus/groovy/bsf/CacheBSFTest.java
+++ /dev/null
@@ -1,119 +0,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.
- */
-package org.codehaus.groovy.bsf;
-
-import junit.framework.TestCase;
-import org.apache.bsf.BSFEngine;
-import org.apache.bsf.BSFException;
-import org.apache.bsf.BSFManager;
-
-import java.util.List;
-import java.util.Vector;
-
-/**
- * Tests the Caching BSF integration
- */
-public class CacheBSFTest extends TestCase {
-
-    protected BSFManager manager;
-    private static final Class CACHING_ENGINE = CachingGroovyEngine.class;
-
-    protected void setUp() throws Exception {
-        // override standard engine with caching one
-        BSFManager.registerScriptingEngine("groovy", CACHING_ENGINE.getName(), new String[]{"groovy", "gy"});
-        manager = new BSFManager();
-    }
-
-    public void testVersion() throws Exception {
-        //System.out.println("BSFManager.getVersion() = " + BSFManager.getVersion());
-        BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
-        assertEquals(CACHING_ENGINE, bsfEngine.getClass());
-    }
-
-    public void testExec() throws Exception {
-        manager.exec("groovy", "Test1.groovy", 0, 0, "println('testing Exec')");
-        //nothing to really test here...just looking for debug that says it
-        // used cache version
-        manager.exec("groovy", "Test1.groovy", 0, 0, "println('testing Exec')");
-    }
-
-    public void testCompileErrorWithExec() throws Exception {
-        try {
-            manager.exec("groovy", "dummy", 0, 0, "assert assert");
-            fail("Should have caught compile exception");
-        } catch (BSFException e) {
-            assertTrue("e.getMessage() should contain CompilationError: " + e.getMessage(),
-                    e.getMessage().indexOf("CompilationError") != -1);
-        }
-    }
-
-    public void testEval() throws Exception {
-        Object dontcare = manager.eval("groovy", "Test1.groovy", 0, 0, "return [1, 2, 3]");
-        // nothing to really test here...just looking for debug that says it
-        // used cache version
-        Object answer = manager.eval("groovy", "Test.groovy", 0, 0, "return [1, 2, 3]");
-        assertTrue("Should return a list: " + answer, answer instanceof List);
-        List list = (List) answer;
-        assertEquals("List should be of right size", 3, list.size());
-    }
-
-    public void testCompileErrorWithEval() throws Exception {
-        try {
-            manager.eval("groovy", "dummy", 0, 0, "assert assert");
-            fail("Should have caught compile exception");
-        } catch (BSFException e) {
-            assertTrue("e.getMessage() should contain CompilationError: " + e.getMessage(),
-                    e.getMessage().indexOf("CompilationError") != -1);
-        }
-    }
-
-    public void testBuiltInVariable() throws Exception {
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0,
-                "assert this.bsf != null\n  return this.bsf");
-        assertTrue("Should have an answer", answer != null);
-    }
-
-    public void testVariables() throws Exception {
-        manager.registerBean("x", 4);
-        Object dontcare = manager.eval("groovy", "Test1.groovy", 0, 0,
-                "valueOfX = this.bsf.lookupBean('x'); assert valueOfX == 4; valueOfX + 1");
-        // nothing to really test here...just looking for debug that says it
-        // used cache version
-        Object answer = manager.eval("groovy", "Test2.groovy", 0, 0,
-                "valueOfX = this.bsf.lookupBean('x'); assert valueOfX == 4; valueOfX + 1");
-        assertEquals("Incorrect return", 5, answer);
-    }
-
-    public void testClassLoaderSet() throws BSFException {
-        CachingGroovyEngine cachingGroovyEngine = new CachingGroovyEngine();
-        manager.setClassLoader(null);
-        cachingGroovyEngine.initialize(manager, "dummy", new Vector());
-        // still working implies classloader set, coverage confirms this
-        assertEquals("hi", manager.eval("groovy", "dummy", 0, 0, "'hi'"));
-    }
-
-    public void testDeclaredVariables() throws Exception {
-        manager.declareBean("foo", 5, Integer.class);
-        Object answer = manager.eval("groovy", "Test1.groovy", 0, 0, "valueOfFoo = foo; return valueOfFoo");
-        assertEquals(5, answer);
-        manager.declareBean("foo", 6, Integer.class);
-        answer = manager.eval("groovy", "Test2.groovy", 0, 0, "valueOfFoo = foo; return valueOfFoo");
-        assertEquals(6, answer);
-    }
-}
diff --git a/subprojects/groovy-bsf/src/test/resources/groovy/script/MapFromList.groovy b/subprojects/groovy-bsf/src/test/resources/groovy/script/MapFromList.groovy
deleted file mode 100644
index 4dee7e1..0000000
--- a/subprojects/groovy-bsf/src/test/resources/groovy/script/MapFromList.groovy
+++ /dev/null
@@ -1,38 +0,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.
- */
-package groovy.script
-
-class MapFromList {
-    def doit(args) {
-        def i = 1
-        def result = [:]
-        args.each {
-            result.put(it, i++)
-        }
-        result
-    }
-
-    static void main(args) {
-        def a = ['tom', 'dick', 'harry']
-        def answer = new MapFromList().doit(a)
-        assert answer instanceof Map
-        assert answer.size() == 3
-        assert answer.values() as Set == 1..3 as Set
-    }
-}