Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore case for features in config element validation #225

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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