Skip to content

Commit

Permalink
plantuml: Support optional component keyword
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Fijalkowski <3066563+tfij@users.noreply.github.com>
  • Loading branch information
tfij committed Jan 2, 2024
1 parent 46d1a19 commit 39190ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static java.util.Collections.singletonList;

class PlantUmlPatterns {
private static final String COMPONENT_TYPE_FORMAT = "(component)?";
private static final String COMPONENT_NAME_GROUP_NAME = "componentName";
private static final String COMPONENT_NAME_FORMAT = "\\[" + capture(anythingBut("\\[\\]"), COMPONENT_NAME_GROUP_NAME) + "]";

Expand All @@ -46,7 +47,7 @@ class PlantUmlPatterns {
private static final String COLOR_FORMAT = "\\s*(?:#" + anyOf("\\w|/\\\\-") + "+)?";

private static final Pattern PLANTUML_COMPONENT_PATTERN = Pattern.compile(
"^\\s*" + COMPONENT_NAME_FORMAT + "\\s*" + STEREOTYPE_FORMAT + "*" + ALIAS_FORMAT + COLOR_FORMAT + "\\s*");
"^\\s*" + COMPONENT_TYPE_FORMAT + "\\s*" + COMPONENT_NAME_FORMAT + "\\s*" + STEREOTYPE_FORMAT + "*" + ALIAS_FORMAT + COLOR_FORMAT + "\\s*");

private static String capture(String pattern) {
return "(" + pattern + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,23 @@ public void ignore_database_components() {
assertThat(b.getDependencies()).isEmpty();
}

@Test
public void supports_components_declared_with_component_keyword() {
File file = TestDiagram.in(temporaryFolder)
.rawLine("component [CompA] <<..c1..>>")
.rawLine("component [Comp B] <<..c2..>> as CompB")
.dependencyFrom("CompA").to("CompB")
.write();

PlantUmlDiagram diagram = createDiagram(file);

PlantUmlComponent a = getComponentWithName("CompA", diagram);
PlantUmlComponent b = getComponentWithAlias(new Alias("CompB"), diagram);

assertThat(a.getDependencies()).containsOnly(b);
assertThat(b.getDependencies()).isEmpty();
}

private PlantUmlComponent getComponentWithName(String componentName, PlantUmlDiagram diagram) {
PlantUmlComponent component = diagram.getAllComponents().stream()
.filter(c -> c.getComponentName().asString().equals(componentName))
Expand Down

0 comments on commit 39190ba

Please sign in to comment.