Browse Source

use helper class, add manager attribute

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@481970 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
2f9e3c1127
1 changed files with 29 additions and 39 deletions
  1. +29
    -39
      src/main/org/apache/tools/ant/taskdefs/optional/Script.java

+ 29
- 39
src/main/org/apache/tools/ant/taskdefs/optional/Script.java View File

@@ -19,9 +19,9 @@ package org.apache.tools.ant.taskdefs.optional;


import java.io.File; import java.io.File;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; 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.Path;
import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Reference;


@@ -32,40 +32,33 @@ import org.apache.tools.ant.types.Reference;
*/ */
public class Script extends Task { 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 * @exception BuildException if something goes wrong with the build
*/ */
public void execute() throws BuildException { 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. * @param language the scripting language name for the script.
*/ */
public void setLanguage(String language) { 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. * @param fileName the name of the file containing the script source.
*/ */
public void setSrc(String fileName) { 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. * @param text a component of the script text to be added.
*/ */
public void addText(String text) { 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. * @param classpath an Ant Path object containing the search path.
*/ */
public void setClasspath(Path classpath) { 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. * @return an empty Path instance to be configured by Ant.
*/ */
public Path createClasspath() { 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. * value.
*/ */
public void setClasspathRef(Reference r) { 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. * @param setBeans the value to set.
*/ */
public void setSetBeans(boolean setBeans) { public void setSetBeans(boolean setBeans) {
this.setBeans = setBeans;
helper.setSetBeans(setBeans);
} }
} }

Loading…
Cancel
Save