diff --git a/src/extension.ts b/src/extension.ts index 89aee34e..5fc18190 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -303,6 +303,18 @@ async function getJavaExtensionAPI(): Promise { if (!vscodeJava) { throw new Error("VSCode java is not installed"); } + const javaVersion: string = (vscodeJava.packageJSON as Record).version as string ?? ""; + if (javaVersion && isJavaVersionIncompatible(javaVersion)) { + window.showWarningMessage( + localize("redhat.java.version.incompatible", javaVersion), + localize("redhat.java.version.incompatible.open"), + localize("redhat.java.version.incompatible.dismiss") + ).then(selection => { + if (selection === localize("redhat.java.version.incompatible.open")) { + commands.executeCommand("extension.open", JAVA_EXTENSION_ID); + } + }); + } const api = await vscodeJava.activate(); if (!api) { throw new Error("VSCode java api not found"); @@ -310,6 +322,12 @@ async function getJavaExtensionAPI(): Promise { return Promise.resolve(api); } +function isJavaVersionIncompatible(version: string): boolean { + const parts = version.split(".").map(p => parseInt(p, 10)); + const [major = 0, minor = 0] = parts; + return major > 1 || (major === 1 && minor >= 55); +} + async function handleWorkspaceSaveInProgress(context: vscode.ExtensionContext): Promise { const projectProvider = getProjectProvider(context); const wip = projectProvider.getContext().globalState.get('workspaceSaveInProgress'); diff --git a/src/locales/en.json b/src/locales/en.json index 849984ed..3da5cf6d 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -72,5 +72,8 @@ "hotkey.commands.title.add.project": "Liberty: Add Project to Liberty Tools", "hotkey.commands.title.remove.project": "Liberty: Remove Project from Liberty Tools", "hotkey.commands.title.show.commands": "Liberty: Show Liberty commands", - "workspace.not.saved.projects.may.not.persist": "Save the workspace first. Projects that you manually add to Liberty Tools might not persist in the next VS Code session if you don't save the workspace before you add the project." + "workspace.not.saved.projects.may.not.persist": "Save the workspace first. Projects that you manually add to Liberty Tools might not persist in the next VS Code session if you don't save the workspace before you add the project.", + "redhat.java.version.incompatible": "Liberty Tools: The installed 'Language Support for Java' extension (v{0}) is not compatible with this version of Liberty Tools. Jakarta EE diagnostics and quick-fixes will not work correctly. Downgrade 'Language Support for Java' to v1.54.0.", + "redhat.java.version.incompatible.open": "View in Marketplace", + "redhat.java.version.incompatible.dismiss": "Dismiss" } diff --git a/src/test/resources/ci/scripts/exec.sh b/src/test/resources/ci/scripts/exec.sh index b3b8664e..0050f9fb 100755 --- a/src/test/resources/ci/scripts/exec.sh +++ b/src/test/resources/ci/scripts/exec.sh @@ -23,6 +23,9 @@ VSCODE_VERSION_TO_RUN=$2 #Build tool to test (maven or gradle) BUILD_TOOL=${3:-gradle} +# Pinned version of redhat.java that is compatible with Liberty Tools (lsp4jakarta) +REDHAT_JAVA_VERSION="1.54.0" + # Current time. currentTime=(date +"%Y/%m/%d-%H:%M:%S:%3N") @@ -51,6 +54,7 @@ main() { #Initialisation step npm run test-compile + installPinnedRedhatJava # Initialize Maven project if needed if [ "$BUILD_TOOL" = "maven" ]; then @@ -116,6 +120,16 @@ main() { fi } +# Download and install a pinned version of redhat.java from Open VSX to avoid +# pulling 1.55.0+ which is incompatible with lsp4jakarta used by Liberty Tools. +installPinnedRedhatJava() { + local vsix_url="https://open-vsx.org/api/redhat/java/${REDHAT_JAVA_VERSION}/file/redhat.java-${REDHAT_JAVA_VERSION}.vsix" + local vsix_file="/tmp/redhat.java-${REDHAT_JAVA_VERSION}.vsix" + echo "> $(${currentTime[@]}): Installing pinned redhat.java v${REDHAT_JAVA_VERSION} from Open VSX" + curl -fL "$vsix_url" -o "$vsix_file" + npx extest install-vsix "$vsix_file" +} + #start docker and display startDisplayAndDocker() { # Tell the terminal session to use display port 88. diff --git a/src/util/javaServerStarter.ts b/src/util/javaServerStarter.ts index d510901e..9a49cd92 100644 --- a/src/util/javaServerStarter.ts +++ b/src/util/javaServerStarter.ts @@ -24,8 +24,8 @@ import * as glob from 'glob'; import {JAKARTA_LS_JAR, LIBERTY_LS_JAR} from '../extension' const DEBUG = startedInDebugMode(); -const LIBERTY_LS_DEBUG_PORT = 8002; -const JAKARTA_LS_DEBUG_PORT = 8003; +const LIBERTY_LS_DEBUG_PORT = 0; +const JAKARTA_LS_DEBUG_PORT = 0; // Referenced: // https://github.com/redhat-developer/vscode-microprofile/blob/master/src/languageServer/javaServerStarter.ts