Browse Source

Make Tasks aware of the name they are used as - and change the

DefaultLogger to use this name in messages.
Submitted by:	Peter Donald donaldp@mad.scientist.com


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267761 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
58fb68f483
4 changed files with 29 additions and 8 deletions
  1. +1
    -5
      src/main/org/apache/tools/ant/DefaultLogger.java
  2. +4
    -1
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  3. +1
    -0
      src/main/org/apache/tools/ant/Project.java
  4. +23
    -2
      src/main/org/apache/tools/ant/Task.java

+ 1
- 5
src/main/org/apache/tools/ant/DefaultLogger.java View File

@@ -130,11 +130,7 @@ public class DefaultLogger implements BuildListener {

// Print out the name of the task if we're in one
if (event.getTask() != null) {
String name = event.getTask().getClass().getName();
int pos = name.lastIndexOf(".");
if (pos != -1) {
name = name.substring(pos + 1);
}
String name = event.getTask().getTaskName();

String msg = "[" + name + "] ";
for (int i = 0; i < (LEFT_COLUMN_SIZE - msg.length()); i++) {


+ 4
- 1
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -116,7 +116,10 @@ public class IntrospectionHelper {
Class returnType = m.getReturnType();
Class[] args = m.getParameterTypes();

if ("setLocation".equals(name) || "setDescription".equals(name)) {
// not really user settable properties
if ("setLocation".equals(name) ||
"setDescription".equals(name) ||
"setTaskName".equals(name)) {
continue;
}


+ 1
- 0
src/main/org/apache/tools/ant/Project.java View File

@@ -400,6 +400,7 @@ public class Project {
task=taskA;
}
task.setProject(this);
task.setTaskName(taskType);
String msg = " +Task: " + taskType;
log (msg, MSG_VERBOSE);
return task;


+ 23
- 2
src/main/org/apache/tools/ant/Task.java View File

@@ -56,6 +56,8 @@ package org.apache.tools.ant;

/**
* Base class for all tasks.
*
* <p>Use {@link Project#createTask Project.createTask} to create a new Task.
*/

public abstract class Task {
@@ -64,6 +66,7 @@ public abstract class Task {
protected Target target = null;
protected String description=null;
protected Location location = Location.UNKNOWN_LOCATION;
protected String taskName = null;

/**
* Sets the project object of this task. This method is used by
@@ -80,7 +83,7 @@ public abstract class Task {
/**
* Get the Project to which this task belongs
*
* @param the task's project.
* @return the task's project.
*/
public Project getProject() {
return project;
@@ -98,12 +101,30 @@ public abstract class Task {
/**
* Get the Target to which this task belongs
*
* @param the task's target.
* @return the task's target.
*/
public Target getOwningTarget() {
return target;
}
/**
* Set the name with which the task has been invoked.
*
* @param name the name the task has been invoked as.
*/
public void setTaskName(String name) {
this.taskName = name;
}

/**
* Get the name with which the task has been invoked.
*
* @return the name the task has been invoked as.
*/
public String getTaskName() {
return taskName;
}

/**
* Log a message with the default (INFO) priority.
*


Loading…
Cancel
Save