Skip to content

Commit

Permalink
Upgrades structurizr-* to 2.1.0; provides a way to merge layout of an…
Browse files Browse the repository at this point in the history
… individual view.
  • Loading branch information
simonbrowndotje committed Mar 2, 2024
1 parent 84c5159 commit c6dab34
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ repositories {

dependencies {

implementation 'com.structurizr:structurizr-dsl:2.0.0'
implementation 'com.structurizr:structurizr-export:2.0.0'
implementation 'com.structurizr:structurizr-dsl:2.1.0'
implementation 'com.structurizr:structurizr-export:2.1.0'
implementation 'io.github.goto1134:structurizr-d2-exporter:1.5.2'
implementation 'com.structurizr:structurizr-autolayout:2.0.0'
implementation 'com.structurizr:structurizr-inspection:2.0.0'
implementation 'com.structurizr:structurizr-autolayout:2.1.0'
implementation 'com.structurizr:structurizr-inspection:2.1.0'

implementation 'commons-cli:commons-cli:1.5.0'

Expand Down
42 changes: 40 additions & 2 deletions src/main/java/com/structurizr/cli/MergeCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.structurizr.cli;

import com.structurizr.Workspace;
import com.structurizr.util.StringUtils;
import com.structurizr.util.WorkspaceUtils;
import com.structurizr.view.ModelView;
import com.structurizr.view.View;
import org.apache.commons.cli.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -22,6 +25,10 @@ public void run(String... args) throws Exception {
option.setRequired(true);
options.addOption(option);

option = new Option("v", "view", true, "Key of the view to merge layout information for");
option.setRequired(false);
options.addOption(option);

option = new Option("l", "layout", true, "Path or URL to the workspace JSON file that includes layout information");
option.setRequired(true);
options.addOption(option);
Expand All @@ -35,13 +42,15 @@ public void run(String... args) throws Exception {

String workspaceWithLayoutPath = null;
String workspaceWithoutLayoutPath = null;
String viewKey = null;
String outputPath = null;

try {
CommandLine cmd = commandLineParser.parse(options, args);

workspaceWithoutLayoutPath = cmd.getOptionValue("workspace");
workspaceWithLayoutPath = cmd.getOptionValue("layout");
viewKey = cmd.getOptionValue("view");
outputPath = cmd.getOptionValue("output");

} catch (ParseException e) {
Expand All @@ -53,15 +62,44 @@ public void run(String... args) throws Exception {
}

log.info("Merging layout");

if (StringUtils.isNullOrEmpty(viewKey)) {
log.info(" - for all views");
} else {
log.info(" - for view \"" + viewKey + "\"");
}

log.info(" - loading workspace from " + workspaceWithoutLayoutPath);
Workspace workspaceWithoutLayout = loadWorkspace(workspaceWithoutLayoutPath);

log.info(" - loading layout information from " + workspaceWithLayoutPath);
Workspace workspaceWithLayout = loadWorkspace(workspaceWithLayoutPath);

log.info(" - merging layout information");
workspaceWithoutLayout.getViews().copyLayoutInformationFrom(workspaceWithLayout.getViews());
workspaceWithoutLayout.getViews().getConfiguration().copyConfigurationFrom(workspaceWithLayout.getViews().getConfiguration());
if (StringUtils.isNullOrEmpty(viewKey)) {
workspaceWithoutLayout.getViews().copyLayoutInformationFrom(workspaceWithLayout.getViews());
workspaceWithoutLayout.getViews().getConfiguration().copyConfigurationFrom(workspaceWithLayout.getViews().getConfiguration());
} else {
View viewWithoutLayout = workspaceWithoutLayout.getViews().getViewWithKey(viewKey);
View viewWithLayout = workspaceWithLayout.getViews().getViewWithKey(viewKey);

if (viewWithoutLayout == null) {
log.info(" - \"" + viewKey + "\" does not exist in " + workspaceWithoutLayoutPath);
System.exit(1);
} else if (!(viewWithoutLayout instanceof ModelView)) {
log.info(" - \"" + viewKey + "\" is not a model view in " + workspaceWithoutLayoutPath);
System.exit(1);
}
if (viewWithLayout == null) {
log.info(" - \"" + viewKey + "\" does not exist in " + workspaceWithLayoutPath);
System.exit(1);
} else if (!(viewWithLayout instanceof ModelView)) {
log.info(" - \"" + viewKey + "\" is not a model view in " + workspaceWithLayoutPath);
System.exit(1);
}

((ModelView)viewWithoutLayout).copyLayoutInformationFrom((ModelView)viewWithLayout);
}

File outputFile = new File(outputPath);
log.info(" - writing " + outputFile.getCanonicalPath());
Expand Down

0 comments on commit c6dab34

Please sign in to comment.