Ejemplo n.º 1
0
  /**
   * Fired when a task starts building, this pushes a timed element for the task onto the stack of
   * elements for the current thread, remembering the current time and the name of the task.
   *
   * @param event An event with any relevant extra information. Will not be <code>null</code>.
   */
  public void taskStarted(BuildEvent event) {
    TimedElement taskElement = new TimedElement();
    taskElement.startTime = System.currentTimeMillis();
    taskElement.element = doc.createElement(TASK_TAG);

    Task task = event.getTask();
    String name = event.getTask().getTaskName();
    if (name == null) {
      name = "";
    }
    taskElement.element.setAttribute(NAME_ATTR, name);
    taskElement.element.setAttribute(LOCATION_ATTR, event.getTask().getLocation().toString());
    tasks.put(task, taskElement);
    getStack().push(taskElement);
  }
Ejemplo n.º 2
0
 /**
  * Fired when a task finishes building, this adds the time taken and any error stacktrace to the
  * appropriate task element in the log.
  *
  * @param event An event with any relevant extra information. Will not be <code>null</code>.
  */
 public void taskFinished(BuildEvent event) {
   Task task = event.getTask();
   TimedElement taskElement = (TimedElement) tasks.get(task);
   if (taskElement != null) {
     long totalTime = System.currentTimeMillis() - taskElement.startTime;
     // taskElement.element.setAttribute(TIME_ATTR,
     // DefaultLogger.formatTime(totalTime));
     Target target = task.getOwningTarget();
     TimedElement targetElement = null;
     if (target != null) {
       targetElement = (TimedElement) targets.get(target);
     }
     if (targetElement == null) {
       buildElement.element.appendChild(taskElement.element);
     } else {
       targetElement.element.appendChild(taskElement.element);
     }
     Stack threadStack = getStack();
     if (!threadStack.empty()) {
       TimedElement poppedStack = (TimedElement) threadStack.pop();
       if (poppedStack != taskElement) {
         throw new RuntimeException(
             "Mismatch - popped element = "
                 + poppedStack
                 + " finished task element = "
                 + taskElement);
       }
     }
     tasks.remove(task);
   } else {
     throw new RuntimeException("Unknown task " + task + " not in " + tasks);
   }
 }
Ejemplo n.º 3
0
  /**
   * Fired when a message is logged, this adds a message element to the most appropriate parent
   * element (task, target or build) and records the priority and text of the message.
   *
   * @param event An event with any relevant extra information. Will not be <code>null</code>.
   */
  public void messageLogged(BuildEvent event) {

    if (buildElement == null) {
      buildElement = new TimedElement();
      buildElement.startTime = System.currentTimeMillis();
      buildElement.element = doc.createElement(BUILD_TAG);
    }
    int priority = event.getPriority();
    if (priority > msgOutputLevel) {
      return;
    }
    Element messageElement = doc.createElement(MESSAGE_TAG);

    String name = "debug";
    switch (event.getPriority()) {
      case MSG_ERR:
        name = "error";
        break;
      case MSG_WARN:
        name = "warn";
        break;
      case MSG_INFO:
        name = "info";
        break;
      default:
        name = "debug";
        break;
    }
    messageElement.setAttribute(PRIORITY_ATTR, name);

    Throwable ex = event.getException();
    if (MSG_DEBUG <= msgOutputLevel && ex != null) {
      Text errText = doc.createCDATASection(StringUtils.getStackTrace(ex));
      Element stacktrace = doc.createElement(STACKTRACE_TAG);
      stacktrace.appendChild(errText);
      buildElement.element.appendChild(stacktrace);
    }
    Text messageText = doc.createCDATASection(event.getMessage());
    messageElement.appendChild(messageText);

    TimedElement parentElement = null;

    Task task = event.getTask();

    Target target = event.getTarget();
    if (task != null) {
      parentElement = getTaskElement(task);
    }
    if (parentElement == null && target != null) {
      parentElement = (TimedElement) targets.get(target);
    }

    /*
     * if (parentElement == null) { Stack threadStack = (Stack)
     * threadStacks.get(Thread.currentThread()); if (threadStack != null) {
     * if (!threadStack.empty()) { parentElement = (TimedElement)
     * threadStack.peek(); } } }
     */

    if (parentElement != null) {
      parentElement.element.appendChild(messageElement);
    } else {
      buildElement.element.appendChild(messageElement);
    }
  }
Ejemplo n.º 4
0
 /* (non-Javadoc)
  * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent)
  */
 public void taskStarted(BuildEvent event) {
   logger.debug("Ant Task Started: " + event.getTask().getTaskName());
 }
Ejemplo n.º 5
0
 public void taskFinished(BuildEvent event) {
   tasksFinished.add(event.getTask().getTaskName());
 }
Ejemplo n.º 6
0
 public void taskStarted(BuildEvent event) {
   tasksStarted.add(event.getTask().getTaskName());
 }