Skip to content

Commit

Permalink
Config element fix for versionless feature (#304)
Browse files Browse the repository at this point in the history
* Config element fix for versionless feature

Signed-off-by: Arun Venmany <[email protected]>

* Resolving review comments

Signed-off-by: Arun Venmany <[email protected]>

---------

Signed-off-by: Arun Venmany <[email protected]>
  • Loading branch information
arunvenmany-ibm authored Sep 24, 2024
1 parent 9de2a28 commit cb95f9f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,30 @@ private void validateConfigElements(DOMDocument domDocument, List<Diagnostic> di
}
for (Diagnostic tempDiagnostic : tempDiagnosticsList) {
String configElement = tempDiagnostic.getSource();
Set<String> includedFeaturesCopy = new HashSet<String>(includedFeatures);
Set<String> compatibleFeaturesList = featureGraph.getAllEnabledBy(configElement);
includedFeaturesCopy.retainAll(compatibleFeaturesList);
Set<String> includedFeaturesCopy = getCompatibleFeatures(includedFeatures, compatibleFeaturesList);
if (includedFeaturesCopy.isEmpty()) {
diagnosticsList.add(tempDiagnostic);
}
}
}

/**
* get compatible features for both versioned and versionless features
*
* @param includedFeatures ll selected features
* @param compatibleFeaturesList enabled by feature list
* @return any compitable feature list
*/
private Set<String> getCompatibleFeatures(Set<String> includedFeatures, Set<String> compatibleFeaturesList) {
Set<String> versionLessCompatibleFeatureList = compatibleFeaturesList.stream()
.map(f -> LibertyUtils.stripVersion(f))
.collect(Collectors.toSet());
return includedFeatures.stream().filter(included ->
compatibleFeaturesList.contains(included) || versionLessCompatibleFeatureList.contains(included)
).collect(Collectors.toSet());
}

/**
* validate platform element. checks for
* 1) if platform is invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,26 @@ public void testValidPlatformDiagnostic() throws BadLocationException {

XMLAssert.testDiagnosticsFor(serverXML, null, null, serverXMLURI);
}

@Test
public void testConfigElementVersionLess() throws JAXBException {
assertTrue(featureList.exists());
FeatureService.getInstance().readFeaturesFromFeatureListFile(new ArrayList<Feature>(), libWorkspace, featureList);
String serverXML1 = String.join(newLine,
"<server description=\"Sample Liberty server\">",
" <featureManager>",
" <feature>servlet</feature>",
" <platform>jakartaee-9.1</platform>",
" </featureManager>",
" <webApplication contextRoot=\"/app-name\" location=\"app-name.war\" />",
" <httpEndpoint id=\"defaultHttpEndpoint\" httpPort=\"9080\" httpsPort=\"9443\"/>",
" <ssl id=\"defaultSSLConfig\" trustDefaultCerts=\"true\" />",
"</server>"
);
Diagnostic configForMissingFeature = new Diagnostic();
configForMissingFeature.setRange(r(7, 3, 7, 57));
configForMissingFeature.setCode(LibertyDiagnosticParticipant.MISSING_CONFIGURED_FEATURE_CODE);
configForMissingFeature.setMessage(LibertyDiagnosticParticipant.MISSING_CONFIGURED_FEATURE_MESSAGE);
XMLAssert.testDiagnosticsFor(serverXML1, null, null, serverXMLURI,configForMissingFeature);
}
}

0 comments on commit cb95f9f

Please sign in to comment.