From 86f914a1c862b19f0a45940b6b9d82508da0ac86 Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Wed, 23 Aug 2017 10:26:16 -0700 Subject: [PATCH] Fix PT-150487597 Don't type-check values with '@' placeholders in application yaml editor --- .../ApplicationYamlASTReconciler.java | 10 ++++++-- .../ApplicationYamlReconcileEngine.java | 1 - .../boot/test/ApplicationYamlEditorTest.java | 25 +++++++++++++++++++ .../util/SimpleTextDocumentService.java | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/headless-services/boot-properties-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java b/headless-services/boot-properties-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java index 3e83117af..b45ba33ea 100644 --- a/headless-services/boot-properties-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java +++ b/headless-services/boot-properties-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlASTReconciler.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; import org.springframework.ide.vscode.boot.metadata.IndexNavigator; import org.springframework.ide.vscode.boot.metadata.PropertyInfo; @@ -265,8 +266,7 @@ public class ApplicationYamlASTReconciler implements YamlASTReconciler { private void reconcile(ScalarNode scalar, Type type) { String stringValue = scalar.getValue(); - if (!stringValue.contains("${")) { //don't check anything with ${} expressions in it as we - // don't know its actual value + if (!hasPlaceHolder(stringValue)) { //don't check anything with placeholder expressions in it ValueParser valueParser = typeUtil.getValueParser(type); if (valueParser!=null) { // Tag tag = scalar.getTag(); //use the tag? Actually, boot tolerates String values @@ -282,6 +282,12 @@ public class ApplicationYamlASTReconciler implements YamlASTReconciler { } } + private static final Pattern PLACE_HOLDER = Pattern.compile("(\\$\\{\\S+\\})|(\\@\\S+\\@)"); + + private boolean hasPlaceHolder(String str) { + return PLACE_HOLDER.matcher(str).find(); + } + private void expectTypeFoundMapping(Type type, MappingNode node) { expectType(ApplicationYamlProblemType.YAML_EXPECT_TYPE_FOUND_MAPPING, type, node); } diff --git a/headless-services/boot-properties-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlReconcileEngine.java b/headless-services/boot-properties-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlReconcileEngine.java index f7670fe3f..4166cf048 100644 --- a/headless-services/boot-properties-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlReconcileEngine.java +++ b/headless-services/boot-properties-language-server/src/main/java/org/springframework/ide/vscode/boot/yaml/reconcile/ApplicationYamlReconcileEngine.java @@ -48,5 +48,4 @@ public class ApplicationYamlReconcileEngine extends YamlReconcileEngine { protected ReconcileProblem syntaxError(String msg, int offset, int len) { return ApplicationYamlProblems.problem(YAML_SYNTAX_ERROR, msg, offset, len); } - } diff --git a/headless-services/boot-properties-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java b/headless-services/boot-properties-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java index c62c815bd..c8f431a57 100644 --- a/headless-services/boot-properties-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java +++ b/headless-services/boot-properties-language-server/src/test/java/org/springframework/ide/vscode/boot/test/ApplicationYamlEditorTest.java @@ -3624,6 +3624,31 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest { ); } + @Test + public void testIgnoreTypeErrorsForValuesContainingMavenResourcesPlaceholders_workaround() throws Exception { + //See: https://www.pivotaltracker.com/story/show/150005676 + defaultTestData(); + Editor editor = newEditor( + "server:\n" + + " port: \"@application-port@\"\n" + + "bogus: bad" //token error to ensure reconciler is really working + ); + editor.assertProblems("bogus|Unknown property"); + } + + @Test @Ignore + public void IGNORED_testIgnoreTypeErrorsForValuesContainingMavenResourcesPlaceholders_direct() throws Exception { + //See: https://www.pivotaltracker.com/story/show/150005676 + //Not implemented, this test fails. The choice not to implement this was deliberate! + defaultTestData(); + Editor editor = newEditor( + "server:\n" + + " port: @application-port@\n" + + "bogus: bad" //token error to ensure reconciler is really working + ); + editor.assertProblems("bogus|Unknown property"); + } + ///////////////// cruft //////////////////////////////////////////////////////// private void generateNestedProperties(int levels, String[] names, String prefix) { diff --git a/headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/util/SimpleTextDocumentService.java b/headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/util/SimpleTextDocumentService.java index 525de3ccd..172ffa0ee 100644 --- a/headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/util/SimpleTextDocumentService.java +++ b/headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/util/SimpleTextDocumentService.java @@ -152,7 +152,7 @@ public class SimpleTextDocumentService implements TextDocumentService { if (url!=null) { String text = params.getTextDocument().getText(); TrackedDocument td = createDocument(url, languageId, version, text).open(); - Log.info("Opened "+td.getOpenCount()+" times: "+url); +// Log.info("Opened "+td.getOpenCount()+" times: "+url); TextDocument doc = td.getDocument(); TextDocumentContentChangeEvent change = new TextDocumentContentChangeEvent() { @Override