From 3fdab62d530cf4bd3d566ebbb6bf48c98a4f557b Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Mon, 9 Sep 2024 14:43:39 +0100 Subject: [PATCH] Removes deprecated `!constant` keyword. --- changelog.md | 1 + .../com/structurizr/dsl/StructurizrDslParser.java | 8 +------- .../src/test/java/com/structurizr/dsl/DslTests.java | 13 +++++++++++++ structurizr-dsl/src/test/resources/dsl/constant.dsl | 5 +++++ 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 structurizr-dsl/src/test/resources/dsl/constant.dsl diff --git a/changelog.md b/changelog.md index 51173a07..e5aec504 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ - structurizr-client: Adds support for [workspace branches](https://docs.structurizr.com/onpremises/workspace-branches) (on-premises installation only). - structurizr-core: Adds name-value properties to dynamic view relationship views (https://github.com/structurizr/java/issues/316). - structurizr-component: Initial rewrite of the original `structurizr-analysis` library - provides a way to automatically find components in a Java codebase. +- structurizr-dsl: Removes deprecated `!constant` keyword. - structurizr-dsl: Adds name-value properties to dynamic view relationship views. - structurizr-dsl: Fixes https://github.com/structurizr/java/issues/312 (!include doesn't work with files encoded as UTF-8 BOM). - structurizr-dsl: Adds a way to explicitly specify the order of relationships in dynamic views. diff --git a/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java b/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java index 4a1be28f..c0ec6c09 100644 --- a/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java +++ b/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java @@ -950,13 +950,7 @@ void parse(List lines, File dslFile, boolean fragment, boolean includeIn } } else if (CONSTANT_TOKEN.equalsIgnoreCase(firstToken)) { - log.warn("!constant has been deprecated and will be removed in a future release - please use !const or !var instead"); - NameValuePair nameValuePair = new NameValueParser().parseConstant(tokens); - - if (constantsAndVariables.containsKey(nameValuePair.getName())) { - log.warn("A constant \"" + nameValuePair.getName() + "\" already exists"); - } - constantsAndVariables.put(nameValuePair.getName(), nameValuePair); + throw new RuntimeException("!constant was previously deprecated, and has now been removed - please use !const or !var instead"); } else if (CONST_TOKEN.equalsIgnoreCase(firstToken)) { NameValuePair nameValuePair = new NameValueParser().parseConstant(tokens); diff --git a/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java b/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java index f3db3bb1..b5bc8641 100644 --- a/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java +++ b/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java @@ -1096,6 +1096,19 @@ void test_Enterprise() { } } + @Test + void test_Constant() { + File dslFile = new File("src/test/resources/dsl/constant.dsl"); + + try { + StructurizrDslParser parser = new StructurizrDslParser(); + parser.parse(dslFile); + fail(); + } catch (StructurizrDslParserException e) { + assertEquals("!constant was previously deprecated, and has now been removed - please use !const or !var instead at line 3 of " + dslFile.getAbsolutePath() + ": !constant NAME VALUE", e.getMessage()); + } + } + @Test void test_UnbalancedCurlyBraces() { try { diff --git a/structurizr-dsl/src/test/resources/dsl/constant.dsl b/structurizr-dsl/src/test/resources/dsl/constant.dsl new file mode 100644 index 00000000..714ce0d2 --- /dev/null +++ b/structurizr-dsl/src/test/resources/dsl/constant.dsl @@ -0,0 +1,5 @@ +workspace { + + !constant NAME VALUE + +} \ No newline at end of file