1 | /*
|
---|
2 | * Copyright 2000-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.optional;
|
---|
18 |
|
---|
19 | import java.io.File;
|
---|
20 | import org.apache.tools.ant.BuildException;
|
---|
21 | import org.apache.tools.ant.Task;
|
---|
22 | import org.apache.tools.ant.util.ScriptRunner;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Executes a script.
|
---|
26 | *
|
---|
27 | * @ant.task name="script"
|
---|
28 | */
|
---|
29 | public class Script extends Task {
|
---|
30 |
|
---|
31 | private String language;
|
---|
32 | private File src;
|
---|
33 | private String text;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Do the work.
|
---|
37 | *
|
---|
38 | * @exception BuildException if something goes wrong with the build
|
---|
39 | */
|
---|
40 | public void execute() throws BuildException {
|
---|
41 | ScriptRunner runner = new ScriptRunner();
|
---|
42 | if (language != null) {
|
---|
43 | runner.setLanguage(language);
|
---|
44 | }
|
---|
45 | if (src != null) {
|
---|
46 | runner.setSrc(src);
|
---|
47 | }
|
---|
48 | if (text != null) {
|
---|
49 | runner.addText(text);
|
---|
50 | }
|
---|
51 |
|
---|
52 | runner.addBeans(getProject().getProperties());
|
---|
53 | runner.addBeans(getProject().getUserProperties());
|
---|
54 | runner.addBeans(getProject().getTargets());
|
---|
55 | runner.addBeans(getProject().getReferences());
|
---|
56 |
|
---|
57 | runner.addBean("project", getProject());
|
---|
58 | runner.addBean("self", this);
|
---|
59 |
|
---|
60 | runner.executeScript("ANT");
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Defines the language (required).
|
---|
65 | *
|
---|
66 | * @param language the scripting language name for the script.
|
---|
67 | */
|
---|
68 | public void setLanguage(String language) {
|
---|
69 | this.language = language;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Load the script from an external file ; optional.
|
---|
74 | *
|
---|
75 | * @param fileName the name of the file containing the script source.
|
---|
76 | */
|
---|
77 | public void setSrc(String fileName) {
|
---|
78 | this.src = new File(fileName);
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Set the script text.
|
---|
83 | *
|
---|
84 | * @param text a component of the script text to be added.
|
---|
85 | */
|
---|
86 | public void addText(String text) {
|
---|
87 | this.text = text;
|
---|
88 | }
|
---|
89 | }
|
---|