Skip to content

Commit

Permalink
Adds support for imports to the Ilograph exporter (#332).
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Sep 2, 2024
1 parent 2a4eea0 commit 8dbdd78
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
- structurizr-dsl: Adds a `!relationships` keyword that can be used to find a set of relationships via an expression.
- structurizr-dsl: Adds a DSL wrapper around the `structurizr-component` component finder.
- structurizr-dsl: Adds support for local theme files to be specified via `theme` (https://github.com/structurizr/java/issues/331).
- structurizr-export: Adds support for icons to the Ilograph exporter.
- structurizr-export: Adds support for icons to the Ilograph exporter (https://github.com/structurizr/java/issues/332).
- structurizr-export: Adds support for imports to the Ilograph exporter (https://github.com/structurizr/java/issues/332).

## 2.2.0 (2nd July 2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,41 @@
*/
public class IlographExporter extends AbstractWorkspaceExporter {

public static final String ILOGRAPH_IMPORTS = "ilograph.imports";
public static final String ILOGRAPH_ICON = "ilograph.icon";

public WorkspaceExport export(Workspace workspace) {
IndentingWriter writer = new IndentingWriter();

// Ilograph imports can be specified in the form:
//
// AWS:ilograph/aws
//
// Which gets exported as:
//
// imports:
// - from: ilograph/aws
// namespace: AWS
String commaSeparatedListOfImports = workspace.getProperties().get(ILOGRAPH_IMPORTS);
if (!StringUtils.isNullOrEmpty(commaSeparatedListOfImports)) {
writer.writeLine("imports:");

String[] ilographImports = commaSeparatedListOfImports.split(",");
for (String ilographImport : ilographImports) {
String[] parts = ilographImport.split(":");
if (parts.length == 2) {
String namespace = parts[0];
String from = parts[1];

writer.writeLine("- from: " + from);
writer.indent();
writer.writeLine("namespace: " + namespace);
writer.outdent();
}
}
writer.writeLine();
}

writer.writeLine("resources:");
writer.indent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void test_BigBankPlcExample() throws Exception {
}

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

Expand All @@ -39,7 +39,7 @@ public void test_AmazonWebServicesExample() throws Exception {
}

@Test
public void test_renderCustomElements() throws Exception {
void test_renderCustomElements() {
Workspace workspace = new Workspace("Name", "Description");
Model model = workspace.getModel();

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

@Test
void test_imports() {
Workspace workspace = new Workspace("Name", "Description");
workspace.addProperty(IlographExporter.ILOGRAPH_IMPORTS, "NAMESPACE1:path1,NAMESPACE2:path2");

WorkspaceExport export = new IlographExporter().export(workspace);
assertEquals("""
imports:
- from: path1
namespace: NAMESPACE1
- from: path2
namespace: NAMESPACE2
resources:
perspectives:
- name: Static Structure
relations:""", export.getDefinition());
}

}

0 comments on commit 8dbdd78

Please sign in to comment.