From 56758a41923b74c3777bd82aee87f78a34070bb9 Mon Sep 17 00:00:00 2001 From: arunvenmany-ibm Date: Fri, 25 Oct 2024 18:51:29 +0530 Subject: [PATCH] Invalid property repeat issue fix (#319) * correcting copyrights Signed-off-by: Arun Venmany * fixing property value diagnostic issue - diagnostic is coming for only last entry if entry is duplicated Signed-off-by: Arun Venmany --------- Signed-off-by: Arun Venmany --- .../diagnostic/LibertyPropertiesDiagnosticService.java | 3 ++- .../diagnostic/BootstrapPropertyDiagnosticTest.java | 9 ++++++--- .../langserver/diagnostic/ServerEnvDiagnosticTest.java | 9 ++++++--- .../src/main/liberty/config/bootstrap.properties | 4 +++- .../diagnostic/src/main/liberty/config/server.env | 4 +++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/liberty-ls/src/main/java/io/openliberty/tools/langserver/diagnostic/LibertyPropertiesDiagnosticService.java b/liberty-ls/src/main/java/io/openliberty/tools/langserver/diagnostic/LibertyPropertiesDiagnosticService.java index 80058397..0e8b3acc 100644 --- a/liberty-ls/src/main/java/io/openliberty/tools/langserver/diagnostic/LibertyPropertiesDiagnosticService.java +++ b/liberty-ls/src/main/java/io/openliberty/tools/langserver/diagnostic/LibertyPropertiesDiagnosticService.java @@ -53,7 +53,7 @@ public Map compute(String text, LibertyTextD if(!line.isBlank()) { PropertiesValidationResult validationResult = PropertiesValidationResult.validateServerProperty(line, openedDocument, lineNumber); if (validationResult.hasErrors()) { - errors.put(line, validationResult); + errors.put(line + "_" + lineNumber, validationResult); } } lineNumber++; @@ -70,6 +70,7 @@ public Collection convertToLSPDiagnostics(Map errorEntry : propertiesErrors.entrySet()) { PropertiesValidationResult validationResult = errorEntry.getValue(); String lineContentInError = errorEntry.getKey(); + lineContentInError = lineContentInError.contains("_") ? lineContentInError.substring(0, lineContentInError.lastIndexOf("_")) : lineContentInError; List invalidValueDiagnostics = computeInvalidValuesDiagnostic(validationResult, lineContentInError); lspDiagnostics.addAll(invalidValueDiagnostics); } diff --git a/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/BootstrapPropertyDiagnosticTest.java b/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/BootstrapPropertyDiagnosticTest.java index 4b2119ac..6393bc95 100644 --- a/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/BootstrapPropertyDiagnosticTest.java +++ b/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/BootstrapPropertyDiagnosticTest.java @@ -14,7 +14,7 @@ public class BootstrapPropertyDiagnosticTest extends AbstractDiagnosticTest { @Test public void testBootstrapProperties() throws Exception { - testDiagnostic("bootstrap.properties", 7); + testDiagnostic("bootstrap.properties", 8); checkDiagnosticsContainsAllRanges( // Checking invalid value: com.ibm.ws.logging.console.format=DEVd createRange(0, 34, 38), @@ -29,7 +29,9 @@ public void testBootstrapProperties() throws Exception { // Checking invalid boolean: com.ibm.ws.logging.copy.system.streams=yes createRange(7, 39, 42), // Checking invalid package list: org.osgi.framework.bootdelegation=com.ibm.websphere,com. - createRange(8, 34, 56) + createRange(8, 34, 56), + // Checking invalid value: com.ibm.ws.logging.console.format=DEVd + createRange(10, 34, 38) ); checkDiagnosticsContainsMessages( "The value `DEVd` is not valid for the property `com.ibm.ws.logging.console.format`.", @@ -38,7 +40,8 @@ public void testBootstrapProperties() throws Exception { "The value `0` is not within the valid range `[1..65535]` for the property `default.http.port`.", "The value `2147483648` is not within the valid range `[0..2147483647]` for the property `com.ibm.hpel.log.purgeMaxSize`.", "The value `yes` is not valid for the property `com.ibm.ws.logging.copy.system.streams`.", - "This value must be a comma-delimited list of Java packages." + "This value must be a comma-delimited list of Java packages.", + "The value `DEVd` is not valid for the property `com.ibm.ws.logging.console.format`." ); } } diff --git a/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/ServerEnvDiagnosticTest.java b/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/ServerEnvDiagnosticTest.java index 84547c97..0c6df512 100644 --- a/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/ServerEnvDiagnosticTest.java +++ b/liberty-ls/src/test/java/io/openliberty/tools/langserver/diagnostic/ServerEnvDiagnosticTest.java @@ -16,7 +16,7 @@ public class ServerEnvDiagnosticTest extends AbstractDiagnosticTest { @Test public void testServerEnv() throws Exception { // has invalid, case-sensitive, case-insensitive, and negative port integer values. - testDiagnostic("server.env", 5); + testDiagnostic("server.env", 6); checkDiagnosticsContainsAllRanges( // Checking invalid value: WLP_LOGGING_CONSOLE_FORMAT=asdf createRange(0, 27, 31), @@ -27,14 +27,17 @@ public void testServerEnv() throws Exception { // Checking invalid whitespace before equal sign: WLP_DEBUG_REMOTE =n createRange(4,16,18), // Checking invalid whitespace after equal sign: WLP_LOGGING_MESSAGE_FORMAT= SIMPLE - createRange(7,26,28) + createRange(7,26,28), + // Checking invalid case-sensitive property: WLP_LOGGING_CONSOLE_SOURCE=messagE + createRange(9, 27, 34) ); checkDiagnosticsContainsMessages( "The value `asdf` is not valid for the variable `WLP_LOGGING_CONSOLE_FORMAT`.", "The value `messagE` is not valid for the variable `WLP_LOGGING_CONSOLE_SOURCE`.", "The value `-2` is not within the valid range `[1..65535]` for the variable `WLP_DEBUG_ADDRESS`.", "There should be no whitespace surrounding the equal sign (=).", - "There should be no whitespace surrounding the equal sign (=)." + "There should be no whitespace surrounding the equal sign (=).", + "The value `messagE` is not valid for the variable `WLP_LOGGING_CONSOLE_SOURCE`." ); } } diff --git a/liberty-ls/src/test/resources/workspace/diagnostic/src/main/liberty/config/bootstrap.properties b/liberty-ls/src/test/resources/workspace/diagnostic/src/main/liberty/config/bootstrap.properties index a6d1502a..64a7e2e3 100644 --- a/liberty-ls/src/test/resources/workspace/diagnostic/src/main/liberty/config/bootstrap.properties +++ b/liberty-ls/src/test/resources/workspace/diagnostic/src/main/liberty/config/bootstrap.properties @@ -6,4 +6,6 @@ default.http.port=0 com.ibm.hpel.log.purgeMinTime=12h com.ibm.hpel.log.purgeMaxSize=2147483648 com.ibm.ws.logging.copy.system.streams=yes -org.osgi.framework.bootdelegation=com.ibm.websphere,com. \ No newline at end of file +org.osgi.framework.bootdelegation=com.ibm.websphere,com. +#adding same line again to check diagnostic is coming on both lines +com.ibm.ws.logging.console.format=DEVd \ No newline at end of file diff --git a/liberty-ls/src/test/resources/workspace/diagnostic/src/main/liberty/config/server.env b/liberty-ls/src/test/resources/workspace/diagnostic/src/main/liberty/config/server.env index ead7ede8..6d22422e 100644 --- a/liberty-ls/src/test/resources/workspace/diagnostic/src/main/liberty/config/server.env +++ b/liberty-ls/src/test/resources/workspace/diagnostic/src/main/liberty/config/server.env @@ -5,4 +5,6 @@ WLP_DEBUG_ADDRESS=-2 WLP_DEBUG_REMOTE =n # adding comment line and blank line to check whether its being ignored -WLP_LOGGING_MESSAGE_FORMAT= SIMPLE \ No newline at end of file +WLP_LOGGING_MESSAGE_FORMAT= SIMPLE +#adding same line again to check diagnostic is coming on both lines +WLP_LOGGING_CONSOLE_SOURCE=messagE \ No newline at end of file