Implementing the Logifier Build Logic

You've discovered how to write the Logging Aspect and how to bundle this Aspect as a plug-in resource. Now, you'll need to implement the plug-in logic to weave the Aspect into the Java .class files and generate a "logified" JAR.

How do I do that?

Luckily, the AspectJ framework has an iajc Ant task that can weave any Aspect onto a set of Java source files, JAR files, or Java bytecode (.class files).

In this plug-in, you'll weave the Logging Aspect onto .class files. Here's the part of your plugin.jelly file that weaves the Aspect and generates the logified JAR:

<?xml version="1.0"?>
  
<project
    xmlns:j="jelly:core"
    xmlns:ant="jelly:ant"
    xmlns:maven="jelly:maven">
  
  <goal name="logifier:compile" prereqs="java:compile">
  
               <ant:iajc 
               destDir="${maven.build.dest}">
               <ant:sourceroots>
        <ant:pathelement location="${plugin.resources}/aspect"/>
      </ant:sourceroots>
               <ant:inpath>
        <ant:pathelement location="${maven.build.dest}"/>
      </ant:inpath>
      <ant:classpath>
        <ant:path refid="maven.dependency.classpath"/>
        <ant:pathelement 
            path="${plugin.getDependencyPath('aspectj:aspectjrt')}"/>
      </ant:classpath>
    </ant:iajc>
    
  </goal>
  
  <goal name="logifier:logify" prereqs="logifier:compile,jar"
      description="Generate a logified JAR"/>
 
</project>

Tip

There is an AspectJ plug-in that you can use to weave Aspects onto your code. You should normally use it to weave Aspects. However, reusing the AspectJ plug-in from the Logifier plug-in is not possible because it has not been designed to be reused ...

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.