destinationClassloader

Description

With this configuration option you can switch the default classloader of the diagram generator which is the classloader of the PlantUMLSequenceDiagramConfig 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 PlantUMLSequenceDiagramConfig class.

Example

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

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.test.sequence.t0004.User");
PlantUMLSequenceDiagramConfigBuilder builder = new PlantUMLSequenceDiagramConfigBuilder(User.class.getName(),
		"interaction").withClassloader(customClassLoader); (2)

PlantUMLSequenceDiagramGenerator generator = new PlantUMLSequenceDiagramGenerator(builder.build());
String expectedDiagramText = IOUtils.toString(
		Objects.requireNonNull(classLoader.getResource("sequence/0004_sequence_diagram_with_custom_classloader.txt")),
		StandardCharsets.UTF_8);

// ACT
String generatedDiagram = generator.generateDiagramText();

// ASSERT
assertAll(() -> assertNotNull(generatedDiagram), () -> assertEquals(expectedDiagramText.replaceAll("\\s+", ""),
		generatedDiagram.replaceAll("\\s+", "")));
1 create classloader
2 add classloader to configuration

which is rendered this way:

0004_sequence_diagram_with_custom_classloader_diagram

and produces this PlantUML diagram text:

@startuml

participant User
participant View
participant Controller
participant Model

activate User
	User -> View : interact
	activate View
		View -> Controller : handleEvent
		activate Controller
			Controller -> Model : manipulate
			activate Model
				Model -> View : notifyView
				activate View
					View -> Model : getData
					activate Model
						Model --> View
					deactivate Model
					View --> Model
				deactivate View
				Model --> Controller
			deactivate Model
			Controller --> View
		deactivate Controller
		View --> User
	deactivate View
deactivate User

@enduml