|
|
@@ -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 |
|
|
|