Skip to content

Commit 5de8529

Browse files
committed
Add incompatibility warning for redhat.java >= 1.55.0
1 parent 6d9bb6a commit 5de8529

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

src/extension.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,31 @@ async function getJavaExtensionAPI(): Promise<JavaExtensionAPI> {
303303
if (!vscodeJava) {
304304
throw new Error("VSCode java is not installed");
305305
}
306+
const javaVersion: string = (vscodeJava.packageJSON as Record<string, unknown>).version as string ?? "";
307+
if (javaVersion && isJavaVersionIncompatible(javaVersion)) {
308+
window.showWarningMessage(
309+
localize("redhat.java.version.incompatible", javaVersion),
310+
localize("redhat.java.version.incompatible.open"),
311+
localize("redhat.java.version.incompatible.dismiss")
312+
).then(selection => {
313+
if (selection === localize("redhat.java.version.incompatible.open")) {
314+
commands.executeCommand("extension.open", JAVA_EXTENSION_ID);
315+
}
316+
});
317+
}
306318
const api = await vscodeJava.activate();
307319
if (!api) {
308320
throw new Error("VSCode java api not found");
309321
}
310322
return Promise.resolve(api);
311323
}
312324

325+
function isJavaVersionIncompatible(version: string): boolean {
326+
const parts = version.split(".").map(p => parseInt(p, 10));
327+
const [major = 0, minor = 0] = parts;
328+
return major > 1 || (major === 1 && minor >= 55);
329+
}
330+
313331
async function handleWorkspaceSaveInProgress(context: vscode.ExtensionContext): Promise<boolean> {
314332
const projectProvider = getProjectProvider(context);
315333
const wip = projectProvider.getContext().globalState.get('workspaceSaveInProgress');

src/locales/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,8 @@
7272
"hotkey.commands.title.add.project": "Liberty: Add Project to Liberty Tools",
7373
"hotkey.commands.title.remove.project": "Liberty: Remove Project from Liberty Tools",
7474
"hotkey.commands.title.show.commands": "Liberty: Show Liberty commands",
75-
"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."
75+
"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.",
76+
"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.",
77+
"redhat.java.version.incompatible.open": "View in Marketplace",
78+
"redhat.java.version.incompatible.dismiss": "Dismiss"
7679
}

src/test/resources/ci/scripts/exec.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ VSCODE_VERSION_TO_RUN=$2
2323
#Build tool to test (maven or gradle)
2424
BUILD_TOOL=${3:-gradle}
2525

26+
# Pinned version of redhat.java that is compatible with Liberty Tools (lsp4jakarta)
27+
REDHAT_JAVA_VERSION="1.54.0"
28+
2629
# Current time.
2730
currentTime=(date +"%Y/%m/%d-%H:%M:%S:%3N")
2831

@@ -51,6 +54,7 @@ main() {
5154

5255
#Initialisation step
5356
npm run test-compile
57+
installPinnedRedhatJava
5458

5559
# Initialize Maven project if needed
5660
if [ "$BUILD_TOOL" = "maven" ]; then
@@ -116,6 +120,16 @@ main() {
116120
fi
117121
}
118122

123+
# Download and install a pinned version of redhat.java from Open VSX to avoid
124+
# pulling 1.55.0+ which is incompatible with lsp4jakarta used by Liberty Tools.
125+
installPinnedRedhatJava() {
126+
local vsix_url="https://open-vsx.org/api/redhat/java/${REDHAT_JAVA_VERSION}/file/redhat.java-${REDHAT_JAVA_VERSION}.vsix"
127+
local vsix_file="/tmp/redhat.java-${REDHAT_JAVA_VERSION}.vsix"
128+
echo "> $(${currentTime[@]}): Installing pinned redhat.java v${REDHAT_JAVA_VERSION} from Open VSX"
129+
curl -fL "$vsix_url" -o "$vsix_file"
130+
npx extest install-vsix "$vsix_file"
131+
}
132+
119133
#start docker and display
120134
startDisplayAndDocker() {
121135
# Tell the terminal session to use display port 88.

src/util/javaServerStarter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import * as glob from 'glob';
2424
import {JAKARTA_LS_JAR, LIBERTY_LS_JAR} from '../extension'
2525

2626
const DEBUG = startedInDebugMode();
27-
const LIBERTY_LS_DEBUG_PORT = 8002;
28-
const JAKARTA_LS_DEBUG_PORT = 8003;
27+
const LIBERTY_LS_DEBUG_PORT = 0;
28+
const JAKARTA_LS_DEBUG_PORT = 0;
2929

3030
// Referenced:
3131
// https://github.com/redhat-developer/vscode-microprofile/blob/master/src/languageServer/javaServerStarter.ts

0 commit comments

Comments
 (0)