-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a command to merge layout information.
- Loading branch information
1 parent
b2fd0b3
commit 71230e3
Showing
7 changed files
with
166 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.structurizr.cli; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.util.WorkspaceUtils; | ||
import org.apache.commons.cli.*; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import java.io.File; | ||
|
||
class MergeCommand extends AbstractCommand { | ||
|
||
private static final Log log = LogFactory.getLog(MergeCommand.class); | ||
|
||
public MergeCommand() { | ||
} | ||
|
||
public void run(String... args) throws Exception { | ||
Options options = new Options(); | ||
|
||
Option option = new Option("w", "workspace", true, "Path or URL to the workspace JSON file/DSL file"); | ||
option.setRequired(true); | ||
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); | ||
|
||
option = new Option("o", "output", true, "Path and name of an output file"); | ||
option.setRequired(true); | ||
options.addOption(option); | ||
|
||
CommandLineParser commandLineParser = new DefaultParser(); | ||
HelpFormatter formatter = new HelpFormatter(); | ||
|
||
String workspaceWithLayoutPath = null; | ||
String workspaceWithoutLayoutPath = null; | ||
String outputPath = null; | ||
|
||
try { | ||
CommandLine cmd = commandLineParser.parse(options, args); | ||
|
||
workspaceWithoutLayoutPath = cmd.getOptionValue("workspace"); | ||
workspaceWithLayoutPath = cmd.getOptionValue("layout"); | ||
outputPath = cmd.getOptionValue("output"); | ||
|
||
} catch (ParseException e) { | ||
log.error(e.getMessage()); | ||
formatter.setWidth(150); | ||
formatter.printHelp("merge", options); | ||
|
||
System.exit(1); | ||
} | ||
|
||
log.info("Merging layout"); | ||
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()); | ||
|
||
File outputFile = new File(outputPath); | ||
log.info(" - writing " + outputFile.getCanonicalPath()); | ||
WorkspaceUtils.saveWorkspaceToJson(workspaceWithoutLayout, outputFile); | ||
|
||
log.info(" - finished"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.structurizr.cli; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.model.Person; | ||
import com.structurizr.util.WorkspaceUtils; | ||
import com.structurizr.view.ElementView; | ||
import com.structurizr.view.SystemLandscapeView; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class MergeCommandTests { | ||
|
||
@Test | ||
public void run() throws Exception { | ||
File tmpDir = Files.createTempDirectory("structurizr").toFile(); | ||
|
||
String[] args = { | ||
"merge", | ||
"-workspace", "src/test/mergeLayout/workspace.dsl", | ||
"-layout", "src/test/mergeLayout/workspace.json", | ||
"-output", new File(tmpDir, "merged.json").getCanonicalPath() | ||
}; | ||
new MergeCommand().run(args); | ||
|
||
assertTrue(new File(tmpDir, "merged.json").exists()); | ||
|
||
Workspace workspace = WorkspaceUtils.loadWorkspaceFromJson(new File(tmpDir, "merged.json")); | ||
Person user = workspace.getModel().getPersonWithName("User"); | ||
SystemLandscapeView view = workspace.getViews().getSystemLandscapeViews().iterator().next(); | ||
ElementView elementView = view.getElementView(user); | ||
assertEquals(123, elementView.getX()); | ||
assertEquals(456, elementView.getY()); | ||
} | ||
|
||
} |
36 changes: 0 additions & 36 deletions
36
src/test/java/com/structurizr/cli/StructurizrCliApplicationTests.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
workspace { | ||
|
||
model { | ||
person "User" | ||
} | ||
|
||
views { | ||
systemLandscape "key" { | ||
include * | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"id" : 0, | ||
"name" : "Name", | ||
"description" : "Description", | ||
"properties" : { | ||
"structurizr.dsl" : "d29ya3NwYWNlIHsKCiAgICBtb2RlbCB7CiAgICAgICAgcGVyc29uICJVc2VyIgogICAgfQoKICAgIHZpZXdzIHsKICAgICAgICBzeXN0ZW1MYW5kc2NhcGUgImtleSIgewogICAgICAgICAgICBpbmNsdWRlICoKICAgICAgICB9CiAgICB9Cgp9Cg==" | ||
}, | ||
"configuration" : { }, | ||
"model" : { | ||
"people" : [ { | ||
"id" : "1", | ||
"tags" : "Element,Person", | ||
"properties" : { | ||
"structurizr.dsl.identifier" : "40722b6a-ae23-4708-85d7-410c1a2ab053" | ||
}, | ||
"name" : "User", | ||
"location" : "Unspecified" | ||
} ] | ||
}, | ||
"documentation" : { }, | ||
"views" : { | ||
"systemLandscapeViews" : [ { | ||
"key" : "key", | ||
"order" : 1, | ||
"enterpriseBoundaryVisible" : true, | ||
"elements" : [ { | ||
"id" : "1", | ||
"x" : 123, | ||
"y" : 456 | ||
} ] | ||
} ], | ||
"configuration" : { | ||
"branding" : { }, | ||
"styles" : { }, | ||
"terminology" : { } | ||
} | ||
} | ||
} |