Skip to content

Commit 91a64b3

Browse files
structurizr-dsl: DSL source is only stored in the JSON workspace when the DSL is deemed as "portable" (i.e. no files, plugins, scripts).
1 parent d40de39 commit 91a64b3

21 files changed

+251
-129
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## v4.2.0 (unreleased)
3+
## v5.0.0 (unreleased)
44

55
- structurizr-java: Fixes https://github.com/structurizr/java/issues/437 (Make ComponentFinder.run() not fail on empty Set<DiscoveredComponent>).
66
- structurizr-dsl: Adds support for `iconPosition` on element styles (options are `Top`, `Bottom`, `Left`).
@@ -15,6 +15,7 @@
1515
- structurizr-dsl: Adds support for a `jump` property on relationship styles.
1616
- structurizr-dsl: PlantUML, Mermaid, and Kroki image views can now be defined by an inline source block.
1717
- structurizr-dsl: Constants and variables are inherited when extending a DSL workspace.
18+
- structurizr-dsl: DSL source is only stored in the JSON workspace when the DSL is deemed as "portable" (i.e. no files, plugins, scripts).
1819
- structurizr-import: Adds support for `plantuml.inline`, `mermaid.inline`, and `kroki.inline` properties to inline the resulting PNG/SVG file into the workspace.
1920
- structurizr-inspection: Adds a way to disable inspections via a workspace property named `structurizr.inspection` (`false` to disable).
2021
- structurizr-inspection: Default inspector adds a summary of error/warning/info/ignore counts as workspace properties.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ signing.secretKeyRingFile=/some/path
55
ossrhUsername=username
66
ossrhPassword=password
77

8-
version=4.2.0
8+
version=5.0.0

structurizr-core/src/main/java/com/structurizr/AbstractWorkspace.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.structurizr;
22

33
import com.structurizr.configuration.WorkspaceConfiguration;
4+
import com.structurizr.util.StringUtils;
45

56
import java.lang.reflect.Constructor;
67
import java.util.Collections;
@@ -229,17 +230,30 @@ public Map<String, String> getProperties() {
229230
* @param value the value of the property
230231
*/
231232
public void addProperty(String name, String value) {
232-
if (name == null || name.trim().length() == 0) {
233+
if (StringUtils.isNullOrEmpty(name)) {
233234
throw new IllegalArgumentException("A property name must be specified.");
234235
}
235236

236-
if (value == null || value.trim().length() == 0) {
237+
if (StringUtils.isNullOrEmpty(value)) {
237238
throw new IllegalArgumentException("A property value must be specified.");
238239
}
239240

240241
properties.put(name, value);
241242
}
242243

244+
/**
245+
* Removes a name-value pair property from this workspace.
246+
*
247+
* @param name the name of the property to remove
248+
*/
249+
public void removeProperty(String name) {
250+
if (StringUtils.isNullOrEmpty(name)) {
251+
throw new IllegalArgumentException("A property name must be specified.");
252+
}
253+
254+
properties.remove(name);
255+
}
256+
243257
void setProperties(Map<String, String> properties) {
244258
if (properties != null) {
245259
this.properties = new HashMap<>(properties);

structurizr-dsl/src/main/java/com/structurizr/dsl/BrandingParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void parseLogo(BrandingDslContext context, Tokens tokens, boolean restricted) {
3030
if (!restricted) {
3131
File file = new File(context.getFile().getParent(), path);
3232
if (file.exists() && !file.isDirectory()) {
33+
context.setDslPortable(false);
3334
try {
3435
String dataUri = ImageUtils.getImageAsDataUri(file);
3536
context.getWorkspace().getViews().getConfiguration().getBranding().setLogo(dataUri);

structurizr-dsl/src/main/java/com/structurizr/dsl/ComponentFinderDslContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class ComponentFinderDslContext extends DslContext {
1616
this.dslParser = dslParser;
1717
this.containerDslContext = containerDslContext;
1818
componentFinderBuilder.forContainer(containerDslContext.getContainer());
19+
setDslPortable(false);
1920
}
2021

2122
@Override

structurizr-dsl/src/main/java/com/structurizr/dsl/DecisionsParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ void parse(ComponentDslContext context, File dslFile, Tokens tokens) {
4747
private void parse(DslContext context, Documentable documentable, File dslFile, Tokens tokens) {
4848
// !adrs <path>
4949

50+
context.setDslPortable(false);
51+
5052
if (tokens.hasMoreThan(TYPE_OR_FQN_INDEX)) {
5153
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
5254
}

structurizr-dsl/src/main/java/com/structurizr/dsl/DocsParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ void parse(ComponentDslContext context, File dslFile, Tokens tokens) {
3535
private void parse(DslContext context, Documentable documentable, File dslFile, Tokens tokens) {
3636
// !docs <path>
3737

38+
context.setDslPortable(false);
39+
3840
if (tokens.hasMoreThan(FQN_INDEX)) {
3941
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
4042
}

structurizr-dsl/src/main/java/com/structurizr/dsl/DslContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ abstract class DslContext {
1717

1818
private Workspace workspace;
1919
private boolean extendingWorkspace;
20+
private boolean dslPortable = true;
2021

2122
protected IdentifiersRegister identifiersRegister = new IdentifiersRegister();
2223

@@ -36,6 +37,14 @@ void setExtendingWorkspace(boolean extendingWorkspace) {
3637
this.extendingWorkspace = extendingWorkspace;
3738
}
3839

40+
boolean isDslPortable() {
41+
return dslPortable;
42+
}
43+
44+
void setDslPortable(boolean bool) {
45+
this.dslPortable = bool;
46+
}
47+
3948
void setIdentifierRegister(IdentifiersRegister identifersRegister) {
4049
this.identifiersRegister = identifersRegister;
4150
}

structurizr-dsl/src/main/java/com/structurizr/dsl/DslLine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class DslLine {
88
private final String source;
99
private final int lineNumber;
1010

11-
DslLine(String source, int lineNumber) {
12-
this.source = source;
11+
DslLine(String processedSource, int lineNumber) {
12+
this.source = processedSource;
1313
this.lineNumber = lineNumber;
1414
}
1515

structurizr-dsl/src/main/java/com/structurizr/dsl/DslUtils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ public static void setDsl(Workspace workspace, String dsl) {
4242
}
4343
}
4444

45+
/**
46+
* Clears the DSL associated with a workspace.
47+
*
48+
* @param workspace a Workspace object
49+
*/
50+
public static void clearDsl(Workspace workspace) {
51+
workspace.removeProperty(STRUCTURIZR_DSL_PROPERTY_NAME);
52+
}
53+
4554
}

0 commit comments

Comments
 (0)