From f15d782721f033b455f34f663b9bb8f59271aea5 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Fri, 11 Aug 2023 07:40:11 +0100 Subject: [PATCH] Fixes an issue with nested groups when using `.` as a group separator. --- build.gradle | 2 +- docs/changelog.md | 4 +++ .../export/AbstractDiagramExporter.java | 7 ++--- .../C4PlantUMLDiagramExporterTests.java | 19 ++++++++++++++ .../nested-groups-with-dot-separator.puml | 26 +++++++++++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/structurizr/export/plantuml/c4plantuml/nested-groups-with-dot-separator.puml diff --git a/build.gradle b/build.gradle index f03fb8c..9a57803 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ targetCompatibility = 11 description = 'Export Structurizr models and views to external formats' group = 'com.structurizr' -version = '1.16.0' +version = '1.16.1' test { useJUnitPlatform() diff --git a/docs/changelog.md b/docs/changelog.md index c36257f..977edbf 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 1.16.1 (unreleased to Maven Central) + +- Fixes an issue with nested groups when using `.` as a group separator. + ## 1.16.0 (25th July 2023) - Updated dependencies and minimum Java version (11). diff --git a/src/main/java/com/structurizr/export/AbstractDiagramExporter.java b/src/main/java/com/structurizr/export/AbstractDiagramExporter.java index 340b757..9c2202b 100644 --- a/src/main/java/com/structurizr/export/AbstractDiagramExporter.java +++ b/src/main/java/com/structurizr/export/AbstractDiagramExporter.java @@ -6,6 +6,7 @@ import com.structurizr.view.*; import java.util.*; +import java.util.regex.Pattern; import java.util.stream.Collectors; public abstract class AbstractDiagramExporter extends AbstractExporter implements DiagramExporter { @@ -528,8 +529,8 @@ protected void writeElements(ModelView view, List elements, In String context = ""; for (String group : groupsAsList) { - int groupCount = group.split(groupSeparator).length; - int contextCount = context.split(groupSeparator).length; + int groupCount = group.split(Pattern.quote(groupSeparator)).length; + int contextCount = context.split(Pattern.quote(groupSeparator)).length; if (groupCount > contextCount) { // moved from a to a/b @@ -563,7 +564,7 @@ protected void writeElements(ModelView view, List elements, In context = group; } - int contextCount = context.split(groupSeparator).length; + int contextCount = context.split(Pattern.quote(groupSeparator)).length; for (int i = 0; i < contextCount; i++) { endGroupBoundary(view, writer); diff --git a/src/test/java/com/structurizr/export/plantuml/C4PlantUMLDiagramExporterTests.java b/src/test/java/com/structurizr/export/plantuml/C4PlantUMLDiagramExporterTests.java index 3c01d30..6116af1 100644 --- a/src/test/java/com/structurizr/export/plantuml/C4PlantUMLDiagramExporterTests.java +++ b/src/test/java/com/structurizr/export/plantuml/C4PlantUMLDiagramExporterTests.java @@ -138,6 +138,25 @@ public void test_NestedGroupsExample() throws Exception { assertEquals(expected, diagram.getDefinition()); } + @Test + public void test_NestedGroupsExample_WithDotAsGroupSeparator() throws Exception { + Workspace workspace = new Workspace("Name", "Description"); + workspace.getModel().addProperty("structurizr.groupSeparator", "."); + + SoftwareSystem a = workspace.getModel().addSoftwareSystem("Team 1"); + a.setGroup("Organisation 1.Department 1.Team 1"); + + SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("SystemLandscape", "Description"); + view.addAllElements(); + + C4PlantUMLExporter exporter = new C4PlantUMLExporter(); + Collection diagrams = exporter.export(workspace); + + Diagram diagram = diagrams.stream().filter(md -> md.getKey().equals("SystemLandscape")).findFirst().get(); + String expected = readFile(new File("./src/test/java/com/structurizr/export/plantuml/c4plantuml/nested-groups-with-dot-separator.puml")); + assertEquals(expected, diagram.getDefinition()); + } + @Test public void test_renderGroupStyles() throws Exception { Workspace workspace = new Workspace("Name", "Description"); diff --git a/src/test/java/com/structurizr/export/plantuml/c4plantuml/nested-groups-with-dot-separator.puml b/src/test/java/com/structurizr/export/plantuml/c4plantuml/nested-groups-with-dot-separator.puml new file mode 100644 index 0000000..eb8787c --- /dev/null +++ b/src/test/java/com/structurizr/export/plantuml/c4plantuml/nested-groups-with-dot-separator.puml @@ -0,0 +1,26 @@ +@startuml +set separator none +title System Landscape + +top to bottom direction + +!include +!include + +AddBoundaryTag("Organisation 1", $borderColor="#cccccc", $fontColor="#cccccc") +Boundary(group_1, "Organisation 1", $tags="Organisation 1") { + AddBoundaryTag("Organisation 1.Department 1", $borderColor="#cccccc", $fontColor="#cccccc") + Boundary(group_2, "Department 1", $tags="Organisation 1.Department 1") { + AddBoundaryTag("Organisation 1.Department 1.Team 1", $borderColor="#cccccc", $fontColor="#cccccc") + Boundary(group_3, "Team 1", $tags="Organisation 1.Department 1.Team 1") { + System(Team1, "Team 1", $descr="", $tags="", $link="") + } + + } + +} + + + +SHOW_LEGEND(true) +@enduml \ No newline at end of file