Skip to content

Commit

Permalink
Versionless feature 1.0 (#298)
Browse files Browse the repository at this point in the history
* Versionless feature changes. Added platform component

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

* Versionless feature changes. Added hover for platform component

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

* Versionless feature changes. modified diagnostics

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

* Versionless feature changes. modified diagnostics

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

* Versionless feature changes. adding more diagnostic scenarios

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

* Versionless feature changes. code changes based on review comments

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

---------

Signed-off-by: Arun Venmany <[email protected]>
  • Loading branch information
arunvenmany-ibm authored Aug 22, 2024
1 parent 7f6375b commit ab3320b
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 IBM Corporation and others.
* Copyright (c) 2020, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -74,8 +74,8 @@ public void onXMLContent(ICompletionRequest request, ICompletionResponse respons
existingFeatures, featureName, featureMgrNode);
featureCompletionItems.stream().forEach(item -> response.addCompletionItem(item));
}
if (parentElement.getTagName().equals(LibertyConstants.PLATFORM_ELEMENT)) {
buildPlatformCompletionItems(request, response, parentElement);
else if (parentElement.getTagName().equals(LibertyConstants.PLATFORM_ELEMENT)) {
this.buildPlatformCompletionItems(request, response, parentElement);
}
}

Expand All @@ -85,7 +85,7 @@ public void onXMLContent(ICompletionRequest request, ICompletionResponse respons
* @param response response
* @param parentElement parent element xml dom
*/
private static void buildPlatformCompletionItems(ICompletionRequest request, ICompletionResponse response, DOMElement parentElement) {
private void buildPlatformCompletionItems(ICompletionRequest request, ICompletionResponse response, DOMElement parentElement) {
DOMNode platformTextNode = (DOMNode) parentElement.getChildNodes().item(0);
String platformName = platformTextNode != null ? platformTextNode.getTextContent() : null;
LibertyRuntime runtimeInfo = LibertyUtils.getLibertyRuntimeInfo(request.getXMLDocument());
Expand All @@ -104,6 +104,11 @@ private static void buildPlatformCompletionItems(ICompletionRequest request, ICo
CompletionItem completionItem = new CompletionItem();
completionItem.setLabel(item);
completionItem.setTextEdit(edit);
String platformNameNoVersion = item.contains("-") ? item.substring(0, item.lastIndexOf("-"))
: item;
if (LibertyConstants.platformDescriptionMap.containsKey(platformNameNoVersion)) {
completionItem.setDocumentation(LibertyConstants.platformDescriptionMap.get(platformNameNoVersion));
}
response.addCompletionItem(completionItem);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package io.openliberty.tools.langserver.lemminx;

import com.google.common.collect.Sets;
import org.eclipse.lemminx.dom.DOMAttr;
import org.eclipse.lemminx.dom.DOMDocument;
import org.eclipse.lemminx.dom.DOMNode;
Expand Down Expand Up @@ -93,7 +94,7 @@ private void validateDom(DOMDocument domDocument, List<Diagnostic> diagnosticsLi
String nodeName = node.getNodeName();
if (LibertyConstants.FEATURE_MANAGER_ELEMENT.equals(nodeName)) {
featureManagerPresent = true;
validateFeature(domDocument, diagnosticsList, node, includedFeatures);
validFeaturesAndPlatforms(domDocument, diagnosticsList, node, includedFeatures);
} else if (LibertyConstants.INCLUDE_ELEMENT.equals(nodeName)) {
validateIncludeLocation(domDocument, diagnosticsList, node);
} else if (featureGraph.isConfigElement(nodeName)) { // defaults to false
Expand All @@ -103,7 +104,7 @@ private void validateDom(DOMDocument domDocument, List<Diagnostic> diagnosticsLi
validateConfigElements(domDocument, diagnosticsList, tempDiagnosticsList, featureGraph, includedFeatures, featureManagerPresent);
}

private void validateFeature(DOMDocument domDocument, List<Diagnostic> list, DOMNode featureManager, Set<String> includedFeatures) {
private void validFeaturesAndPlatforms(DOMDocument domDocument, List<Diagnostic> list, DOMNode featureManager, Set<String> includedFeatures) {

LibertyRuntime runtimeInfo = LibertyUtils.getLibertyRuntimeInfo(domDocument);
String libertyVersion = runtimeInfo == null ? null : runtimeInfo.getRuntimeVersion();
Expand Down Expand Up @@ -292,7 +293,7 @@ private void validateConfigElements(DOMDocument domDocument, List<Diagnostic> di
* @param selectedPlatformsWithoutVersion platforms in xml without version
* @param selectedPlatforms platforms in xml
*/
private static void validatePlatform(DOMDocument domDocument, List<Diagnostic> list, DOMNode featureTextNode, Set<String> selectedPlatformsWithoutVersion,
private void validatePlatform(DOMDocument domDocument, List<Diagnostic> list, DOMNode featureTextNode, Set<String> selectedPlatformsWithoutVersion,
Set<String> selectedPlatforms) {
LibertyRuntime runtimeInfo = LibertyUtils.getLibertyRuntimeInfo(domDocument);
String libertyVersion = runtimeInfo == null ? null : runtimeInfo.getRuntimeVersion();
Expand All @@ -318,7 +319,8 @@ private static void validatePlatform(DOMDocument domDocument, List<Diagnostic> l
if (!conflictingPlatforms.isEmpty()) {
Range range = XMLPositionUtility.createRange(featureTextNode.getStart(),
featureTextNode.getEnd(), domDocument);
String message = "ERROR: " + platformName + " conflicts with already included platform(s) " + conflictingPlatforms;
conflictingPlatforms.add(platformName);
String message = "ERROR: The following configured platform versions are in conflict " + conflictingPlatforms;
list.add(new Diagnostic(range, message, DiagnosticSeverity.Error, LIBERTY_LEMMINX_SOURCE));
}
selectedPlatformsWithoutVersion.add(platformNoVersionLower);
Expand All @@ -341,7 +343,7 @@ private static void validatePlatform(DOMDocument domDocument, List<Diagnostic> l
* @param platformName
* @param platformNoVersionLower
*/
private static void checkForPlatformUniqueness(DOMDocument domDocument, List<Diagnostic> list, DOMNode featureTextNode, Set<String> selectedPlatformsWithoutVersion, Set<String> selectedPlatforms, String platformNameLowerCase, String platformName, String platformNoVersionLower) {
private void checkForPlatformUniqueness(DOMDocument domDocument, List<Diagnostic> list, DOMNode featureTextNode, Set<String> selectedPlatformsWithoutVersion, Set<String> selectedPlatforms, String platformNameLowerCase, String platformName, String platformNoVersionLower) {
if (selectedPlatforms.contains(platformNameLowerCase)) {
Range range = XMLPositionUtility.createRange(featureTextNode.getStart(),
featureTextNode.getEnd(), domDocument);
Expand All @@ -362,7 +364,7 @@ private static void checkForPlatformUniqueness(DOMDocument domDocument, List<Dia
* @param selectedPlatforms
* @return
*/
private static Set<String> getConflictingPlatforms(String platformNoVersionLower, Set<String> selectedPlatforms) {
private Set<String> getConflictingPlatforms(String platformNoVersionLower, Set<String> selectedPlatforms) {
if(LibertyConstants.conflictingPlatforms.containsKey(platformNoVersionLower)){
String conflictingPlatformName = LibertyConstants.conflictingPlatforms.get(platformNoVersionLower);
return selectedPlatforms.stream()
Expand All @@ -381,19 +383,18 @@ private static Set<String> getConflictingPlatforms(String platformNoVersionLower
* @param selectedPlatforms
* @param versionedFeatures
*/
private static void checkForPlatFormAndFeature(DOMDocument domDocument, List<Diagnostic> list, Set<String> versionlessFeatures, List<DOMNode> features, Set<String> selectedPlatforms, Set<String> versionedFeatures) {
private void checkForPlatFormAndFeature(DOMDocument domDocument, List<Diagnostic> list, Set<String> versionlessFeatures, List<DOMNode> features, Set<String> selectedPlatforms, Set<String> versionedFeatures) {

for (DOMNode featureNode : features) {
DOMNode featureTextNode = (DOMNode) featureNode.getChildNodes().item(0);
if (LibertyConstants.FEATURE_ELEMENT.equals(featureNode.getLocalName())
&& featureTextNode != null && featureTextNode.getTextContent() != null) {
String featureName = featureTextNode.getTextContent().trim();
String featureNameLower = featureName.toLowerCase();
if (!featureNameLower.contains("-")&& versionlessFeatures.contains(featureName)) {
if (versionlessFeatures.contains(featureName)) {
// versionless feature
validateVersionLessFeatures(domDocument, list, selectedPlatforms, versionedFeatures, featureTextNode, featureName);
}
else if(featureNameLower.contains("-") && versionedFeatures.contains(featureName)){
} else {
validateVersionedFeatures(domDocument, list, selectedPlatforms, versionedFeatures, featureTextNode, featureName);
}
}
Expand All @@ -411,7 +412,7 @@ else if(featureNameLower.contains("-") && versionedFeatures.contains(featureName
* @param featureTextNode
* @param featureName
*/
private static void validateVersionedFeatures(DOMDocument domDocument, List<Diagnostic> list, Set<String> selectedPlatforms, Set<String> versionedFeatures, DOMNode featureTextNode, String featureName) {
private void validateVersionedFeatures(DOMDocument domDocument, List<Diagnostic> list, Set<String> selectedPlatforms, Set<String> versionedFeatures, DOMNode featureTextNode, String featureName) {
// if any platform is selected, it should be allowed for all features, otherwise throw error
LibertyRuntime runtimeInfo = LibertyUtils.getLibertyRuntimeInfo(domDocument);
String libertyVersion = runtimeInfo == null ? null : runtimeInfo.getRuntimeVersion();
Expand All @@ -422,7 +423,8 @@ private static void validateVersionedFeatures(DOMDocument domDocument, List<Diag
if (commonPlatforms != null && !commonPlatforms.isEmpty() && !commonPlatforms.containsAll(selectedPlatforms)) {
Range range = XMLPositionUtility.createRange(featureTextNode.getStart(), featureTextNode.getEnd(),
domDocument);
String message = "ERROR: \"" + featureName + "\" cannot be used since selected platform(s) " + selectedPlatforms + " do not match with supported platform(s) " + commonPlatforms;
commonPlatforms.addAll(selectedPlatforms);
String message = "ERROR: The following configured platform versions are in conflict " + commonPlatforms;
list.add(new Diagnostic(range, message, DiagnosticSeverity.Error, LIBERTY_LEMMINX_SOURCE, INCORRECT_FEATURE_CODE));
}
}
Expand All @@ -445,7 +447,7 @@ private static void validateVersionedFeatures(DOMDocument domDocument, List<Diag
* @param versionLessFeatureTextNode
* @param featureName
*/
private static void validateVersionLessFeatures(DOMDocument domDocument, List<Diagnostic> list, Set<String> selectedPlatforms, Set<String> versionedFeatures,DOMNode versionLessFeatureTextNode, String featureName) {
private void validateVersionLessFeatures(DOMDocument domDocument, List<Diagnostic> list, Set<String> selectedPlatforms, Set<String> versionedFeatures,DOMNode versionLessFeatureTextNode, String featureName) {
LibertyRuntime runtimeInfo = LibertyUtils.getLibertyRuntimeInfo(domDocument);
String libertyVersion = runtimeInfo == null ? null : runtimeInfo.getRuntimeVersion();
String libertyRuntime = runtimeInfo == null ? null : runtimeInfo.getRuntimeType();
Expand Down Expand Up @@ -485,13 +487,13 @@ private static void validateVersionLessFeatures(DOMDocument domDocument, List<Di
* @param libertyRuntime
* @param requestDelay
*/
private static void checkForVersionlessPlatforms(DOMDocument domDocument, List<Diagnostic> list, Set<String> selectedPlatforms, DOMNode versionLessFeatureTextNode, String featureName, String libertyVersion, String libertyRuntime, int requestDelay) {
private void checkForVersionlessPlatforms(DOMDocument domDocument, List<Diagnostic> list, Set<String> selectedPlatforms, DOMNode versionLessFeatureTextNode, String featureName, String libertyVersion, String libertyRuntime, int requestDelay) {
Set<String> allPlatforrmsForVersionLess = FeatureService.getInstance()
.getAllPlatformsForVersionLessFeature(featureName, libertyVersion, libertyRuntime, requestDelay, domDocument.getDocumentURI());
if (!allPlatforrmsForVersionLess.containsAll(selectedPlatforms)) {
if (Sets.intersection(allPlatforrmsForVersionLess, selectedPlatforms).isEmpty() ){
Range range = XMLPositionUtility.createRange(versionLessFeatureTextNode.getStart(), versionLessFeatureTextNode.getEnd(),
domDocument);
String message = "ERROR: The \"" + featureName + "\" versionless feature cannot be resolved";
String message = "ERROR: The \"" + featureName + "\" versionless feature cannot be resolved. Specify a platform or a feature with a version to enable resolution.";
list.add(new Diagnostic(range, message, DiagnosticSeverity.Error, LIBERTY_LEMMINX_SOURCE, INCORRECT_FEATURE_CODE));
}
}
Expand All @@ -509,7 +511,7 @@ private static void checkForVersionlessPlatforms(DOMDocument domDocument, List<D
* @param requestDelay
* @return
*/
private static Set<String> checkForCommonPlatforms(DOMDocument domDocument, Set<String> versionedFeatures, String libertyVersion, String libertyRuntime, int requestDelay) {
private Set<String> checkForCommonPlatforms(DOMDocument domDocument, Set<String> versionedFeatures, String libertyVersion, String libertyRuntime, int requestDelay) {
Set<String> commonPlatforms = FeatureService.getInstance()
.getCommonPlatformsForFeatures(versionedFeatures, libertyVersion, libertyRuntime, requestDelay, domDocument.getDocumentURI());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public Hover onText(IHoverRequest request, CancelChecker cancelChecker) {
*/
private Hover getHoverPlatformDescription(String platformName) {
String platformNameLowerCase = platformName.toLowerCase();
// strip off version number after the - so that we can provide all possible valid versions of a feature for completion
String featureNameToCompare = platformNameLowerCase.contains("-") ? platformNameLowerCase.substring(0, platformNameLowerCase.lastIndexOf("-")) : platformNameLowerCase;
// strip off version number after the - so that we can provide all possible valid versions of a platform for completion
String platformNameToCompare = platformNameLowerCase.contains("-") ? platformNameLowerCase.substring(0, platformNameLowerCase.lastIndexOf("-")) : platformNameLowerCase;
String version = platformNameLowerCase.contains("-") ? platformNameLowerCase.substring(platformNameLowerCase.lastIndexOf("-") + 1) : "";
if (LibertyConstants.platformDescriptionMap.containsKey(featureNameToCompare)) {
if (LibertyConstants.platformDescriptionMap.containsKey(platformNameToCompare)) {
return new Hover(new MarkupContent("plaintext",
String.format(LibertyConstants.platformDescriptionMap.get(featureNameToCompare), version)));
String.format(LibertyConstants.platformDescriptionMap.get(platformNameToCompare), version)));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022, 2024 IBM Corporation and others.
* Copyright (c) 2020, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,23 @@ public List<Feature> getFeatureReplacements(String featureName, DOMNode featureM
for (String nextFeatureName : featureNamesLowerCase) {
if (existingFeatures.contains(nextFeatureName)) {
// collect feature name minus version number to know which other features to exclude
String featureNameMinusVersion = nextFeatureName.substring(0, nextFeatureName.lastIndexOf("-") + 1);
String featureNameMinusVersion = nextFeatureName.contains("-") ?
nextFeatureName.substring(0, nextFeatureName.lastIndexOf("-") + 1) : nextFeatureName;
featuresWithoutVersionsToExclude.add(featureNameMinusVersion);
}
}

List<Feature> replacementFeatures = new ArrayList<Feature>();
String featureNameLowerCase = featureName.toLowerCase();

for (int i=0; i < featureNamesLowerCase.size(); i++) {
for (int i = 0; i < featureNamesLowerCase.size(); i++) {
String nextFeatureName = featureNamesLowerCase.get(i);
if (nextFeatureName.contains(featureNameLowerCase) && (!nextFeatureName.contains("-") ||
!featuresWithoutVersionsToExclude.contains(nextFeatureName.substring(0, nextFeatureName.lastIndexOf("-") + 1)))) {
if (nextFeatureName.contains(featureNameLowerCase)) {
String comparingFeatureName = nextFeatureName.contains("-") ?
nextFeatureName.substring(0, nextFeatureName.lastIndexOf("-") + 1) : nextFeatureName+"-";
if (!featuresWithoutVersionsToExclude.contains(comparingFeatureName)) {
replacementFeatures.add(features.get(i));
}
}
}

Expand Down Expand Up @@ -625,8 +629,8 @@ public Set<String> getAllPlatformsForVersionLessFeature(String featureName, Stri
Optional<Feature> feature = this.getFeature(featureName, libertyVersion, libertyRuntime, requestDelay, documentURI);
Set<String> featureNames = new HashSet<>();
if (feature.isPresent()) {
addRequiredFeatureNames(feature.get(), featureNames);
addRequireTolerateFeatureNames(feature.get(), featureNames);
this.addRequiredFeatureNames(feature.get(), featureNames);
this.addRequireTolerateFeatureNames(feature.get(), featureNames);
}
return featureNames.stream()
.map(f -> getAllPlatformsForFeature(f, libertyVersion, libertyRuntime, requestDelay, documentURI))
Expand All @@ -638,7 +642,7 @@ public Set<String> getAllPlatformsForVersionLessFeature(String featureName, Stri
* @param feature current feature
* @param featureNames feature name list
*/
private static void addRequireTolerateFeatureNames(Feature feature, Set<String> featureNames) {
private void addRequireTolerateFeatureNames(Feature feature, Set<String> featureNames) {
List<FeatureTolerate> featureTolerates = feature.getWlpInformation().getRequireFeatureWithTolerates();

for(FeatureTolerate featureTolerate: featureTolerates) {
Expand Down Expand Up @@ -668,7 +672,7 @@ private static void addRequireTolerateFeatureNames(Feature feature, Set<String>
* @param feature current feature
* @param requiredFeatureNames required feature name array
*/
private static void addRequiredFeatureNames(Feature feature, Set<String> requiredFeatureNames) {
private void addRequiredFeatureNames(Feature feature, Set<String> requiredFeatureNames) {
ArrayList<String> requireFeatures = feature.getWlpInformation().getRequireFeature();

for(String requireFeature: requireFeatures) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 IBM Corporation and others.
* Copyright (c) 2020, 2024 IBM Corporation and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Loading

0 comments on commit ab3320b

Please sign in to comment.