Browse Source

use helper class, add manager attribute, add classpath

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@481972 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
a757f30ad3
2 changed files with 144 additions and 23 deletions
  1. +68
    -8
      src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java
  2. +76
    -15
      src/main/org/apache/tools/ant/types/optional/ScriptSelector.java

+ 68
- 8
src/main/org/apache/tools/ant/types/optional/AbstractScriptComponent.java View File

@@ -17,8 +17,13 @@
*/ */
package org.apache.tools.ant.types.optional; package org.apache.tools.ant.types.optional;


import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent; 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; import java.io.File;


@@ -28,15 +33,30 @@ import java.io.File;
*/ */
public abstract class AbstractScriptComponent extends ProjectComponent { 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 * Get our script runner
* @return the runner * @return the runner
*/ */
public ScriptRunner getRunner() {
public ScriptRunnerBase getRunner() {
initScriptRunner();
return runner; return runner;
} }


@@ -46,7 +66,7 @@ public abstract class AbstractScriptComponent extends ProjectComponent {
* @param file the file containing the script source. * @param file the file containing the script source.
*/ */
public void setSrc(File file) { 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. * @param text a component of the script text to be added.
*/ */
public void addText(String text) { 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. * @param language the scripting language name for the script.
*/ */
public void setLanguage(String language) { public void setLanguage(String language) {
runner.setLanguage(language);
helper.setLanguage(language);
} }


/** /**
* Initialize the script runner. Calls this before running the system * Initialize the script runner. Calls this before running the system
*/ */
protected void initScriptRunner() { 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);
} }


/** /**


+ 76
- 15
src/main/org/apache/tools/ant/types/optional/ScriptSelector.java View File

@@ -17,12 +17,16 @@
*/ */
package org.apache.tools.ant.types.optional; 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 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 * Selector that lets you run a script with selection logic inline
* @since Ant1.7 * @since Ant1.7
@@ -30,14 +34,14 @@ import java.io.File;
public class ScriptSelector extends BaseSelector { public class ScriptSelector extends BaseSelector {


/** /**
* Has this object been initialized ?
* script runner helper
*/ */
private boolean initialized = false;
private ScriptRunnerHelper helper = new ScriptRunnerHelper();


/** /**
* script runner * script runner
*/ */
private ScriptRunner runner = new ScriptRunner();
private ScriptRunnerBase runner;


/** /**
* fields updated for every selection * fields updated for every selection
@@ -51,13 +55,31 @@ public class ScriptSelector extends BaseSelector {
*/ */
private boolean selected; 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). * Defines the language (required).
* *
* @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) {
runner.setLanguage(language);
helper.setLanguage(language);
} }


/** /**
@@ -67,21 +89,19 @@ public class ScriptSelector extends BaseSelector {
* if someting goes wrong * if someting goes wrong
*/ */
private void init() throws BuildException { private void init() throws BuildException {
if (initialized) {
if (runner != null) {
return; return;
} }
initialized = true;
runner.bindToComponent(this);
runner = helper.getScriptRunner();
} }



/** /**
* Load the script from an external file ; optional. * Load the script from an external file ; optional.
* *
* @param file the file containing the script source. * @param file the file containing the script source.
*/ */
public void setSrc(File file) { 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. * @param text a component of the script text to be added.
*/ */
public void addText(String text) { 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(); return isSelected();
} }



/** /**
* get the base directory * get the base directory
* @return the base directory * @return the base directory


Loading…
Cancel
Save