Skip to content

Commit

Permalink
Ignore case for features in config element validation (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking authored Oct 10, 2023
1 parent fb8b255 commit 7ebb1d5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ private void validateFeature(DOMDocument domDocument, List<Diagnostic> 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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class FeatureListGraph {
private String runtime = "";
private Map<String, FeatureListNode> nodes;
private Map<String, Set<String>> enabledByCache;
private Map<String, Set<String>> enabledByCache; // storing in lower case to enable diagnostics with configured features
private Map<String, Set<String>> enablesCache;

public FeatureListGraph() {
Expand Down Expand Up @@ -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
*/
Expand All @@ -99,8 +100,16 @@ public Set<String> getAllEnabledBy(String elementName) {
allEnabledBy.addAll(enablers);
queue.addAll(enablers);
}
enabledByCache.put(elementName, allEnabledBy);
return allEnabledBy;
return addToEnabledByCacheInLowerCase(elementName, allEnabledBy);
}

private Set<String> addToEnabledByCacheInLowerCase(String configElement, Set<String> allEnabledBy) {
Set<String> lowercaseEnabledBy = new HashSet<String>();
for (String nextFeature: allEnabledBy) {
lowercaseEnabledBy.add(nextFeature.toLowerCase());
}
enabledByCache.put(configElement, lowercaseEnabledBy);
return lowercaseEnabledBy;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void testConfigElementDirect() throws JAXBException {
assertTrue(featureList.exists());
FeatureService.getInstance().readFeaturesFromFeatureListFile(new ArrayList<Feature>(), libWorkspace, featureList);

String correctFeature = " <feature>ssl-1.0</feature>";
String correctFeature = " <feature>Ssl-1.0</feature>";
String incorrectFeature = " <feature>jaxrs-2.0</feature>";
String configElement = " <ssl id=\"\"/>";
int diagnosticStart = configElement.indexOf("<");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down

0 comments on commit 7ebb1d5

Please sign in to comment.