From 2f9e3c1127662cf164ce69f0a9d394fa55a542e2 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Sun, 3 Dec 2006 22:55:44 +0000 Subject: [PATCH] use helper class, add manager attribute git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@481970 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/optional/Script.java | 68 ++++++++----------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Script.java b/src/main/org/apache/tools/ant/taskdefs/optional/Script.java index 53f97d56b..74930f2d9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Script.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Script.java @@ -19,9 +19,9 @@ package org.apache.tools.ant.taskdefs.optional; import java.io.File; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.tools.ant.util.optional.ScriptRunner; -import org.apache.tools.ant.util.ScriptRunnerBase; +import org.apache.tools.ant.util.ScriptRunnerHelper; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; @@ -32,40 +32,33 @@ import org.apache.tools.ant.types.Reference; */ public class Script extends Task { - private Path classpath; - private String language; - private File src; - private String text; - private boolean setBeans = true; + private ScriptRunnerHelper helper = new ScriptRunnerHelper(); /** - * Do the work. + * Set the project. + * @param project the project that this task belongs to. + */ + public void setProject(Project project) { + super.setProject(project); + helper.setProjectComponent(this); + } + + /** + * Run the script using the helper object. * * @exception BuildException if something goes wrong with the build */ public void execute() throws BuildException { - ScriptRunnerBase runner = new ScriptRunner(); - if (language != null) { - runner.setLanguage(language); - } - if (src != null) { - runner.setSrc(src); - } - if (text != null) { - runner.addText(text); - } - if (classpath != null) { - runner.setScriptClassLoader( - getProject().createClassLoader( - getClass().getClassLoader(), classpath)); - } - if (setBeans) { - runner.bindToComponent(this); - } else { - runner.bindToComponentMinimum(this); - } + helper.getScriptRunner().executeScript("ANT"); + } - runner.executeScript("ANT"); + /** + * Defines the manager. + * + * @param manager the scripting manager. + */ + public void setManager(String manager) { + helper.setManager(manager); } /** @@ -74,7 +67,7 @@ public class Script extends Task { * @param language the scripting language name for the script. */ public void setLanguage(String language) { - this.language = language; + helper.setLanguage(language); } /** @@ -83,7 +76,7 @@ public class Script extends Task { * @param fileName the name of the file containing the script source. */ public void setSrc(String fileName) { - this.src = new File(fileName); + helper.setSrc(new File(fileName)); } /** @@ -92,7 +85,7 @@ public class Script extends Task { * @param text a component of the script text to be added. */ public void addText(String text) { - this.text = text; + helper.addText(text); } /** @@ -101,7 +94,7 @@ public class Script extends Task { * @param classpath an Ant Path object containing the search path. */ public void setClasspath(Path classpath) { - createClasspath().append(classpath); + helper.setClasspath(classpath); } /** @@ -110,10 +103,7 @@ public class Script extends Task { * @return an empty Path instance to be configured by Ant. */ public Path createClasspath() { - if (this.classpath == null) { - this.classpath = new Path(getProject()); - } - return this.classpath.createPath(); + return helper.createClasspath(); } /** @@ -123,7 +113,7 @@ public class Script extends Task { * value. */ public void setClasspathRef(Reference r) { - createClasspath().setRefid(r); + helper.setClasspathRef(r); } /** @@ -137,6 +127,6 @@ public class Script extends Task { * @param setBeans the value to set. */ public void setSetBeans(boolean setBeans) { - this.setBeans = setBeans; + helper.setSetBeans(setBeans); } }