diff --git a/archunit/src/main/java/com/tngtech/archunit/library/plantuml/rules/PlantUmlPatterns.java b/archunit/src/main/java/com/tngtech/archunit/library/plantuml/rules/PlantUmlPatterns.java index b1a741b05..a7ce0cfbc 100644 --- a/archunit/src/main/java/com/tngtech/archunit/library/plantuml/rules/PlantUmlPatterns.java +++ b/archunit/src/main/java/com/tngtech/archunit/library/plantuml/rules/PlantUmlPatterns.java @@ -34,6 +34,7 @@ import static java.util.Collections.singletonList; class PlantUmlPatterns { + private static final String OPTIONAL_COMPONENT_KEYWORD_FORMAT = "(?:component)?"; private static final String COMPONENT_NAME_GROUP_NAME = "componentName"; private static final String COMPONENT_NAME_FORMAT = "\\[" + capture(anythingBut("\\[\\]"), COMPONENT_NAME_GROUP_NAME) + "]"; @@ -46,7 +47,13 @@ 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*" + OPTIONAL_COMPONENT_KEYWORD_FORMAT + + "\\s*" + COMPONENT_NAME_FORMAT + + "\\s*" + STEREOTYPE_FORMAT + "*" + + ALIAS_FORMAT + + COLOR_FORMAT + + "\\s*" + ); private static String capture(String pattern) { return "(" + pattern + ")"; diff --git a/archunit/src/test/java/com/tngtech/archunit/library/plantuml/rules/PlantUmlParserTest.java b/archunit/src/test/java/com/tngtech/archunit/library/plantuml/rules/PlantUmlParserTest.java index 4ddcf9814..873d8dde4 100644 --- a/archunit/src/test/java/com/tngtech/archunit/library/plantuml/rules/PlantUmlParserTest.java +++ b/archunit/src/test/java/com/tngtech/archunit/library/plantuml/rules/PlantUmlParserTest.java @@ -437,6 +437,23 @@ public void ignores_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))