Wiki

Clone wiki

autodoc / Writing a plugin

Writing an input plugin for Autodoc is pretty easy; you can use validation plugin as a quickstart to customize on.

Writing the plugin class

public class ValidationPlugin extends net.riccardocossu.autodoc.base.BaseAbstractPlugin implements
        net.riccardocossu.autodoc.base.AnnotationsPlugin { 
  • Provide a list of the annotation classes your plugin is able to parse
  • Write reasonable implementations for isFieldUseful, isMethodUseful and isClassUseful methods (for example for JPA only class annotated in a certain way are to parsed, while validation is usually triggered by an annotation on either a field or a method)
  • Define a unique short name (it identifies the plugin in many places)
  • Write a small method for every type of annotation the plugin is able to parse, to tell the undelying engine which properties should be considered for that specific annotation

(Optional) Support short name reference

Normally the plugins should be called by fully classified class name, but if you add a file called /META-INF/services/net.riccardocossu.autodoc.base.AnnotationsPlugin, with a line containing a FQCN for each plugin you define (standard Service provider pattern). Example:

net.riccardocossu.autodoc.validation.ValidationPlugin

Add the plugin to your build

<plugins>
    <plugin>
        <groupId>net.riccardocossu.autodoc</groupId>
        <artifactId>autodoc-maven-plugin</artifactId>
        <version>1.0.0</version>
        <dependencies>
            <dependency>
                <groupId>net.riccardocossu.autodoc</groupId>
                <artifactId>autodoc-validation-plugin</artifactId>
                <version>0.2.0</version>
            </dependency>
        </dependencies>
        <configuration>
            <outputDirectory>${project.build.directory}</outputDirectory>
            <packages>
                <!-- list of plugins to parse -->
                <param>fully.qualified.package.name</param>
            </packages>
            <inputPlugins>
                <!-- fully classified name of needed plugin; JPA plugin is for JPA2 annotations -->
                <param>JPA</param>
                <param>VALIDATION</param>
            </inputPlugins>
            <outputPlugins>
                <!-- output plugin are supposed to write to files; for example, this is the html output plugin -->
                <param>net.riccardocossu.autodoc.html.HtmlOutputPlugin</param>
            </outputPlugins>
        </configuration>
        <executions>
            <execution>
                <phase>process-classes</phase>
                <goals>
                    <goal>parse</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    ...
</plugins>

(Optional) Let me know you created a new plugin

I will be glad to hear it; please drop me an email at riccardo dot cossu at gmail dot com !

Updated