Script Plugin (quokka.plugin.script:0.1, namespace=script)
The Script plugin allows ad hoc targets to be written in scripting languages such as Javascript.
Built-in and optional Ant tasks may be used, in addition to any Quokka template targets.
Template Targets
| script | Executes a script |
| javascript | Executes a script using Javascript |
To use Ant optional tasks, it is necessary to add the required libraries to the ant-types project path. In general, only the dependency from Ant is required and all other dependencies will be included automatically. e.g. To use the ftp task, add the commons-net dependency from the apache.ant group and the commons.net library will be included automatically.
To use a Quokka template target, you must declare the plugin as a dependency and declare the templates you're using via the templates attribute. You can then define properties and call quokka.execute to run the template instance.
The following example shows how to run a javascript script that a uses built-in ant task, and optional ant task and a quokka plugin template.
<dependency group="apache.ant" name="commons-net" version="1.7.1" paths="ant-types"/>
<plugin group="quokka.plugin.fop" version="?" templates="transform"/>
<plugin group="quokka.plugin.script" version="?">
<target name="myscript" template="javascript">
<property name="script"><![CDATA[
// Example of built-in tasks (echo)
for (i=1; i<=10; i++) {
echo = project.createTask("echo");
echo.setMessage(i*i);
echo.perform();
}
// Example of optional Ant task (ftp) - dependencies are added to ant-types
ftp = project.createTask("ftp")
ftp.setUserid("ftp.crap.com")
// Example of using a a quokka plugin (fop) - the plugin and template must be declared
props = new java.util.Properties()
props.put("in","src/fop/fo.xml")
props.put("out","${q.project.targetDir}/fop/fo.pdf")
quokka.execute("quokka.plugin.fop", "transform", props)
]]></property>
</target>
</plugin>
The implementation uses Ant's standard scripting mechanism, so see Ant's script task for more information on accessing Ant types and tasks from a script.
Properties:
- language: Mandatory. The programming language the script is written in. Must be a supported Apache BSF or JSR 223 language
-
manager: Optional. This can have one of three values (auto, bsf or javax). The default value is auto.
-
bsf: use the BSF scripting manager to run the language.
javax: use the javax.scripting manager to run the language. (This will only work for JDK6 and higher).
auto: use the BSF engine if it exists, otherwise use the javax.scripting manager.
-
bsf: use the BSF scripting manager to run the language.
- src: Optional. The location of the script as a file, if not inline
- setBeans: Optional. This attribute controls whether to set variables for all properties, references and targets in the running script. If this attribute is false, only the "project" and "quokka" variables are set. If this attribute is true all the variables are set. The default value of this attribute is "true"
- scriptClasspath: Optional. Although strictly speaking it is optional, it is always required unless you're are running with a scripting language bundled with the JDK (at present, that's Javascript on JDK1.6+ on Linux, Windows and Solaris). The value should contain the paths that contain the necessary libraries to run the script. These include languages supported by Apache BSF, or JSR 223. The paths should be a comma separated list project and plugin paths that have a prefix of "project." and "plugin." respectively. See the javascript target below for an example.
- classpath: Optional.A comma separated list of paths for libraries you want to use within your script. Project paths should be prefixed with "project."
The Javascript template is essentially the same as the script target, just pre-configured for Javascript. As such, all the the script properties above apply. Through the use of automatic profiles it will attempt to select Javascript libraries need for your platform and JDK version (BSF and rhino for JDKs prior to 1.6, JSR 223 and rhino for 1.6 for OS X as it's not bundled, and nothing for other 1.6 platforms as it is bundled)
Default Properties
| [!java1.6]prefix.scriptClasspath | plugin.js-bsf |
| [java1.6 + !osMac]prefix.scriptClasspath | plugin.js-nodeps |
| [java1.6 + osMac]prefix.scriptClasspath | plugin.js-jsr223 |
| language | javascript |
Plugin Paths
runtime : Runtime class path
quokka.core.plugin-spi plugin-spi 0.3
apache.ant ant 1.7.1
apache.ant nodeps 1.7.1
js-bsf : Dependencies for Javascript using BSF
apache.ant bsf 1.7.1
apache.bsf bsf 2.4
apache.commons.logging logging 1.0.4
apache.ant ant 1.7.1
apache.ant launcher 1.7.1
mozilla.rhino rhino 1.6.7
js-nodeps : Dependencies for Javascript on 1.6 JDKs that have Javascript bundled
apache.ant nodeps 1.7.1
apache.ant ant 1.7.1
apache.ant launcher 1.7.1
js-jsr223 : Dependencies for Javascript using Java's scripting support (JSR 223)
java-net.scripting js-engine 20080808.0
mozilla.rhino rhino 1.6.7
apache.ant nodeps 1.7.1
apache.ant ant 1.7.1
apache.ant launcher 1.7.1