Section 6.4. Writing a Complex Plug-in: The Logifier


6.4. Writing a Complex Plug-in: The Logifier

Now that you have written your first simple plug-in, try to write another plug-in, but this time you'll aim for something a bit more complex and useful. You are going to develop a plug-in that applies a Logging Aspect, which is defined using the AspectJ Aspect-Oriented Programming (AOP) implementation (http://www.eclipse.org/aspectj/) to any Maven project. This is a plug-in that will prove useful whenever you wish to automatically add debugging information to a Maven project's JAR. Once you've created this Logifier plug-in, you can modify it to do fancier Aspect-oriented magic, such as verifying that best practices are applied, writing a simple profiling tool, generating sequence diagrams automatically, benchmarking, etc.

6.4.1. How do I do that?

The user of the Logifier plug-in is any Maven project that generates a JAR and wishes to add logging statements around all public methods. You'll create a plug-in with the logifier:logify goal, which will apply a Logging Aspect to the project's Java .class files. The Logging Aspect will instrument the Maven project's Java .class files, adding debug calls around all public methods. The Logifier will generate a "logified" JAR containing this instrumented code, and whenever the "logified" JAR is executed, the debugging information added by the Logging Aspect will appear on the console. Figure 6-3 illustrates the Logifier plug-in and the process which you will use to "logify" a project's JAR file.

Figure 6-3. Architecture of the Logifier plug-in


To write the Logifier, you will need to complete the next few labs, which cover the following topics:


Developing a Logging Aspect

This is simple. You'll write a Logging Aspect using AspectJ. If you are new to Aspect-oriented programming, this will serve as a quick introduction. AOP is changing everything, from logging to EJBs, and now is your chance to learn.


Packaging this Aspect in the Logifier plug-in

Once you've written the Aspect, you'll assemble all the pieces in a Maven plug-in.


Writing the Logifier plug-in's plugin.jelly file

This file performs the weaving (a nice word in Aspect terminology that means to apply an Aspect) of the Logging Aspect onto the target Java .class files and generates a "logified" JAR.


Executing the plug-in

Once you are finished, you'll install the plug-in and execute it to see the Logifier in action.

Let's get started!



Maven. A Developer's Notebook
Maven: A Developers Notebook (Developers Notebooks)
ISBN: 0596007507
EAN: 2147483647
Year: 2003
Pages: 125

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net