You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2006/12/03 23:57:57 UTC

svn commit: r481972 - in /ant/core/trunk/src/main/org/apache/tools/ant/types/optional: AbstractScriptComponent.java ScriptSelector.java

Author: peterreilly
Date: Sun Dec  3 14:57:56 2006
New Revision: 481972

URL: http://svn.apache.org/viewvc?view=rev&rev=481972
Log:
use helper class, add manager attribute, add classpath

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java?view=diff&rev=481972&r1=481971&r2=481972
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java Sun Dec  3 14:57:56 2006
@@ -17,8 +17,13 @@
  */
 package org.apache.tools.ant.types.optional;
 
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectComponent;
-import org.apache.tools.ant.util.optional.ScriptRunner;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.util.ScriptRunnerBase;
+import org.apache.tools.ant.util.ScriptRunnerHelper;
+
 
 import java.io.File;
 
@@ -28,15 +33,30 @@
  */
 public abstract class AbstractScriptComponent extends ProjectComponent {
     /**
-     * script runner
+     * script runner helper
+     */
+    private ScriptRunnerHelper helper = new ScriptRunnerHelper();
+
+    /**
+     * script runner.
+     */
+    private ScriptRunnerBase   runner = null;
+
+    /**
+     * Set the project.
+     * @param project the owner of this component.
      */
-    private ScriptRunner runner = new ScriptRunner();
+    public void setProject(Project project) {
+        super.setProject(project);
+        helper.setProjectComponent(this);
+    }
 
     /**
      * Get our script runner
      * @return the runner
      */
-    public ScriptRunner getRunner() {
+    public ScriptRunnerBase getRunner() {
+        initScriptRunner();
         return runner;
     }
 
@@ -46,7 +66,7 @@
      * @param file the file containing the script source.
      */
     public void setSrc(File file) {
-        runner.setSrc(file);
+        helper.setSrc(file);
     }
 
     /**
@@ -55,7 +75,16 @@
      * @param text a component of the script text to be added.
      */
     public void addText(String text) {
-        runner.addText(text);
+        helper.addText(text);
+    }
+
+    /**
+     * Defines the manager.
+     *
+     * @param manager the scripting manager.
+     */
+    public void setManager(String manager) {
+        helper.setManager(manager);
     }
 
     /**
@@ -64,14 +93,45 @@
      * @param language the scripting language name for the script.
      */
     public void setLanguage(String language) {
-        runner.setLanguage(language);
+        helper.setLanguage(language);
     }
 
     /**
      * Initialize the script runner. Calls this before running the system
      */
     protected void initScriptRunner() {
-        getRunner().bindToComponent(this);
+        if (runner != null) {
+            return;
+        }
+        helper.setProjectComponent(this);
+        runner = helper.getScriptRunner();
+    }
+    /**
+     * Set the classpath to be used when searching for classes and resources.
+     *
+     * @param classpath an Ant Path object containing the search path.
+     */
+    public void setClasspath(Path classpath) {
+        helper.setClasspath(classpath);
+    }
+
+    /**
+     * Classpath to be used when searching for classes and resources.
+     *
+     * @return an empty Path instance to be configured by Ant.
+     */
+    public Path createClasspath() {
+        return helper.createClasspath();
+    }
+
+    /**
+     * Set the classpath by reference.
+     *
+     * @param r a Reference to a Path instance to be used as the classpath
+     *          value.
+     */
+    public void setClasspathRef(Reference r) {
+        helper.setClasspathRef(r);
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java?view=diff&rev=481972&r1=481971&r2=481972
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java Sun Dec  3 14:57:56 2006
@@ -17,12 +17,16 @@
  */
 package org.apache.tools.ant.types.optional;
 
-import org.apache.tools.ant.types.selectors.BaseSelector;
-import org.apache.tools.ant.util.optional.ScriptRunner;
-import org.apache.tools.ant.BuildException;
-
 import java.io.File;
 
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.selectors.BaseSelector;
+import org.apache.tools.ant.util.ScriptRunnerBase;
+import org.apache.tools.ant.util.ScriptRunnerHelper;
+
 /**
  * Selector that lets you run a script with selection logic inline
  * @since Ant1.7
@@ -30,14 +34,14 @@
 public class ScriptSelector extends BaseSelector {
 
     /**
-     * Has this object been initialized ?
+     * script runner helper
      */
-    private boolean initialized = false;
+    private ScriptRunnerHelper helper = new ScriptRunnerHelper();
 
     /**
      * script runner
      */
-    private ScriptRunner runner = new ScriptRunner();
+    private ScriptRunnerBase runner;
 
     /**
      * fields updated for every selection
@@ -52,12 +56,30 @@
     private boolean selected;
 
     /**
+     * Set the project.
+     * @param project the owner of this component.
+     */
+    public void setProject(Project project) {
+        super.setProject(project);
+        helper.setProjectComponent(this);
+    }
+
+    /**
+     * Defines the manager.
+     *
+     * @param manager the scripting manager.
+     */
+    public void setManager(String manager) {
+        helper.setManager(manager);
+    }
+
+    /**
      * Defines the language (required).
      *
      * @param language the scripting language name for the script.
      */
     public void setLanguage(String language) {
-        runner.setLanguage(language);
+        helper.setLanguage(language);
     }
 
     /**
@@ -67,21 +89,19 @@
      *          if someting goes wrong
      */
     private void init() throws BuildException {
-        if (initialized) {
+        if (runner != null) {
             return;
         }
-        initialized = true;
-        runner.bindToComponent(this);
+        runner = helper.getScriptRunner();
     }
 
-
     /**
      * Load the script from an external file ; optional.
      *
      * @param file the file containing the script source.
      */
     public void setSrc(File file) {
-        runner.setSrc(file);
+        helper.setSrc(file);
     }
 
     /**
@@ -90,7 +110,49 @@
      * @param text a component of the script text to be added.
      */
     public void addText(String text) {
-        runner.addText(text);
+        helper.addText(text);
+    }
+
+    /**
+     * Set the classpath to be used when searching for classes and resources.
+     *
+     * @param classpath an Ant Path object containing the search path.
+     */
+    public void setClasspath(Path classpath) {
+        helper.setClasspath(classpath);
+    }
+
+    /**
+     * Classpath to be used when searching for classes and resources.
+     *
+     * @return an empty Path instance to be configured by Ant.
+     */
+    public Path createClasspath() {
+        return helper.createClasspath();
+    }
+
+    /**
+     * Set the classpath by reference.
+     *
+     * @param r a Reference to a Path instance to be used as the classpath
+     *          value.
+     */
+    public void setClasspathRef(Reference r) {
+        helper.setClasspathRef(r);
+    }
+
+    /**
+     * Set the setbeans attribute.
+     * If this is true, <script> will create variables in the
+     * script instance for all
+     * properties, targets and references of the current project.
+     * It this is false, only the project and self variables will
+     * be set.
+     * The default is true.
+     * @param setBeans the value to set.
+     */
+    public void setSetBeans(boolean setBeans) {
+        helper.setSetBeans(setBeans);
     }
 
     /**
@@ -116,7 +178,6 @@
         runner.executeScript("ant_selector");
         return isSelected();
     }
-
 
     /**
      * get the base directory



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