From db19df41c4634c8782060fafcffd8b71bb86a171 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 22 Oct 2010 15:05:13 +0000 Subject: [PATCH] improvements to 'writing tasks' tutorial by Kevin Connor Arpe git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1026358 13f79535-47bb-0310-9956-ffa450edef68 --- CONTRIBUTORS | 1 + contributors.xml | 5 ++++ docs/manual/tutorial-writing-tasks.html | 36 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index af4da3c0d..bdbab8637 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -177,6 +177,7 @@ Julian Simpson Justin Vallon Keiron Liddle Keith Visco +Kevin Connor Arpe Kevin Greiner Kevin Jackson Kevin Ross diff --git a/contributors.xml b/contributors.xml index 1c1f9643f..9b7e03251 100644 --- a/contributors.xml +++ b/contributors.xml @@ -741,6 +741,11 @@ Keith Visco + + Kevin + Connor + Arpe + Kevin Greiner diff --git a/docs/manual/tutorial-writing-tasks.html b/docs/manual/tutorial-writing-tasks.html index a50b31da4..53e33ac72 100644 --- a/docs/manual/tutorial-writing-tasks.html +++ b/docs/manual/tutorial-writing-tasks.html @@ -31,11 +31,13 @@ tasks.

  • Use the Task
  • Integration with TaskAdapter
  • Deriving from Ant's Task
  • +
  • Accessing the Task's Project
  • Attributes
  • Nested Text
  • Nested Elements
  • Our task in a little more complex version
  • Test the Task
  • +
  • Debugging
  • Resources
  • @@ -232,6 +234,18 @@ use: [helloworld] I am used in: C:\tmp\anttests\MyFirstTask\build.xml:23: + +

    Accessing the Task's Project

    +

    The parent project of your custom task may be accessed through method getProject(). However, do not call this from the custom task constructor, as the return value will be null. Later, when node attributes or text are set, or method execute() is called, the Project object is available.

    +

    Here are two useful methods from class Project: +

      +
    • String getProperty(String propertyName)
    • +
    • + String replaceProperties(String value) +
    • +
    +

    The method replaceProperties() is discussed further in section Nested Text.

    Attributes

    @@ -298,6 +312,7 @@ For that you have to provide a public void addText(String text) method.
     ...
     public class HelloWorld extends Task {
    +    private String message;
         ...
         public void addText(String text) {
             message = text;
    @@ -308,6 +323,12 @@ public class HelloWorld extends Task {
     But here properties are not resolved! For resolving properties we have to use
     Project's replaceProperties(String propname) : String method which takes the
     property name as argument and returns its value (or ${propname} if not set).

    +

    Thus, to replace properties in the nested node text, our method addText() can be written as:

    +
    +    public void addText(String text) {
    +        message = getProject().replaceProperties(text);
    +    }
    +
    @@ -735,6 +756,21 @@ C:\tmp\anttests\MyFirstTask>

    +Debugging + +

    Try running Ant with the flag -verbose. For more information, try flag -debug.

    +

    For deeper issues, you may need to run the custom task code in a Java debugger. First, get the source for Ant and build it with debugging information.

    +

    Since Ant is a large project, it can be a little tricky to set the right breakpoints. Here are two important breakpoints for version 1.8: +

    +

    +

    If you need to debug when a task attribute or the text is set, begin by debugging into method execute() of your custom task. Then set breakpoints in other methods. This will ensure the class byte-code has been loaded by the Java VM.

    + + +

    Resources

    This tutorial and its resources are available via