diff --git a/spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java b/spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java index 33787479..f7605d83 100644 --- a/spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java +++ b/spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java @@ -34,7 +34,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; -import com.structurizr.export.plantuml.AbstractPlantUMLExporter; import org.springframework.lang.Nullable; import org.springframework.modulith.core.ApplicationModule; import org.springframework.modulith.core.ApplicationModules; @@ -49,6 +48,7 @@ import org.springframework.util.MultiValueMap; import com.structurizr.Workspace; import com.structurizr.export.IndentingWriter; +import com.structurizr.export.plantuml.AbstractPlantUMLExporter; import com.structurizr.export.plantuml.C4PlantUMLExporter; import com.structurizr.export.plantuml.StructurizrPlantUMLExporter; import com.structurizr.model.Component; @@ -71,6 +71,7 @@ import com.tngtech.archunit.core.domain.JavaClass; * @author Oliver Drotbohm * @author Cora Iberkleid * @author Tobias Haindl + * @author Alexander Miller */ public class Documenter { @@ -563,19 +564,13 @@ public class Documenter { default: var plantUmlExporter = new CustomizedPlantUmlExporter(); - addSkinParamsFromOptions(plantUmlExporter, options); plantUmlExporter.addSkinParam("componentStyle", "uml1"); + addSkinParamsFromOptions(plantUmlExporter, options); return plantUmlExporter.export(view).getDefinition(); } } - private void addSkinParamsFromOptions(AbstractPlantUMLExporter exporter, DiagramOptions options) { - for (var skinParamEntry : options.skinParams.entrySet()) { - exporter.addSkinParam(skinParamEntry.getKey(), skinParamEntry.getValue()); - } - } - private String createPlantUml(DiagramOptions options) { ComponentView componentView = createComponentView(options); @@ -609,6 +604,10 @@ public class Documenter { } } + private void addSkinParamsFromOptions(AbstractPlantUMLExporter exporter, DiagramOptions options) { + options.skinParams.forEach(exporter::addSkinParam); + } + private static Component applyBackgroundColor(ApplicationModule module, Map components, DiagramOptions options, @@ -708,7 +707,7 @@ public class Documenter { Assert.notNull(defaultDisplayName, "Default display name must not be null!"); Assert.notNull(style, "DiagramStyle must not be null!"); Assert.notNull(elementsWithoutRelationships, "ElementsWithoutRelationships must not be null!"); - Assert.notNull(skinParams, "SkinParams must not be null!"); + Assert.notNull(skinParams, "Skin parameters must not be null!"); this.dependencyTypes = dependencyTypes; this.dependencyDepth = dependencyDepth; @@ -808,14 +807,23 @@ public class Documenter { } /** - * Configuration setting to add arbitrary skin parameters to the created diagrams. + * Configuration setting to add arbitrary skin parameters to the created diagrams. Applies to both the UML and C4 + * {@link DiagramStyle styles}. * - * Applies to both the UML and C4 {@link DiagramStyle styles}. + * @param name must not be {@literal null} or empty. + * @param value can be {@literal null}. + * @return will never be {@literal null}. + * @since 1.2.7, 1.3.1 */ - public DiagramOptions withSkinParam(String name, String value) { - skinParams.put(name, value); + public DiagramOptions withSkinParam(String name, @Nullable String value) { + + Assert.hasText(name, "Name must not be null or empty!"); + + var newSkinParams = new LinkedHashMap<>(skinParams); + newSkinParams.put(name, value); + return new DiagramOptions(dependencyTypes, dependencyDepth, exclusions, componentFilter, targetOnly, - targetFileName, colorSelector, defaultDisplayName, style, elementsWithoutRelationships, skinParams); + targetFileName, colorSelector, defaultDisplayName, style, elementsWithoutRelationships, newSkinParams); } /**