X

Geertjan's Blog

  • January 8, 2008

My First Ant Logger

Geertjan Wielenga
Product Manager
A "hello world" implementation of org.apache.tools.ant.module.spi.AntLogger:

  1. Create a module project.

  2. Set a dependency on a module called "Ant" and a module called "I/O APIs".

  3. Create a Java class and extend org.apache.tools.ant.module.spi.AntLogger.

  4. Override the methods interestedInSession, interestedInAllScripts, interestedInTargets, targetStarted, and targetFinished. Implement them like this:

    @Override
    public boolean interestedInSession(AntSession session) {
    return true;
    }
    @Override
    public boolean interestedInAllScripts(AntSession session) {
    return true;
    }
    @Override
    public String[] interestedInTargets(AntSession session) {
    return AntLogger.ALL_TARGETS;
    }
    @Override
    public void targetStarted(AntEvent event) {
    String name = event.getTargetName();
    event.getSession().println(name + " started!", true, null);
    }
    @Override
    public void targetFinished(AntEvent event) {
    String name = event.getTargetName();
    event.getSession().println(name + " finished!", true, null);
    }
  5. Expand the "Important Files" node. Expand the "META-INF services" node. Expand the "all services" node. Right-click org.apache.tools.ant.module.spi.AntLogger. Choose "Add New Service". Browse to your class and click OK.

  6. Install the module.

Now, whenever you run any target in the IDE, the Output window will show the messages you added above whenever the target starts and finishes. Replace "null" in those lines above with an OutputListener, and you'll then have hyperlinks on those lines. A future blog entry will discuss this.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.