Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Fixes an issue with nested groups when using . as a group separator.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Aug 11, 2023
1 parent a5d8291 commit f15d782
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -528,8 +529,8 @@ protected void writeElements(ModelView view, List<GroupableElement> 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
Expand Down Expand Up @@ -563,7 +564,7 @@ protected void writeElements(ModelView view, List<GroupableElement> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Diagram> 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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@startuml
set separator none
title System Landscape

top to bottom direction

!include <C4/C4>
!include <C4/C4_Context>

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

0 comments on commit f15d782

Please sign in to comment.