Skip to content

Commit 2ddec5a

Browse files
committed
GH-989 - Polishing.
Make sure that adding skin parameters does not alter the existing instance's parameters. Javadoc. General polishing.
1 parent eed4744 commit 2ddec5a

File tree

1 file changed

+22
-14
lines changed
  • spring-modulith-docs/src/main/java/org/springframework/modulith/docs

1 file changed

+22
-14
lines changed

spring-modulith-docs/src/main/java/org/springframework/modulith/docs/Documenter.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.stream.Collectors;
3636
import java.util.stream.Stream;
3737

38-
import com.structurizr.export.plantuml.AbstractPlantUMLExporter;
3938
import org.springframework.lang.Nullable;
4039
import org.springframework.modulith.core.ApplicationModule;
4140
import org.springframework.modulith.core.ApplicationModuleDependency;
@@ -51,6 +50,7 @@
5150

5251
import com.structurizr.Workspace;
5352
import com.structurizr.export.IndentingWriter;
53+
import com.structurizr.export.plantuml.AbstractPlantUMLExporter;
5454
import com.structurizr.export.plantuml.C4PlantUMLExporter;
5555
import com.structurizr.export.plantuml.StructurizrPlantUMLExporter;
5656
import com.structurizr.model.Component;
@@ -72,6 +72,7 @@
7272
*
7373
* @author Oliver Drotbohm
7474
* @author Cora Iberkleid
75+
* @author Alexander Miller
7576
*/
7677
public class Documenter {
7778

@@ -575,19 +576,13 @@ private String render(ComponentView view, DiagramOptions options) {
575576
default:
576577

577578
var plantUmlExporter = new CustomizedPlantUmlExporter();
578-
addSkinParamsFromOptions(plantUmlExporter, options);
579579
plantUmlExporter.addSkinParam("componentStyle", "uml1");
580+
addSkinParamsFromOptions(plantUmlExporter, options);
580581

581582
return plantUmlExporter.export(view).getDefinition();
582583
}
583584
}
584585

585-
private void addSkinParamsFromOptions(AbstractPlantUMLExporter exporter, DiagramOptions options) {
586-
for (var skinParamEntry : options.skinParams.entrySet()) {
587-
exporter.addSkinParam(skinParamEntry.getKey(), skinParamEntry.getValue());
588-
}
589-
}
590-
591586
private String createPlantUml(DiagramOptions options) {
592587

593588
ComponentView componentView = createComponentView(options);
@@ -625,6 +620,10 @@ private Path recreateFile(String name) {
625620
}
626621
}
627622

623+
private void addSkinParamsFromOptions(AbstractPlantUMLExporter exporter, DiagramOptions options) {
624+
options.skinParams.forEach(exporter::addSkinParam);
625+
}
626+
628627
private static Component applyBackgroundColor(ApplicationModule module,
629628
Map<ApplicationModule, Component> components,
630629
DiagramOptions options,
@@ -733,7 +732,7 @@ public static class DiagramOptions {
733732
Assert.notNull(defaultDisplayName, "Default display name must not be null!");
734733
Assert.notNull(style, "DiagramStyle must not be null!");
735734
Assert.notNull(elementsWithoutRelationships, "ElementsWithoutRelationships must not be null!");
736-
Assert.notNull(skinParams, "SkinParams must not be null!");
735+
Assert.notNull(skinParams, "Skin parameters must not be null!");
737736

738737
this.dependencyTypes = dependencyTypes;
739738
this.dependencyDepth = dependencyDepth;
@@ -833,14 +832,23 @@ public DiagramOptions withElementsWithoutRelationships(ElementsWithoutRelationsh
833832
}
834833

835834
/**
836-
* Configuration setting to add arbitrary skin parameters to the created diagrams.
835+
* Configuration setting to add arbitrary skin parameters to the created diagrams. Applies to both the UML and C4
836+
* {@link DiagramStyle styles}.
837837
*
838-
* Applies to both the UML and C4 {@link DiagramStyle styles}.
838+
* @param name must not be {@literal null} or empty.
839+
* @param value can be {@literal null}.
840+
* @return will never be {@literal null}.
841+
* @since 1.2.7, 1.3.1
839842
*/
840-
public DiagramOptions withSkinParam(String name, String value) {
841-
skinParams.put(name, value);
843+
public DiagramOptions withSkinParam(String name, @Nullable String value) {
844+
845+
Assert.hasText(name, "Name must not be null or empty!");
846+
847+
var newSkinParams = new LinkedHashMap<>(skinParams);
848+
newSkinParams.put(name, value);
849+
842850
return new DiagramOptions(dependencyTypes, dependencyDepth, exclusions, componentFilter, targetOnly,
843-
targetFileName, colorSelector, defaultDisplayName, style, elementsWithoutRelationships, skinParams);
851+
targetFileName, colorSelector, defaultDisplayName, style, elementsWithoutRelationships, newSkinParams);
844852
}
845853

846854
/**

0 commit comments

Comments
 (0)