Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support optional component keyword in PlantUML diagram rules #1223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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) + "]";

Expand All @@ -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 + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down