/java-to-graphviz-maven-plugin

Maven plugin for java-to-graphviz

Primary LanguageJavaBSD 2-Clause "Simplified" LicenseBSD-2-Clause

java-to-graphviz-maven-plugin

This plugin generates graphviz sources and images from java source code.

Overview

This plugin can be used to help document specific classes and interfaces of a larger software project.

It uses the java-to-graphviz tool to generate the graphviz diagrams. This diagram will read java source code, and generate graphviz 'dot' source, which can be converted to PNGs and included in the maven-generated site documentation.

The shape of the diagrams can be modified using specially-constructed comments in the source file; see the java-to-graphviz README for details.

Example pom.xml

Here's a minimal pom.xml that generates some images from java source code.

The images can be included in the javadoc by adding <img src="doc-files/Classname.png"/> tags to the javadoc.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example.contrived</groupId>
  <artifactId>contrived-web</artifactId>
  <packaging>war</packaging>
  <version>0.0.2-SNAPSHOT</version>

  <build>
    <plugins>
    
      <!-- 
        copies additional javadoc files from src/main/javadoc 
        to target/javadoc-resources ( which will also contain the generated images )
      -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-javadoc-resources</id>
            <phase>pre-site</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <resources>
                <resource>
                  <directory>src/main/javadoc</directory>
                </resource>
              </resources>
              <outputDirectory>${basedir}/target/javadoc-resources</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- 
        generate graphviz diagrams and images
      -->
      <plugin>
        <groupId>com.randomnoun.maven.plugins</groupId>
        <artifactId>java-to-graphviz-maven-plugin</artifactId>
        <version>1.0.3</version>
        <executions>
          <execution>
            <id>java-to-graphviz</id>
            <phase>pre-site</phase>
            <goals>
              <goal>java-to-graphviz</goal>
            </goals>
            <configuration>
              <fileset>
                <includes>
                  <include>com/example/contrived/web/action/**.java</include>
                </includes>
                <directory>${project.basedir}/src/main/java</directory>
              </fileset>
              <outputDirectory>${project.basedir}/target/javadoc-resources</outputDirectory>
              <outputFilenamePattern>{directory}/doc-files/{basename}.dot</outputFilenamePattern>
              <invokeGraphviz>true</invokeGraphviz>
              <graphvizExecutable>C:\Program Files (x86)\Graphviz2.38\bin\dot.exe</graphvizExecutable>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>

  </build>

  <reporting>
    <plugins>

      <!-- 
        site javadoc
        note javadocDirectory here is the target/javadoc-resources directory written to above
        which also includes src/main/javadoc
      -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.3.1</version>
        <configuration>
          <source>11</source>
          <failOnError>false</failOnError>
          <stylesheetfile>${project.basedir}/target/javadoc/stylesheet.css</stylesheetfile>
          <javadocDirectory>${project.basedir}/target/javadoc-resources</javadocDirectory>

          <docfilessubdirs>true</docfilessubdirs>
          <author>true</author>
          <linksource>true</linksource>
          <doclint>none</doclint>
        </configuration>
        <reportSets>
          <reportSet>
            <reports>
              <report>javadoc</report>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>

    </plugins>
  </reporting>

</project>

Is there a blog article about this project ?

Yes there is: http://www.randomnoun.com/wp/2021/12/11/flowcharts-r-us/

Licensing

java-to-graphviz-maven-plugin is licensed under the BSD 2-clause license.