Skip to content

Commit

Permalink
Merge branch 'OpenLiberty:main' into ca_add_variable
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvenmany-ibm authored Feb 14, 2025
2 parents 6c23b67 + 349a02c commit fd0f62a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lemminx-liberty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<dependency>
<groupId>io.openliberty.tools</groupId>
<artifactId>ci.common</artifactId>
<version>1.8.36</version>
<version>1.8.37-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testGetVariables() throws BadLocationException {
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <httpEndpoint host=\"*\" httpPort=\"default|\"\n",//
" <httpEndpoint host=\"*\" httpPort=\"${default|\"\n",//
" httpsPort=\"${default.https.port}\" id=\"defaultHttpEndpoint\"/>",//
"</server>" //
);
Expand All @@ -61,6 +61,40 @@ public void testGetVariables() throws BadLocationException {
XMLAssert.testCompletionFor(serverXML, null, serverXmlFile.toURI().toString(), TOTAL_ITEMS, httpCompletion,
httpsCompletion);

// tests for checking completion of liberty pre defined variables
// verifying variables starting with server. and wlp.
serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <webApplication contextRoot=\"/app-name\" location=\"${server.|}\" />",//
"</server>" //
);

CompletionItem serverConfigDirCompletion= c("${server.config.dir}", "${server.config.dir}");
CompletionItem serverOutputDirCompletion = c("${server.output.dir}", "${server.output.dir}");

XMLAssert.testCompletionFor(serverXML, null, serverXmlFile.toURI().toString(), TOTAL_ITEMS, serverConfigDirCompletion,
serverOutputDirCompletion);

serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <webApplication contextRoot=\"/app-name\" location=\"${wlp.|}\" />",//
"</server>" //
);

CompletionItem wlpInstallDirCompletion = c("${wlp.install.dir}", "${wlp.install.dir}");
CompletionItem wlpUsrDirCompletion = c("${wlp.user.dir}", "${wlp.user.dir}");

XMLAssert.testCompletionFor(serverXML, null, serverXmlFile.toURI().toString(), TOTAL_ITEMS, wlpInstallDirCompletion,
wlpUsrDirCompletion);

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class LibertyCompletionParticipant extends CompletionParticipantAdapter {
public void onAttributeValue(String valuePrefix, ICompletionRequest request, ICompletionResponse response, CancelChecker cancelChecker) throws Exception {
if (!LibertyUtils.isConfigXMLFile(request.getXMLDocument()))
return;
//show variable completion only if user uses "${"
if(!valuePrefix.contains("${"))
return;
Properties variableProps = SettingsService.getInstance()
.getVariablesForServerXml(request.getXMLDocument()
.getDocumentURI());
Expand All @@ -75,17 +78,10 @@ public void onAttributeValue(String valuePrefix, ICompletionRequest request, ICo
completionPrefix = valuePrefix.substring(0,lastVar.getEndLoc()+1);
}
} else {
// for single variable,check ${ is specified
if (valuePrefix.contains("${")) {
// extract variable name with whatever is after ${
variablePrefix = valuePrefix.substring(valuePrefix.lastIndexOf("${") + 2);
// extract completionPrefix with whatever is before ${
completionPrefix = valuePrefix.substring(0, valuePrefix.lastIndexOf("${"));
} else {
// if no ${ specified, take all data as completion variable
variablePrefix = valuePrefix;
completionPrefix = "";
}
// extract variable name with whatever is after ${
variablePrefix = valuePrefix.substring(valuePrefix.lastIndexOf("${") + 2);
// extract completionPrefix with whatever is before ${
completionPrefix = valuePrefix.substring(0, valuePrefix.lastIndexOf("${"));
}
String finalVariableName = variablePrefix.replace("${","").replace("}","");
variableProps.entrySet().stream().filter(it -> it.getKey().toString().toLowerCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ public void populateVariablesForWorkspace(LibertyWorkspace workspace) {
File installDirectory = LibertyUtils.getFileFromLibertyPluginXml(pluginConfigFilePath, "installDirectory");
File serverDirectory = LibertyUtils.getFileFromLibertyPluginXml(pluginConfigFilePath, "serverDirectory");
File userDirectory = LibertyUtils.getFileFromLibertyPluginXml(pluginConfigFilePath, "userDirectory");
if (serverDirectory != null && installDirectory != null && userDirectory != null) {
File serverOutputDirectory = LibertyUtils.getFileFromLibertyPluginXml(pluginConfigFilePath, "serverOutputDirectory");
if (serverDirectory != null && installDirectory != null && userDirectory != null && serverOutputDirectory !=null) {
try {
ServerConfigDocument serverConfigDocument = new ServerConfigDocument(
new CommonLogger(LOGGER), null, installDirectory, userDirectory, serverDirectory);
new CommonLogger(LOGGER), null, installDirectory, userDirectory, serverDirectory, serverOutputDirectory);
variablesForWorkspace.putAll(serverConfigDocument.getDefaultProperties());
variablesForWorkspace.putAll(serverConfigDocument.getProperties());
LOGGER.finest("Populated variables for workspace: " + workspace.getWorkspaceString() + ". Number of variables found: " + variablesForWorkspace.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public void testVariableCompletionItem() throws BadLocationException {
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <httpEndpoint host=\"*\" httpPort=\"de|\"\n",//
" <httpEndpoint host=\"*\" httpPort=\"${de|\"\n",//
" httpsPort=\"${default.https.port}\" id=\"defaultHttpEndpoint\"/>",//
"</server>" //
);
Expand Down Expand Up @@ -364,6 +364,20 @@ public void testVariableCompletionItem() throws BadLocationException {
"</server>" //
);
XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, 0);

// here completion should be zero, even though user has used a valid variable prefix,
// because its not started with ${
serverXML = String.join(newLine, //
"<server description=\"Sample Liberty server\">", //
" <featureManager>", //
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <httpEndpoint host=\"*\" httpPort=\"default|\"\n",//
" httpsPort=\"${default.https.port}\" id=\"defaultHttpEndpoint\"/>",//
"</server>" //
);
XMLAssert.testCompletionFor(serverXML, null, serverXMLURI, 0);
}

@Test
Expand All @@ -374,7 +388,7 @@ public void testVariableCompletionItemWithDefaultXsdValues() throws BadLocationE
" <platform>javaee-6.0</platform>", //
" <feature>acmeCA-2.0</feature>", //
" </featureManager>", //
" <httpEndpoint host=\"*\" httpPort=\"f|\"\n",//
" <httpEndpoint host=\"*\" httpPort=\"${f|\"\n",//
" httpsPort=\"${default.https.port}\" id=\"defaultHttpEndpoint\"/>",//
"</server>" //
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public void setupWorkspace() {
.thenReturn(installDir);
libertyUtils.when(() -> LibertyUtils.getFileFromLibertyPluginXml(any(), eq("userDirectory")))
.thenReturn(userDir);
libertyUtils.when(() -> LibertyUtils.getFileFromLibertyPluginXml(any(), eq("serverOutputDirectory")))
.thenReturn(serverDir);
}

@AfterEach
Expand Down

0 comments on commit fd0f62a

Please sign in to comment.