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.

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 ...

Get Maven: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.