From 2287849430af65240f6c8c1d0e95612e82add6f7 Mon Sep 17 00:00:00 2001 From: Jan Materne Date: Fri, 12 Sep 2003 14:15:17 +0000 Subject: [PATCH] Link to documentation of "JavaAdapter". How to import classes outside of "java" namespace. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275228 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/OptionalTasks/script.html | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/manual/OptionalTasks/script.html b/docs/manual/OptionalTasks/script.html index f2147d391..3ef8a12ef 100644 --- a/docs/manual/OptionalTasks/script.html +++ b/docs/manual/OptionalTasks/script.html @@ -9,14 +9,14 @@

Script

Description

-

Execute a script in a +

Execute a script in a Apache BSF supported language.

Note: This task depends on external libraries not included in the Ant distribution. See Library Dependencies for more information.

All items (tasks, targets, etc) of the running project are accessible from the script, using either their name or id attributes (as long as their names are considered -valid Java identifiers, that is). +valid Java identifiers, that is). The name "project" is a pre-defined reference to the Project, which can be used instead of the project name. The name "self" is a pre-defined reference to the actual <script>-Task instance.
From these objects you have access to the Ant Java API, see the @@ -26,6 +26,15 @@ used instead of the project name. The name "self" is a pre-defined reference to

If you are using JavaScript a good resource is http://www.mozilla.org/rhino/doc.html as we are using their JavaScript interpreter.

Scripts can do almost anything a task written in Java could do.

+

Rhino provides a special construct - the JavaAdapter. Whith that you can +create an object which implements several interfaces, extends classes and for which you +can overwrite methods. Because this is an undocumented feature (yet), here is the link +to an explanation: +Groups@Google: "Rhino, enum.js, JavaAdapter?" by Norris Boyd in the newsgroup +netscape.public.mozilla.jseng.

+ + +

Parameters

@@ -178,7 +187,12 @@ filesizes of all files a <fileset/> caught.

We want to use the Java API. Because we donīt want always typing the package signature we do an import. Rhino knows to different methods for import statements: one for packages -and one for a single class.
+and one for a single class. By default only the java packages are available, so +java.lang.System can be directly imported with importClass/importPackage. +For other packages you have to prefix the full classified name with Package. +For example antīs FileUtil class can be imported with +importClass(Package.org.apache.tools.ant.util.FileUtils) +
The <script> task populates the Project instance under the name project, so we can use that reference. Another way is to use its given name or getting its reference from the task itself.
@@ -199,4 +213,4 @@ apropriate logging before and after invoking execute(). Reserved.

- + \ No newline at end of file