2
* The Apache Software License, Version 1.1
4
* Copyright (c) 1999 The Apache Software Foundation. All rights
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
11
* 1. Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
14
* 2. Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in
16
* the documentation and/or other materials provided with the
19
* 3. The end-user documentation included with the redistribution, if
20
* any, must include the following acknowlegement:
21
* "This product includes software developed by the
22
* Apache Software Foundation (http://www.apache.org/)."
23
* Alternately, this acknowlegement may appear in the software itself,
24
* if and wherever such third-party acknowlegements normally appear.
26
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
27
* Foundation" must not be used to endorse or promote products derived
28
* from this software without prior written permission. For written
29
* permission, please contact apache@apache.org.
31
* 5. Products derived from this software may not be called "Apache"
32
* nor may "Apache" appear in their names without prior written
33
* permission of the Apache Group.
35
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47
* ====================================================================
49
* This software consists of voluntary contributions made by many
50
* individuals on behalf of the Apache Software Foundation. For more
51
* information on the Apache Software Foundation, please see
52
* <http://www.apache.org/>.
55
package org.apache.tools.ant;
58
* Base class for all tasks.
60
* <p>Use {@link Project#createTask Project.createTask} to create a new Task.
63
public abstract class Task extends ProjectComponent {
65
protected Target target = null;
66
protected String description=null;
67
protected Location location = Location.UNKNOWN_LOCATION;
68
protected String taskName = null;
69
protected String taskType = null;
70
protected RuntimeConfigurable wrapper;
73
* Sets the target object of this task.
75
* @param target Target in whose scope this task belongs.
77
public void setOwningTarget(Target target) {
82
* Get the Target to which this task belongs
84
* @return the task's target.
86
public Target getOwningTarget() {
91
* Set the name to use in logging messages.
93
* @param name the name to use in logging messages.
95
public void setTaskName(String name) {
100
* Get the name to use in logging messages.
102
* @return the name to use in logging messages.
104
public String getTaskName() {
109
* Set the name with which the task has been invoked.
111
* @param type the name the task has been invoked as.
113
void setTaskType(String type) {
114
this.taskType = type;
117
/** Sets a description of the current action. It will be usefull in commenting
120
public void setDescription( String desc ) {
124
public String getDescription() {
129
* Called by the project to let the task initialize properly.
131
* @throws BuildException if someting goes wrong with the build
133
public void init() throws BuildException {}
136
* Called by the project to let the task do it's work. This method may be
137
* called more than once, if the task is invoked more than once. For example,
138
* if target1 and target2 both depend on target3, then running
139
* "ant target1 target2" will run all tasks in target3 twice.
141
* @throws BuildException if someting goes wrong with the build
143
public void execute() throws BuildException {}
146
* Returns the file location where this task was defined.
148
public Location getLocation() {
153
* Sets the file location where this task was defined.
155
public void setLocation(Location location) {
156
this.location = location;
160
* Returns the wrapper class for runtime configuration.
162
public RuntimeConfigurable getRuntimeConfigurableWrapper() {
163
if (wrapper == null) {
164
wrapper = new RuntimeConfigurable(this, getTaskName());
169
protected void setRuntimeConfigurableWrapper(RuntimeConfigurable wrapper) {
170
this.wrapper = wrapper;
174
* Configure this task - if it hasn't been done already.
176
public void maybeConfigure() throws BuildException {
177
if (wrapper != null) {
178
wrapper.maybeConfigure(project);
182
protected void handleOutput(String line) {
183
log(line, Project.MSG_INFO);
186
protected void handleErrorOutput(String line) {
187
log(line, Project.MSG_ERR);
192
* Log a message with the default (INFO) priority.
194
* @param the message to be logged.
196
public void log(String msg) {
197
log(msg, Project.MSG_INFO);
201
* Log a mesage with the give priority.
203
* @param the message to be logged.
204
* @param msgLevel the message priority at which this message is to be logged.
206
public void log(String msg, int msgLevel) {
207
project.log(this, msg, msgLevel);
213
public final void perform() {
215
project.fireTaskStarted(this);
218
project.fireTaskFinished(this, null);
220
catch(RuntimeException exc) {
221
if (exc instanceof BuildException) {
222
BuildException be = (BuildException) exc;
223
if (be.getLocation() == Location.UNKNOWN_LOCATION) {
224
be.setLocation(getLocation());
227
project.fireTaskFinished(this, exc);