diff --git a/build.gradle b/build.gradle index 3219658..00403cb 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/src/main/java/com/structurizr/cli/MergeCommand.java b/src/main/java/com/structurizr/cli/MergeCommand.java index daea1ef..bc24f02 100644 --- a/src/main/java/com/structurizr/cli/MergeCommand.java +++ b/src/main/java/com/structurizr/cli/MergeCommand.java @@ -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; @@ -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); @@ -35,6 +42,7 @@ public void run(String... args) throws Exception { String workspaceWithLayoutPath = null; String workspaceWithoutLayoutPath = null; + String viewKey = null; String outputPath = null; try { @@ -42,6 +50,7 @@ public void run(String... args) throws Exception { workspaceWithoutLayoutPath = cmd.getOptionValue("workspace"); workspaceWithLayoutPath = cmd.getOptionValue("layout"); + viewKey = cmd.getOptionValue("view"); outputPath = cmd.getOptionValue("output"); } catch (ParseException e) { @@ -53,6 +62,13 @@ 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); @@ -60,8 +76,30 @@ public void run(String... args) throws Exception { 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());