My First Ant Logger

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.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
19
21
22
23
24
25
26
27
28
29
30
   
       
Today