Skip to content

Commit 8019a80

Browse files
committed
GH-983 - Polishing.
Make sure that adding skin parameters does not alter the existing instance's parameters. Javadoc. General polishing.
1 parent 63b4ab7 commit 8019a80

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
@@ -34,7 +34,6 @@
3434
import java.util.stream.Collectors;
3535
import java.util.stream.Stream;
3636

37-
import com.structurizr.export.plantuml.AbstractPlantUMLExporter;
3837
import org.springframework.lang.Nullable;
3938
import org.springframework.modulith.core.ApplicationModule;
4039
import org.springframework.modulith.core.ApplicationModules;
@@ -49,6 +48,7 @@
4948

5049
import com.structurizr.Workspace;
5150
import com.structurizr.export.IndentingWriter;
51+
import com.structurizr.export.plantuml.AbstractPlantUMLExporter;
5252
import com.structurizr.export.plantuml.C4PlantUMLExporter;
5353
import com.structurizr.export.plantuml.StructurizrPlantUMLExporter;
5454
import com.structurizr.model.Component;
@@ -71,6 +71,7 @@
7171
* @author Oliver Drotbohm
7272
* @author Cora Iberkleid
7373
* @author Tobias Haindl
74+
* @author Alexander Miller
7475
*/
7576
public class Documenter {
7677

@@ -563,19 +564,13 @@ private String render(ComponentView view, DiagramOptions options) {
563564
default:
564565

565566
var plantUmlExporter = new CustomizedPlantUmlExporter();
566-
addSkinParamsFromOptions(plantUmlExporter, options);
567567
plantUmlExporter.addSkinParam("componentStyle", "uml1");
568+
addSkinParamsFromOptions(plantUmlExporter, options);
568569

569570
return plantUmlExporter.export(view).getDefinition();
570571
}
571572
}
572573

573-
private void addSkinParamsFromOptions(AbstractPlantUMLExporter exporter, DiagramOptions options) {
574-
for (var skinParamEntry : options.skinParams.entrySet()) {
575-
exporter.addSkinParam(skinParamEntry.getKey(), skinParamEntry.getValue());
576-
}
577-
}
578-
579574
private String createPlantUml(DiagramOptions options) {
580575

581576
ComponentView componentView = createComponentView(options);
@@ -609,6 +604,10 @@ private void potentiallyWipeOutputFolder() {
609604
}
610605
}
611606

607+
private void addSkinParamsFromOptions(AbstractPlantUMLExporter exporter, DiagramOptions options) {
608+
options.skinParams.forEach(exporter::addSkinParam);
609+
}
610+
612611
private static Component applyBackgroundColor(ApplicationModule module,
613612
Map<ApplicationModule, Component> components,
614613
DiagramOptions options,
@@ -708,7 +707,7 @@ public static class DiagramOptions {
708707
Assert.notNull(defaultDisplayName, "Default display name must not be null!");
709708
Assert.notNull(style, "DiagramStyle must not be null!");
710709
Assert.notNull(elementsWithoutRelationships, "ElementsWithoutRelationships must not be null!");
711-
Assert.notNull(skinParams, "SkinParams must not be null!");
710+
Assert.notNull(skinParams, "Skin parameters must not be null!");
712711

713712
this.dependencyTypes = dependencyTypes;
714713
this.dependencyDepth = dependencyDepth;
@@ -808,14 +807,23 @@ public DiagramOptions withElementsWithoutRelationships(ElementsWithoutRelationsh
808807
}
809808

810809
/**
811-
* Configuration setting to add arbitrary skin parameters to the created diagrams.
810+
* Configuration setting to add arbitrary skin parameters to the created diagrams. Applies to both the UML and C4
811+
* {@link DiagramStyle styles}.
812812
*
813-
* Applies to both the UML and C4 {@link DiagramStyle styles}.
813+
* @param name must not be {@literal null} or empty.
814+
* @param value can be {@literal null}.
815+
* @return will never be {@literal null}.
816+
* @since 1.2.7, 1.3.1
814817
*/
815-
public DiagramOptions withSkinParam(String name, String value) {
816-
skinParams.put(name, value);
818+
public DiagramOptions withSkinParam(String name, @Nullable String value) {
819+
820+
Assert.hasText(name, "Name must not be null or empty!");
821+
822+
var newSkinParams = new LinkedHashMap<>(skinParams);
823+
newSkinParams.put(name, value);
824+
817825
return new DiagramOptions(dependencyTypes, dependencyDepth, exclusions, componentFilter, targetOnly,
818-
targetFileName, colorSelector, defaultDisplayName, style, elementsWithoutRelationships, skinParams);
826+
targetFileName, colorSelector, defaultDisplayName, style, elementsWithoutRelationships, newSkinParams);
819827
}
820828

821829
/**

0 commit comments

Comments
 (0)