Configuration
Configuration options
Depending on the parameters you want to set you have three basic options to configure the PlantUMLClassDiagramGenerator for diagram generation:
-
add parameters to the constructor directly (deprecated)
-
construct a PlantUMLClassDiagramConfig object on your own and pass it into the constructor of the generator (not recommended)
-
use the PlantUMLClassDiagramConfigBuilder to build the configuration object and pass it into the constructor of the generator (recommended)
The first option with different constructor parameters only applies to the parameters
and should not be used anymore. It is deprecated and is only supported for compatibility reasons.
The second approach to fill all configuration data in an object of type PlantUMLClassDiagramConfig and pass it into the PlantUMLClassDiagramGenerator constructor is supported but should not be used, as it is not so readable than the third option via the PlantUMLClassDiagramConfigBuilder class and therefore this option is the recommended one.
Builder customization
If you construct a PlantUMLClassDiagramConfigBuilder - as recommended - , you need to choose between four constructor options:
-
define specific packages to add all classes inside these packages via the scanpackages parameter to the diagram
-
define specific packages in combination with an blacklist regular expression to add only specific classes of these packages on the classpath to the diagram
-
define a whitelist regular expression to add all classes found by this expression on the classpath to the diagram
-
define specific packages in combination with a whitelist regular expression to add only classes to the diagram which match the scan packages and the regular expression
If you have done this, you can add the following list of parameters via builder methods:
-
withClassloader
to specify the classloader to search for the classes -
addAdditionalPlantUmlConfigs
to add additional PlantUML configuration to the beginning of the generated PlantUML diagram -
addJPAAnnotations
to add JPA annotations of the classes to the diagram -
addValidationAnnotations
to add Validation annotations of the classes to the diagram -
withFieldBlacklistRegexp
to filter out fields of the shown classes in the diagram via a regular expression -
withFieldClassifierToIgnore
for a single classifier or -
withFieldClassifiersToIgnore
for multiple classifiers to filter out fields via their classifiers -
withHideClasses
to hide classes from the diagram (they are still part of the diagram but they are not rendered) -
withHideFieldsParameter
to hide all fields of the classes in the diagram (they are still part of the diagram but they are not rendered) -
withHideMethods
to hide all methods of the classes in the diagram (they are still part of the diagram but they are not rendered) -
withMaximumFieldVisibility
to filter out all fields of the classes in the diagram by their visibility in java -
withMaximumMethodVisibility
to filter out all methods of the classes in the diagram by their visibility in java -
withMethodBlacklistRegexp
to filter out methods of all classes in the diagram by a regular expression -
withMethodClassifierToIgnore
for a single classifier or
withMethodClassifiersToIgnore
for multiple classifiers to filter out methods via their classifiers -
removeFields
to remove fields completely from the diagram (they are not part of the unrendered diagram) -
removeMethods
to remove methods completely from the diagram (they are not part of the unrendered diagram) -
useShortClassNames
to shorten the class names in the diagram -
useShortClassNamesInFieldsAndMethods
to shorten the class names only in fields and methods in the diagram -
useSmetana
to activate Smetana as replacement for GraphViz/Dot for layouting
After you configured everything you can construct the PlantUMLClassDiagramConfig object via the build() method and pass this configuration as parameter to the PlantUMLClassDiagramGenerator and create the diagram text.
Builder usage example
Here is a simple example for the usage of the PlantUMLClassDiagramConfigBuilder with three parameters (scanpackages, hideClasses, destinationClassloader) retrieved from the JUnit tests:
List<String> scanPackages = new ArrayList<>();
scanPackages.add("de.elnarion.test.domain.t0001");
List<String> hideClasses = new ArrayList<>(); (1)
hideClasses.add("de.elnarion.test.domain.ChildB");
PlantUMLClassDiagramConfigBuilder configBuilder = new PlantUMLClassDiagramConfigBuilder(scanPackages) (2)
.withHideClasses(hideClasses); (3)
PlantUMLClassDiagramGenerator generator = new PlantUMLClassDiagramGenerator(configBuilder.build()); (4)
String result = generator.generateDiagramText(); (5)
String expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource("class/0001_general_diagram.txt")),
StandardCharsets.UTF_8);
assertNotNull(result);
assertNotNull(expectedDiagramText);
assertEquals(expectedDiagramText.replaceAll("\\s+", ""), result.replaceAll("\\s+", ""));
the result of this generation is
@startuml
class de.elnarion.test.domain.t0001.BaseAbstractClass {
{method} +doSomething () : void
{method} +doSomethingElse () : void
{method} +doSomethingWithParameter ( paramString1 : String ) : void
{method} +doSomethingWithReturnValue () : String
}
interface de.elnarion.test.domain.t0001.BaseInterface {
{method} {abstract} +doSomething () : void
{method} {abstract} +doSomethingWithParameter ( paramString1 : String ) : void
{method} {abstract} +doSomethingWithReturnValue () : String
}
class de.elnarion.test.domain.t0001.ChildA {
}
class de.elnarion.test.domain.t0001.ChildB {
}
class de.elnarion.test.domain.t0001.Util {
}
de.elnarion.test.domain.t0001.BaseAbstractClass ..|> de.elnarion.test.domain.t0001.BaseInterface
de.elnarion.test.domain.t0001.ChildA --|> de.elnarion.test.domain.t0001.BaseAbstractClass
de.elnarion.test.domain.t0001.ChildB --> de.elnarion.test.domain.t0001.Util : util
de.elnarion.test.domain.t0001.ChildB --|> de.elnarion.test.domain.t0001.BaseAbstractClass
hide de.elnarion.test.domain.ChildB
@enduml
which is rendered in PlantUML this way: