diff --git a/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java b/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java index f1f25c838..025a57ea8 100644 --- a/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java +++ b/src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java @@ -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 @@ import java.io.File; */ 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 @@ public abstract class AbstractScriptComponent extends ProjectComponent { * @param file the file containing the script source. */ public void setSrc(File file) { - runner.setSrc(file); + helper.setSrc(file); } /** @@ -55,7 +75,16 @@ public abstract class AbstractScriptComponent extends ProjectComponent { * @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 @@ public abstract class AbstractScriptComponent extends ProjectComponent { * @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); } /** diff --git a/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java b/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java index 0a75c4490..ca28f69f5 100644 --- a/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java +++ b/src/main/org/apache/tools/ant/types/optional/ScriptSelector.java @@ -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 @@ import java.io.File; 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 @@ -51,13 +55,31 @@ public class ScriptSelector extends BaseSelector { */ 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 @@ public class ScriptSelector extends BaseSelector { * 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 @@ public class ScriptSelector extends BaseSelector { * @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); } /** @@ -117,7 +179,6 @@ public class ScriptSelector extends BaseSelector { return isSelected(); } - /** * get the base directory * @return the base directory