diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java index a2e30322f..809ba63a4 100644 --- a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java +++ b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java @@ -125,6 +125,13 @@ public abstract class ScriptRunnerBase { */ public abstract boolean supportsLanguage(); + /** + * Get the name of the manager prefix used for this + * scriptrunner. + * @return the prefix string. + */ + public abstract String getManagerName(); + /** * Defines the language (required). * @param language the scripting language name for the script. @@ -216,6 +223,22 @@ public abstract class ScriptRunnerBase { this.script = ""; } + /** + * Set the project for this runner. + * @param project the project. + */ + public void setProject(Project project) { + this.project = project; + } + + /** + * Get the project for this runner. + * @return the project. + */ + public Project getProject() { + return project; + } + /** * Bind the runner to a project component. * Properties, targets and references are all added as beans; diff --git a/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java b/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java index 0f24e0683..f4844c3f1 100644 --- a/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java +++ b/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java @@ -21,9 +21,14 @@ import org.apache.bsf.BSFException; import org.apache.bsf.BSFManager; import org.apache.bsf.BSFEngine; -import org.apache.tools.ant.BuildException; import java.util.Iterator; +import java.util.Hashtable; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; + +import org.apache.tools.ant.util.ReflectUtil; import org.apache.tools.ant.util.ScriptRunnerBase; /** @@ -43,27 +48,39 @@ public class ScriptRunner extends ScriptRunnerBase { private BSFEngine engine; private BSFManager manager; + /** + * Get the name of the manager prefix. + * @return "bsf" + */ + public String getManagerName() { + return "bsf"; + } + /** * Check if bsf supports the language. * @return true if bsf can create an engine for this language. */ public boolean supportsLanguage() { - if (manager != null) { - return true; + Hashtable table = (Hashtable) ReflectUtil.getField( + new BSFManager(), "registeredEngines"); + String engineClassName = (String) table.get(getLanguage()); + if (engineClassName == null) { + getProject().log( + "This is no BSF engine class for language '" + + getLanguage() + "'", + Project.MSG_VERBOSE); + return false; } - checkLanguage(); - ClassLoader origLoader = replaceContextLoader(); try { - BSFManager m = createManager(); - BSFEngine e = - engine != null - ? engine - : m.loadScriptingEngine(getLanguage()); - return e != null; - } catch (Exception ex) { + getScriptClassLoader().loadClass(engineClassName); + return true; + } catch (Throwable ex) { + getProject().log( + "unable to create BSF engine class for language '" + + getLanguage() + "'", + ex, + Project.MSG_VERBOSE); return false; - } finally { - restoreContextLoader(origLoader); } }