Skip to content

Commit 8dbdd78

Browse files
Adds support for imports to the Ilograph exporter (#332).
1 parent 2a4eea0 commit 8dbdd78

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
- structurizr-dsl: Adds a `!relationships` keyword that can be used to find a set of relationships via an expression.
1313
- structurizr-dsl: Adds a DSL wrapper around the `structurizr-component` component finder.
1414
- structurizr-dsl: Adds support for local theme files to be specified via `theme` (https://github.com/structurizr/java/issues/331).
15-
- structurizr-export: Adds support for icons to the Ilograph exporter.
15+
- structurizr-export: Adds support for icons to the Ilograph exporter (https://github.com/structurizr/java/issues/332).
16+
- structurizr-export: Adds support for imports to the Ilograph exporter (https://github.com/structurizr/java/issues/332).
1617

1718
## 2.2.0 (2nd July 2024)
1819

structurizr-export/src/main/java/com/structurizr/export/ilograph/IlographExporter.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,41 @@
1616
*/
1717
public class IlographExporter extends AbstractWorkspaceExporter {
1818

19+
public static final String ILOGRAPH_IMPORTS = "ilograph.imports";
1920
public static final String ILOGRAPH_ICON = "ilograph.icon";
2021

2122
public WorkspaceExport export(Workspace workspace) {
2223
IndentingWriter writer = new IndentingWriter();
24+
25+
// Ilograph imports can be specified in the form:
26+
//
27+
// AWS:ilograph/aws
28+
//
29+
// Which gets exported as:
30+
//
31+
// imports:
32+
// - from: ilograph/aws
33+
// namespace: AWS
34+
String commaSeparatedListOfImports = workspace.getProperties().get(ILOGRAPH_IMPORTS);
35+
if (!StringUtils.isNullOrEmpty(commaSeparatedListOfImports)) {
36+
writer.writeLine("imports:");
37+
38+
String[] ilographImports = commaSeparatedListOfImports.split(",");
39+
for (String ilographImport : ilographImports) {
40+
String[] parts = ilographImport.split(":");
41+
if (parts.length == 2) {
42+
String namespace = parts[0];
43+
String from = parts[1];
44+
45+
writer.writeLine("- from: " + from);
46+
writer.indent();
47+
writer.writeLine("namespace: " + namespace);
48+
writer.outdent();
49+
}
50+
}
51+
writer.writeLine();
52+
}
53+
2354
writer.writeLine("resources:");
2455
writer.indent();
2556

structurizr-export/src/test/java/com/structurizr/export/ilograph/IlographExporterTests.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void test_BigBankPlcExample() throws Exception {
2626
}
2727

2828
@Test
29-
public void test_AmazonWebServicesExample() throws Exception {
29+
void test_AmazonWebServicesExample() throws Exception {
3030
Workspace workspace = WorkspaceUtils.loadWorkspaceFromJson(new File("./src/test/resources/structurizr-54915-workspace.json"));
3131
workspace.getViews().getConfiguration().getStyles().addElementStyle("Amazon Web Services - Route 53").addProperty(IlographExporter.ILOGRAPH_ICON, "AWS/Networking/Route-53.svg");
3232

@@ -39,7 +39,7 @@ public void test_AmazonWebServicesExample() throws Exception {
3939
}
4040

4141
@Test
42-
public void test_renderCustomElements() throws Exception {
42+
void test_renderCustomElements() {
4343
Workspace workspace = new Workspace("Name", "Description");
4444
Model model = workspace.getModel();
4545

@@ -71,4 +71,23 @@ public void test_renderCustomElements() throws Exception {
7171
" color: \"#707070\"\n", export.getDefinition());
7272
}
7373

74+
@Test
75+
void test_imports() {
76+
Workspace workspace = new Workspace("Name", "Description");
77+
workspace.addProperty(IlographExporter.ILOGRAPH_IMPORTS, "NAMESPACE1:path1,NAMESPACE2:path2");
78+
79+
WorkspaceExport export = new IlographExporter().export(workspace);
80+
assertEquals("""
81+
imports:
82+
- from: path1
83+
namespace: NAMESPACE1
84+
- from: path2
85+
namespace: NAMESPACE2
86+
87+
resources:
88+
perspectives:
89+
- name: Static Structure
90+
relations:""", export.getDefinition());
91+
}
92+
7493
}

0 commit comments

Comments
 (0)