destinationClassloader

Description

With this configuration option you can switch the default classloader of the diagram generator which is the classloader of the PlantUMLClassDiagramConfig class. Afterwards all classes to be added to the diagram are searched with this classloader. Sometimes if you need a more generic classloader or a customized classloader you can add it with this option and this classloader is used for all class search/load operations.

For example this option is used by the maven plugin to add all maven dependencies to the classpath.

Default value

If not specified this is the classloader of the PlantUMLClassDiagramConfig class.

Example

Here is an example from the JUnit tests using this configuration parameter:

String filename = "class/0008_classloader_test.txt";
String testClassPath = "file:///" + System.getProperty("user.dir") + "/src/test/classes/";
URL[] classesURLs = new URL[]{new URL(testClassPath)};
URLClassLoader customClassLoader = new URLClassLoader(classesURLs); (1)
customClassLoader.loadClass("de.elnarion.maven.plugin.plantuml.generator.test.domain.ChildA");
List<String> scanPackages = new ArrayList<>();
scanPackages.add("de.elnarion.maven.plugin.plantuml.generator.test.domain");
PlantUMLClassDiagramConfigBuilder configBuilder = new PlantUMLClassDiagramConfigBuilder(scanPackages)
        .withClassLoader(customClassLoader).withHideFieldsParameter(true).withHideMethods(true); (2)
PlantUMLClassDiagramGenerator generator = new PlantUMLClassDiagramGenerator(configBuilder.build());
String result = generator.generateDiagramText();
String expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource(filename)), StandardCharsets.UTF_8);
assertNotNull(result);
assertNotNull(expectedDiagramText);
assertEquals(expectedDiagramText.replaceAll("\\s+", ""), result.replaceAll("\\s+", ""));
1 create custom classloader
2 add custom classloader to the configuration

which is rendered this way:

0001_general_diagram

and produces this PlantUML diagram text:

@startuml

class de.elnarion.maven.plugin.plantuml.generator.test.domain.BaseAbstractClass {
	{method} +doSomething () : void
	{method} +doSomethingElse () : void
	{method} +doSomethingWithParameter ( paramString1 : String ) : void
	{method} +doSomethingWithReturnValue () : String
}

interface de.elnarion.maven.plugin.plantuml.generator.test.domain.BaseInterface {
	{method}  {abstract} +doSomething () : void
	{method}  {abstract} +doSomethingWithParameter ( paramString1 : String ) : void
	{method}  {abstract} +doSomethingWithReturnValue () : String
}

class de.elnarion.maven.plugin.plantuml.generator.test.domain.ChildA {
}

class de.elnarion.maven.plugin.plantuml.generator.test.domain.ChildB {
}

class de.elnarion.maven.plugin.plantuml.generator.test.domain.Util {
}

de.elnarion.maven.plugin.plantuml.generator.test.domain.BaseAbstractClass ..|>  de.elnarion.maven.plugin.plantuml.generator.test.domain.BaseInterface
de.elnarion.maven.plugin.plantuml.generator.test.domain.ChildA --|>  de.elnarion.maven.plugin.plantuml.generator.test.domain.BaseAbstractClass
de.elnarion.maven.plugin.plantuml.generator.test.domain.ChildB -->  de.elnarion.maven.plugin.plantuml.generator.test.domain.Util : util
de.elnarion.maven.plugin.plantuml.generator.test.domain.ChildB --|>  de.elnarion.maven.plugin.plantuml.generator.test.domain.BaseAbstractClass

hide fields
hide methods

@enduml