ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject svn commit: r481961 - in /ant/core/trunk/src/main/org/apache/tools/ant/util: ScriptRunnerBase.java optional/ScriptRunner.java
Date Sun, 03 Dec 2006 22:49:32 GMT
Author: peterreilly
Date: Sun Dec  3 14:49:29 2006
New Revision: 481961

URL: http://svn.apache.org/viewvc?view=rev&rev=481961
Log:
change supportslanguge method

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java?view=diff&rev=481961&r1=481960&r2=481961
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java Sun Dec  3 14:49:29
2006
@@ -126,6 +126,13 @@
     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.
      */
@@ -214,6 +221,22 @@
      */
     public void clearScript() {
         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;
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java?view=diff&rev=481961&r1=481960&r2=481961
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/optional/ScriptRunner.java Sun Dec 
3 14:49:29 2006
@@ -21,9 +21,14 @@
 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;
 
 /**
@@ -44,26 +49,38 @@
     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);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message