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:

If you have done this, you can add the following list of parameters via builder methods:

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+", ""));
1 list of strings (class names) is declared for parameter hideclasses
2 packages with all classes to show in the diagram are added as string list
3 parameters hideclasses and classloader are added to configuration builder
4 generator is initialized with configuration of builder
5 diagram is generated

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:

0001_general_diagram