plantuml-generator is a project which consists of a utility module which can be used to generate PlantUML class diagrams from existing java classes and its maven plugin frontend.
With the help of this project you can generate class diagrams for your project documentation on the fly during each maven build or via the utility module.
The artifact plantuml-generator-util contains a Utility class with the name PlantUMLClassDiagramGenerator which can be used to generate a PlantUML diagram text out of existing java classes. All you have to do is:
-
to provide
-
a list of package names which should be scanned for java classes (can be filtered with a blacklist regular expression),
-
a whitelist regular expression to filter classes in the classpath of the given classloader (can be speed up with a list of package names where the classes are in)
-
-
a classloader which is able to find and read these packages/classes
-
some toggles to hide information in the resulting Plant UML class diagram.
After you created the generator object simply call the method generateDiagramText and you’ll get the Plant UML class diagram as text.
-
a list of packages to scan:
List<String> scanpackages = new ArrayList<>();
scanpackages.add("de.elnarion.test.domain.t0005");
List<String> hideClasses = new ArrayList<>();
PlantUMLClassDiagramGenerator generator =
new PlantUMLClassDiagramGenerator(this.getClass().getClassLoader(),
scanpackages,null, hideClasses, false, false);
String result = generator.generateDiagramText();-
a list of packages to scan filterd by a blacklist regular expression:
List<String> scanpackages = new ArrayList<>();
scanpackages.add("de.elnarion.test.domain.t0005");
String blacklistRegExp = ".*Child.*";
List<String> hideClasses = new ArrayList<>();
PlantUMLClassDiagramGenerator generator =
new PlantUMLClassDiagramGenerator(this.getClass().getClassLoader(),
scanpackages,blacklistRegExp, hideClasses, false, false);
String result = generator.generateDiagramText();-
a whitelist regular expression to filter the classes in the classpath:
String whitelistRegExp = ".*Child.*";
List<String> hideClasses = new ArrayList<>();
PlantUMLClassDiagramGenerator generator =
new PlantUMLClassDiagramGenerator(this.getClass().getClassLoader(),
whitelistRegExp, hideClasses, false, false,null);
String result = generator.generateDiagramText();-
a whitelist regular expression and some packages to scan to filter the classes in the classpath:
List<String> scanpackages = new ArrayList<>();
scanpackages.add("de.elnarion.test.domain.t0005");
String whitelistRegExp = ".*Child.*";
List<String> hideClasses = new ArrayList<>();
PlantUMLClassDiagramGenerator generator =
new PlantUMLClassDiagramGenerator(this.getClass().getClassLoader(),
whitelistRegExp, hideClasses, false, false,scanpackages);
String result = generator.generateDiagramText();You can use this String as input for the PlantUML tools or as part of your "living" documentation (for example with asciidoc)
To use this utility library you need to add the plantuml-generator-util.jar to your classpath.
If you use maven as build tool this is easy, just add the following dependency:
<dependency>
<groupId>de.elnarion.util</groupId>
<artifactId>plantuml-generator-util</artifactId>
<version>1.1.2</version>
</dependency>to your pom.xml
If you want to use the plantuml-generator-maven-plugin for class diagram generation, you need to configure this plugin as any normal maven plugin as part of your build and add this plugin specific configuration:
-
outputDirectory - the target folder where the diagram file is written; defaults to target/generated-docs
-
outputFilename - the file name of the diagram generated by this plugin; required
-
hideFields - simple toggle to hide field information in the Plant UML diagram; optional
-
hideMethods - simple toggle to hide method information in the Plant UML diagram; optional
-
removeFields - simple toggle to remove all field information in the Plant UML diagram; optional
-
removeMethods - simple toggle to remove all method information in the Plant UML diagram; optional
-
fieldBlacklistRegexp - a regular expression to remove special fields from the diagram; optional
-
methodBlacklistRegexp - a regular expression to remove special methods from the diagram; optional
-
maxVisibilityFields - a toggle to remove fields with a special visibility; if you set it to
-
public - only public fields will be displayed
-
protected - only public and protected fields will be displayed
-
package_private - only public, protected and package_private fields will be displayed
-
private - all fields will be displayed if not removed or ignored by other parameters
-
-
maxVisibilityMethods - a toggle to remove methods with a special visibility; if you set it to
-
public - only public methods will be displayed
-
protected - only public and protected methods will be displayed
-
package_private - only public, protected and package_private methods will be displayed
-
private - all methods will be displayed if not removed or ignored by other parameters
-
-
fieldClassifierListToIgnore - a list of classifiers which mark fields as to be ignored during the creation of the diagram
-
methodClassifierListToIgnore - a list of classifiers which mark methods as to be ignored during the creation of the diagram
-
scanPackages - a string list of all packages which should be used to generate the class diagram; required in conjunction with the blacklist regular expression and optional with the whitelist regular expression
-
whitelistRegexp - a regular expression to filter all classes in the classpath which should be part of the diagram (processing can be speed up with the scanPackages configuration); optional
if a whitelist regular expression is configured the blacklist regular expression is ignored! -
blacklistRegexp - a regular expression to remove classes from the list of classes in the diagram - works only if the configuration parameter scanPackages is not empty and no whitelist regular expression is defined; optional
-
hideClasses - a string list of all classes which should be hidden in the resultign class diagram; optional
-
enableAsciidocWrapper - a boolean which defines if the generated diagram should be wrapped by an asciidoc diagram block - default is false; optional;
-
asciidocDiagramName - the name of the diagram in the asciidoc diagram block - default is outputFilename + "." + asciidocDiagramImageType;optional (only used when enableAsciidocWrapper is true);
-
asciidocDiagramImageFormat - the image format (png/svg/latex etc.) - default is png; optional (only used when enableAsciidocWrapper is true);
-
asciidocDiagramBlockDelimiter - defines the block delimiter of the asciidoc diagram block - default is "----"; optional (only used when enableAsciidocWrapper is true);
-
addJPAAnnotations - a boolean to express if JPA-annotations should be shown in the diagram; optional - Default false
-
with a simple package to scan:
<plugin>
<artifactId>plantuml-generator-maven-plugin</artifactId>
<groupId>de.elnarion.maven</groupId>
<version>1.1.2</version>
<executions>
<execution>
<id>generate-simple-diagram</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<outputFilename>testdiagram1.txt</outputFilename>
<scanPackages>
<scanPackage>
some.package.to.process
</scanPackage>
</scanPackages>
</configuration>
</execution>
</executions>
</plugin>-
with a simple package to scan reduced by a blacklist regular expression:
<plugin>
<artifactId>plantuml-generator-maven-plugin</artifactId>
<groupId>de.elnarion.maven</groupId>
<version>1.1.2</version>
<executions>
<execution>
<id>generate-simple-diagram</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<outputFilename>testdiagram1.txt</outputFilename>
<scanPackages>
<scanPackage>
some.package.to.process
</scanPackage>
</scanPackages>
<blacklistRegexp>.*TestClass.*</blacklistRegexp>
</configuration>
</execution>
</executions>
</plugin>-
with a whitelist regular expression:
<plugin>
<artifactId>plantuml-generator-maven-plugin</artifactId>
<groupId>de.elnarion.maven</groupId>
<version>1.1.2</version>
<executions>
<execution>
<id>generate-simple-diagram</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<outputFilename>testdiagram1.txt</outputFilename>
<whitelistRegexp>.*TestClass.*</whitelistRegexp>
</configuration>
</execution>
</executions>
</plugin>-
with a whitelist regular expression filtered by a list of packages to scan:
<plugin>
<artifactId>plantuml-generator-maven-plugin</artifactId>
<groupId>de.elnarion.maven</groupId>
<version>1.1.2</version>
<executions>
<execution>
<id>generate-simple-diagram</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<outputFilename>testdiagram1.txt</outputFilename>
<scanPackages>
<scanPackage>
some.package.to.process
</scanPackage>
</scanPackages>
<whitelistRegexp>.*TestClass.*</whitelistRegexp>
</configuration>
</execution>
</executions>
</plugin>-
with multiple packages to scan, some classes, all methods and all fields to hide:
<plugin>
<artifactId>plantuml-generator-maven-plugin</artifactId>
<groupId>de.elnarion.maven</groupId>
<version>1.1.2</version>
<executions>
<execution>
<id>generate-simple-diagram</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<outputDirectory>/tmp</outputDirectory>
<outputFilename>testdiagram1.txt</outputFilename>
<scanPackages>
<scanPackage>
some.package.to.process
</scanPackage>
<scanPackage>
second.package.to.process
</scanPackage>
</scanPackages>
<hideFields>true</hideFields>
<hideMethods>true</hideMethods>
<hideClasses>
<hideClass>
some.package.to.process.TestClass
</hideClass>
<hideClass>
second.package.to.process.TestClass2
</hideClass>
</hideClasses>
</configuration>
</execution>
</executions>
</plugin>-
with a whitelist regular expression wrapped as asciidoc diagram block:
<plugin>
<artifactId>plantuml-generator-maven-plugin</artifactId>
<groupId>de.elnarion.maven</groupId>
<version>1.1.2</version>
<executions>
<execution>
<id>generate-simple-diagram</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-test-sources</phase>
<configuration>
<outputFilename>testdiagram1.txt</outputFilename>
<whitelistRegexp>.*TestClass.*</whitelistRegexp>
<enableAsciidocWrapper>true</enableAsciidocWrapper>
</configuration>
</execution>
</executions>
</plugin>This software is licensed under the Apache Licence, Version 2.0. Note that plantuml-generator has several dependencies which are not licensed under the Apache License. Note that using plant-uml-generator comes without any (legal) warranties.
This project uses sematic versioning. For more information refer to semver.
This plugin has a dedicated Changelog.
Latest and greatest source of plantuml-generator can be found on GitHub. Fork it!