KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > Script


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.taskdefs.optional;
19
20 import java.io.File JavaDoc;
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.Task;
24 import org.apache.tools.ant.util.ScriptRunnerHelper;
25 import org.apache.tools.ant.types.Path;
26 import org.apache.tools.ant.types.Reference;
27
28 /**
29  * Executes a script.
30  *
31  * @ant.task name="script"
32  */

33 public class Script extends Task {
34
35     private ScriptRunnerHelper helper = new ScriptRunnerHelper();
36
37     /**
38      * Set the project.
39      * @param project the project that this task belongs to.
40      */

41     public void setProject(Project project) {
42         super.setProject(project);
43         helper.setProjectComponent(this);
44     }
45
46     /**
47      * Run the script using the helper object.
48      *
49      * @exception BuildException if something goes wrong with the build
50      */

51     public void execute() throws BuildException {
52         helper.getScriptRunner().executeScript("ANT");
53     }
54
55     /**
56      * Defines the manager.
57      *
58      * @param manager the scripting manager.
59      */

60     public void setManager(String JavaDoc manager) {
61         helper.setManager(manager);
62     }
63
64     /**
65      * Defines the language (required).
66      *
67      * @param language the scripting language name for the script.
68      */

69     public void setLanguage(String JavaDoc language) {
70         helper.setLanguage(language);
71     }
72
73     /**
74      * Load the script from an external file ; optional.
75      *
76      * @param fileName the name of the file containing the script source.
77      */

78     public void setSrc(String JavaDoc fileName) {
79         helper.setSrc(new File JavaDoc(fileName));
80     }
81
82     /**
83      * Set the script text.
84      *
85      * @param text a component of the script text to be added.
86      */

87     public void addText(String JavaDoc text) {
88         helper.addText(text);
89     }
90
91     /**
92      * Set the classpath to be used when searching for classes and resources.
93      *
94      * @param classpath an Ant Path object containing the search path.
95      */

96     public void setClasspath(Path classpath) {
97         helper.setClasspath(classpath);
98     }
99
100     /**
101      * Classpath to be used when searching for classes and resources.
102      *
103      * @return an empty Path instance to be configured by Ant.
104      */

105     public Path createClasspath() {
106         return helper.createClasspath();
107     }
108
109     /**
110      * Set the classpath by reference.
111      *
112      * @param r a Reference to a Path instance to be used as the classpath
113      * value.
114      */

115     public void setClasspathRef(Reference r) {
116         helper.setClasspathRef(r);
117     }
118
119     /**
120      * Set the setbeans attribute.
121      * If this is true, <script> will create variables in the
122      * script instance for all
123      * properties, targets and references of the current project.
124      * It this is false, only the project and self variables will
125      * be set.
126      * The default is true.
127      * @param setBeans the value to set.
128      */

129     public void setSetBeans(boolean setBeans) {
130         helper.setSetBeans(setBeans);
131     }
132 }
133
Popular Tags