Skip to content

Commit

Permalink
Merge branch 'main' into customConfigSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
evie-lau authored Oct 3, 2023
2 parents ffdad94 + 586068e commit 7381937
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
import io.openliberty.tools.intellij.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -33,18 +31,10 @@ public class LibertyConfigLanguageServer extends ProcessStreamConnectionProvider
private static final Logger LOGGER = LoggerFactory.getLogger(LibertyConfigLanguageServer.class);

public LibertyConfigLanguageServer() {
String javaHome = System.getProperty("java.home");
IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij"));
File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-jar-with-dependencies.jar");
String javaHome = System.getProperty("java.home");
if (javaHome == null) {
LOGGER.error("Unable to launch the Liberty language server. Could not resolve the java home system property");
return;
}
if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) {
LOGGER.error("Unable to launch the Liberty language server." +
" Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." +
" Change the boot Java runtime of the IDE as documented here:" +
" https://www.jetbrains.com/help/idea/switching-boot-jdk.html");
if(!isJavaHomeValid(javaHome, Constants.LIBERTY_CONFIG_SERVER)){
return;
}
if (libertyServerPath.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,11 @@ public class LibertyXmlServer extends ProcessStreamConnectionProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(LibertyXmlServer.class);

public LibertyXmlServer() {
String javaHome = System.getProperty("java.home");
IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij"));
File lemminxServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lemminx-uber.jar");
File libertyServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/liberty-langserver-lemminx-jar-with-dependencies.jar");
String javaHome = System.getProperty("java.home");
if (javaHome == null) {
LOGGER.error("Unable to launch the LemMinX language server. Could not resolve the java home system property");
return;
}
if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) {
LOGGER.error("Unable to launch the LemMinX language server." +
" Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." +
" Change the boot Java runtime of the IDE as documented here:" +
" https://www.jetbrains.com/help/idea/switching-boot-jdk.html");
if(!isJavaHomeValid(javaHome, Constants.LIBERTY_XML_SERVER)){
return;
}
if (lemminxServerPath.exists() && libertyServerPath.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,10 @@ public class JakartaLanguageServer extends ProcessStreamConnectionProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(JakartaLanguageServer.class);

public JakartaLanguageServer() {
String javaHome = System.getProperty("java.home");
IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij"));
File lsp4JakartaServerPath = new File(descriptor.getPluginPath().toFile(), JAR_DIR + LANGUAGESERVER_JAR);
String javaHome = System.getProperty("java.home");
if (javaHome == null) {
LOGGER.error("Unable to launch the Eclipse LSP4Jakarta language server. Could not resolve the java home system property");
return;
}
if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) {
LOGGER.error("Unable to launch the Eclipse LSP4Jakarta language server." +
" Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." +
" Change the boot Java runtime of the IDE as documented here:" +
" https://www.jetbrains.com/help/idea/switching-boot-jdk.html");
if(!isJavaHomeValid(javaHome, Constants.JAKARTA_LANG_SERVER)){
return;
}
if (lsp4JakartaServerPath.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.openapi.extensions.PluginId;
import io.openliberty.tools.intellij.liberty.lsp.LibertyXmlServer;
import io.openliberty.tools.intellij.lsp4mp.lsp4ij.server.ProcessStreamConnectionProvider;
import io.openliberty.tools.intellij.util.Constants;
import org.slf4j.Logger;
Expand All @@ -34,18 +33,10 @@ public class MicroProfileServer extends ProcessStreamConnectionProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(MicroProfileServer.class);

public MicroProfileServer() {
String javaHome = System.getProperty("java.home");
IdeaPluginDescriptor descriptor = PluginManagerCore.getPlugin(PluginId.getId("open-liberty.intellij"));
File lsp4mpServerPath = new File(descriptor.getPluginPath().toFile(), "lib/server/org.eclipse.lsp4mp.ls-uber.jar");
String javaHome = System.getProperty("java.home");
if (javaHome == null) {
LOGGER.error("Unable to launch the Eclipse LSP4MP language server. Could not resolve the java home system property");
return;
}
if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) {
LOGGER.error("Unable to launch the Eclipse LSP4MP language server." +
" Java " + Constants.REQUIRED_JAVA_VERSION + " or more recent is required to run 'Liberty Tools for IntelliJ'." +
" Change the boot Java runtime of the IDE as documented here:" +
" https://www.jetbrains.com/help/idea/switching-boot-jdk.html");
if(!isJavaHomeValid(javaHome, Constants.MICROPROFILE_SERVER)){
return;
}
if (lsp4mpServerPath.exists()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package io.openliberty.tools.intellij.lsp4mp.lsp4ij.server;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import io.openliberty.tools.intellij.LibertyPluginIcons;
import io.openliberty.tools.intellij.util.Constants;
import io.openliberty.tools.intellij.util.LocalizedResourceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import javax.annotation.Nullable;
import java.io.*;
import java.util.List;
Expand Down Expand Up @@ -160,5 +170,44 @@ public String toString() {
return "ProcessStreamConnectionProvider [commands=" + this.getCommands() + ", workingDir=" //$NON-NLS-1$//$NON-NLS-2$
+ this.getWorkingDirectory() + "]"; //$NON-NLS-1$
}
public boolean isJavaHomeValid(String javaHome, String serverType) {

if (javaHome == null) {
String errorMessage = LocalizedResourceUtil.getMessage("javaHome.is.null", serverType, Constants.REQUIRED_JAVA_VERSION);
LOGGER.error(errorMessage);
showErrorPopup(errorMessage);
return false;
}

File javaHomeDir = new File(javaHome);
if (!javaHomeDir.exists()) {
String errorMessage = LocalizedResourceUtil.getMessage("javaHomeDir.does.not.exist", serverType, Constants.REQUIRED_JAVA_VERSION);
LOGGER.error(errorMessage);
showErrorPopup(errorMessage);
return false;
}

if (!checkJavaVersion(javaHome, Constants.REQUIRED_JAVA_VERSION)) {
String errorMessage = LocalizedResourceUtil.getMessage("java.version.message", serverType, Constants.REQUIRED_JAVA_VERSION);
LOGGER.error(errorMessage);
showErrorPopup(errorMessage);
return false;
}
return true;
}

private void notifyError(String errMsg, Project project) {
Notification notif = new Notification(Constants.LIBERTY_DEV_DASHBOARD_ID, errMsg, NotificationType.WARNING)
.setTitle(LocalizedResourceUtil.getMessage("java.runtime.error.message"))
.setIcon(LibertyPluginIcons.libertyIcon)
.setSubtitle("")
.setListener(NotificationListener.URL_OPENING_LISTENER);
Notifications.Bus.notify(notif, project);
}

private void showErrorPopup(String errorMessage) {
notifyError(errorMessage, ProjectManager.getInstance().getDefaultProject());

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@ public final class Constants {
* Constants for langauge servers
*/
public static final String SERVER_ENV_GLOB_PATTERN = "**/*.env";

public static final String LIBERTY_XML_SERVER = "LemMinX";
public static final String LIBERTY_CONFIG_SERVER="Liberty Config";
public static final String JAKARTA_LANG_SERVER="Eclipse LSP4Jakarta";
public static final String MICROPROFILE_SERVER="Eclipse LSP4MP";

}
6 changes: 6 additions & 0 deletions src/main/resources/messages/LibertyBundles.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ liberty.project.file.selection.dialog.message=Select Liberty project for {0}
liberty.action.selection.dialog.title=Liberty action
liberty.action.selection.dialog.message=Select Liberty action to run

#Messages for Checking javaHome
javaHome.is.null=Unable to launch the {0} language server. Could not resolve the java home system property. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here <a href="https://www.jetbrains.com/help/idea/switching-boot-jdk.html">https://www.jetbrains.com/help/idea/switching-boot-jdk.html</a>
javaHomeDir.does.not.exist=Unable to launch the {0} language server. The java home directory does not exist. Make sure the boot Java runtime of the IDE is set to a valid JDK of Java {1} or later. Change the boot Java runtime of the IDE as documented here <a href="https://www.jetbrains.com/help/idea/switching-boot-jdk.html">https://www.jetbrains.com/help/idea/switching-boot-jdk.html</a>
java.version.message=Unable to launch the {0} language server. Java {1} or more recent is required to run 'Liberty Tools for IntelliJ'. Change the boot Java runtime of the IDE as documented here <a href="https://www.jetbrains.com/help/idea/switching-boot-jdk.html">https://www.jetbrains.com/help/idea/switching-boot-jdk.html</a>
java.runtime.error.message=Java runtime error

# Messages for Liberty add and remove project actions
liberty.project.add=add Liberty project
liberty.project.add.dialog.title=Add Liberty project
Expand Down

0 comments on commit 7381937

Please sign in to comment.