From 1b37c49988ae9c9bdbb881c9cf01ea02a6a52033 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Tue, 10 Oct 2023 16:05:27 -0500 Subject: [PATCH] Ignore case for features in config element validation --- .../lemminx/LibertyDiagnosticParticipant.java | 5 +++-- .../langserver/lemminx/data/FeatureListGraph.java | 15 ++++++++++++--- .../io/openliberty/LibertyDiagnosticTest.java | 2 +- .../java/io/openliberty/LibertyFeatureTest.java | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/LibertyDiagnosticParticipant.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/LibertyDiagnosticParticipant.java index 736c359c..9067a2a9 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/LibertyDiagnosticParticipant.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/LibertyDiagnosticParticipant.java @@ -115,13 +115,14 @@ private void validateFeature(DOMDocument domDocument, List list, DOM String message = "ERROR: The feature \"" + featureName + "\" does not exist."; list.add(new Diagnostic(range, message, DiagnosticSeverity.Error, LIBERTY_LEMMINX_SOURCE, INCORRECT_FEATURE_CODE)); } else { - if (includedFeatures.contains(featureName)) { + String featureNameLower = featureName.toLowerCase(); + if (includedFeatures.contains(featureNameLower)) { Range range = XMLPositionUtility.createRange(featureTextNode.getStart(), featureTextNode.getEnd(), domDocument); String message = "ERROR: " + featureName + " is already included."; list.add(new Diagnostic(range, message, DiagnosticSeverity.Error, LIBERTY_LEMMINX_SOURCE)); } else { - includedFeatures.add(featureName); + includedFeatures.add(featureNameLower); } } } diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/data/FeatureListGraph.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/data/FeatureListGraph.java index 3d4a40ff..cb69b25c 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/data/FeatureListGraph.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/data/FeatureListGraph.java @@ -22,7 +22,7 @@ public class FeatureListGraph { private String runtime = ""; private Map nodes; - private Map> enabledByCache; + private Map> enabledByCache; // storing in lower case to enable diagnostics with configured features private Map> enablesCache; public FeatureListGraph() { @@ -74,6 +74,7 @@ public String getRuntime() { /** * Returns a superset of 'owning' features that enable a given config element or feature. + * The features are returned in lower case to make the diagnostic code easier. * @param elementName * @return */ @@ -99,8 +100,16 @@ public Set getAllEnabledBy(String elementName) { allEnabledBy.addAll(enablers); queue.addAll(enablers); } - enabledByCache.put(elementName, allEnabledBy); - return allEnabledBy; + return addToEnabledByCacheInLowerCase(elementName, allEnabledBy); + } + + private Set addToEnabledByCacheInLowerCase(String configElement, Set allEnabledBy) { + Set lowercaseEnabledBy = new HashSet(); + for (String nextFeature: allEnabledBy) { + lowercaseEnabledBy.add(nextFeature.toLowerCase()); + } + enabledByCache.put(configElement, lowercaseEnabledBy); + return lowercaseEnabledBy; } /** diff --git a/lemminx-liberty/src/test/java/io/openliberty/LibertyDiagnosticTest.java b/lemminx-liberty/src/test/java/io/openliberty/LibertyDiagnosticTest.java index c827b903..6fffeb3f 100644 --- a/lemminx-liberty/src/test/java/io/openliberty/LibertyDiagnosticTest.java +++ b/lemminx-liberty/src/test/java/io/openliberty/LibertyDiagnosticTest.java @@ -213,7 +213,7 @@ public void testConfigElementDirect() throws JAXBException { assertTrue(featureList.exists()); FeatureService.getInstance().readFeaturesFromFeatureListFile(new ArrayList(), libWorkspace, featureList); - String correctFeature = " ssl-1.0"; + String correctFeature = " Ssl-1.0"; String incorrectFeature = " jaxrs-2.0"; String configElement = " "; int diagnosticStart = configElement.indexOf("<"); diff --git a/lemminx-liberty/src/test/java/io/openliberty/LibertyFeatureTest.java b/lemminx-liberty/src/test/java/io/openliberty/LibertyFeatureTest.java index c3971b37..de8d54b3 100644 --- a/lemminx-liberty/src/test/java/io/openliberty/LibertyFeatureTest.java +++ b/lemminx-liberty/src/test/java/io/openliberty/LibertyFeatureTest.java @@ -51,8 +51,8 @@ public void getInstalledFeaturesListTest() throws JAXBException { assertTrue(fg.get("ssl").getEnabledBy().contains("ssl-1.0")); assertEquals(77, fg.getAllEnabledBy("ssl").size()); assertEquals(235, fg.getAllEnabledBy("library").size()); - assertTrue(fg.getAllEnabledBy("ltpa").contains("adminCenter-1.0")); // direct enabler - assertTrue(fg.getAllEnabledBy("ssl").contains("microProfile-5.0")); // transitive enabler + assertTrue(fg.getAllEnabledBy("ltpa").contains("admincenter-1.0")); // direct enabler + assertTrue(fg.getAllEnabledBy("ssl").contains("microprofile-5.0")); // transitive enabler assertTrue(fg.getAllEnables("microProfile-5.0").contains("ssl")); assertTrue(fg.getAllEnables("jakartaee-8.0").contains("classloading")); }