35
35
import java .util .stream .Collectors ;
36
36
import java .util .stream .Stream ;
37
37
38
+ import com .structurizr .export .plantuml .AbstractPlantUMLExporter ;
38
39
import org .springframework .lang .Nullable ;
39
40
import org .springframework .modulith .core .ApplicationModule ;
40
41
import org .springframework .modulith .core .ApplicationModuleDependency ;
@@ -565,6 +566,7 @@ private String render(ComponentView view, DiagramOptions options) {
565
566
case C4 :
566
567
567
568
var c4PlantUmlExporter = new C4PlantUMLExporter ();
569
+ addSkinParamsFromOptions (c4PlantUmlExporter , options );
568
570
var diagram = c4PlantUmlExporter .export (view );
569
571
570
572
return diagram .getDefinition ();
@@ -573,12 +575,19 @@ private String render(ComponentView view, DiagramOptions options) {
573
575
default :
574
576
575
577
var plantUmlExporter = new CustomizedPlantUmlExporter ();
578
+ addSkinParamsFromOptions (plantUmlExporter , options );
576
579
plantUmlExporter .addSkinParam ("componentStyle" , "uml1" );
577
580
578
581
return plantUmlExporter .export (view ).getDefinition ();
579
582
}
580
583
}
581
584
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
+
582
591
private String createPlantUml (DiagramOptions options ) {
583
592
584
593
ComponentView componentView = createComponentView (options );
@@ -692,6 +701,7 @@ public static class DiagramOptions {
692
701
private final Function <ApplicationModule , String > defaultDisplayName ;
693
702
private final DiagramStyle style ;
694
703
private final ElementsWithoutRelationships elementsWithoutRelationships ;
704
+ private final Map <String , String > skinParams ;
695
705
696
706
/**
697
707
* @param dependencyTypes must not be {@literal null}.
@@ -704,13 +714,15 @@ public static class DiagramOptions {
704
714
* @param defaultDisplayName must not be {@literal null}.
705
715
* @param style must not be {@literal null}.
706
716
* @param elementsWithoutRelationships must not be {@literal null}.
717
+ * @param skinParams must not be {@literal null}.
707
718
*/
708
719
DiagramOptions (Set <DependencyType > dependencyTypes , DependencyDepth dependencyDepth ,
709
720
Predicate <ApplicationModule > exclusions , Predicate <Component > componentFilter ,
710
721
Predicate <ApplicationModule > targetOnly , @ Nullable String targetFileName ,
711
722
Function <ApplicationModule , Optional <String >> colorSelector ,
712
723
Function <ApplicationModule , String > defaultDisplayName , DiagramStyle style ,
713
- ElementsWithoutRelationships elementsWithoutRelationships ) {
724
+ ElementsWithoutRelationships elementsWithoutRelationships ,
725
+ Map <String , String > skinParams ) {
714
726
715
727
Assert .notNull (dependencyTypes , "Dependency types must not be null!" );
716
728
Assert .notNull (dependencyDepth , "Dependency depth must not be null!" );
@@ -721,6 +733,7 @@ public static class DiagramOptions {
721
733
Assert .notNull (defaultDisplayName , "Default display name must not be null!" );
722
734
Assert .notNull (style , "DiagramStyle must not be null!" );
723
735
Assert .notNull (elementsWithoutRelationships , "ElementsWithoutRelationships must not be null!" );
736
+ Assert .notNull (skinParams , "SkinParams must not be null!" );
724
737
725
738
this .dependencyTypes = dependencyTypes ;
726
739
this .dependencyDepth = dependencyDepth ;
@@ -732,30 +745,31 @@ public static class DiagramOptions {
732
745
this .defaultDisplayName = defaultDisplayName ;
733
746
this .style = style ;
734
747
this .elementsWithoutRelationships = elementsWithoutRelationships ;
748
+ this .skinParams = skinParams ;
735
749
}
736
750
737
751
/**
738
752
* The {@link DependencyDepth} to define which other modules to be included in the diagram to be created.
739
753
*/
740
754
public DiagramOptions withDependencyDepth (DependencyDepth dependencyDepth ) {
741
755
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
742
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
756
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
743
757
}
744
758
745
759
/**
746
760
* A {@link Predicate} to define the which modules to exclude from the diagram to be created.
747
761
*/
748
762
public DiagramOptions withExclusions (Predicate <ApplicationModule > exclusions ) {
749
763
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
750
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
764
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
751
765
}
752
766
753
767
/**
754
768
* A {@link Predicate} to define which Structurizr {@link Component}s to be included in the diagram to be created.
755
769
*/
756
770
public DiagramOptions withComponentFilter (Predicate <Component > componentFilter ) {
757
771
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
758
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
772
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
759
773
}
760
774
761
775
/**
@@ -765,7 +779,7 @@ public DiagramOptions withComponentFilter(Predicate<Component> componentFilter)
765
779
*/
766
780
public DiagramOptions withTargetOnly (Predicate <ApplicationModule > targetOnly ) {
767
781
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
768
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
782
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
769
783
}
770
784
771
785
/**
@@ -777,15 +791,15 @@ public DiagramOptions withTargetFileName(String targetFileName) {
777
791
Assert .isTrue (targetFileName .contains ("%s" ), () -> INVALID_FILE_NAME_PATTERN .formatted (targetFileName ));
778
792
779
793
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
780
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
794
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
781
795
}
782
796
783
797
/**
784
798
* A callback to return a hex-encoded color per {@link ApplicationModule}.
785
799
*/
786
800
public DiagramOptions withColorSelector (Function <ApplicationModule , Optional <String >> colorSelector ) {
787
801
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
788
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
802
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
789
803
}
790
804
791
805
/**
@@ -794,15 +808,15 @@ public DiagramOptions withColorSelector(Function<ApplicationModule, Optional<Str
794
808
*/
795
809
public DiagramOptions withDefaultDisplayName (Function <ApplicationModule , String > defaultDisplayName ) {
796
810
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
797
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
811
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
798
812
}
799
813
800
814
/**
801
815
* Which style to render the diagram in. Defaults to {@link DiagramStyle#UML}.
802
816
*/
803
817
public DiagramOptions withStyle (DiagramStyle style ) {
804
818
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
805
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
819
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
806
820
}
807
821
808
822
/**
@@ -815,7 +829,18 @@ public DiagramOptions withStyle(DiagramStyle style) {
815
829
*/
816
830
public DiagramOptions withElementsWithoutRelationships (ElementsWithoutRelationships elementsWithoutRelationships ) {
817
831
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
818
- targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
832
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
833
+ }
834
+
835
+ /**
836
+ * Configuration setting to add arbitrary skin parameters to the created diagrams.
837
+ *
838
+ * Applies to both the UML and C4 {@link DiagramStyle styles}.
839
+ */
840
+ public DiagramOptions withSkinParam (String name , String value ) {
841
+ skinParams .put (name , value );
842
+ return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
843
+ targetFileName , colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
819
844
}
820
845
821
846
/**
@@ -828,7 +853,7 @@ public DiagramOptions withElementsWithoutRelationships(ElementsWithoutRelationsh
828
853
public static DiagramOptions defaults () {
829
854
return new DiagramOptions (ALL_TYPES , DependencyDepth .IMMEDIATE , it -> false , it -> true , it -> false , null ,
830
855
__ -> Optional .empty (), it -> it .getDisplayName (), DiagramStyle .C4 ,
831
- ElementsWithoutRelationships .HIDDEN );
856
+ ElementsWithoutRelationships .HIDDEN , new LinkedHashMap <>() );
832
857
}
833
858
834
859
/**
@@ -845,7 +870,7 @@ public DiagramOptions withDependencyTypes(DependencyType... types) {
845
870
846
871
return new DiagramOptions (dependencyTypes , dependencyDepth , exclusions , componentFilter , targetOnly ,
847
872
targetFileName ,
848
- colorSelector , defaultDisplayName , style , elementsWithoutRelationships );
873
+ colorSelector , defaultDisplayName , style , elementsWithoutRelationships , skinParams );
849
874
}
850
875
851
876
private Optional <String > getTargetFileName () {
0 commit comments