Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSNetBeans: Check for source level java compatibility #7555

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion java/java.lsp.server/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion java/java.lsp.server/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@
"@types/ps-node": "^0.1.0",
"@types/vscode": "^1.76.0",
"@types/vscode-webview": "^1.57.1",
"@types/xml2js": "^0.4.14",
"@vscode/codicons": "0.0.29",
"esbuild": "^0.16.17",
"glob": "^7.1.6",
Expand All @@ -1269,7 +1270,8 @@
"@vscode/webview-ui-toolkit": "^1.2.2",
"jdk-utils": "^0.4.4",
"jsonc-parser": "3.0.0",
"vscode-languageclient": "8.0.1"
"vscode-languageclient": "8.0.1",
"xml2js": "^0.6.2"
},
"__metadata": {
"id": "66c7d7dc-934c-499b-94af-5375e8234fdd",
Expand Down
4 changes: 3 additions & 1 deletion java/java.lsp.server/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ import { InputStep, MultiStepInput } from './utils';
import { PropertiesView } from './propertiesView/propertiesView';
import * as configuration from './jdk/configuration';
import * as jdk from './jdk/jdk';
import { validateJDKCompatibility } from './jdk/validation/validation';

const API_VERSION : string = "1.0";
export const COMMAND_PREFIX : string = "nbls";
const DATABASE: string = 'Database';
const listeners = new Map<string, string[]>();
let client: Promise<NbLanguageClient>;
export let client: Promise<NbLanguageClient>;
let testAdapter: NbTestAdapter | undefined;
let nbProcess : ChildProcess | null = null;
let debugPort: number = -1;
Expand Down Expand Up @@ -184,6 +185,7 @@ function findJDK(onChange: (path : string | null) => void): void {
}

let currentJdk = find();
validateJDKCompatibility(currentJdk);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note -- there's a pending PR #7497 that introduces projectJDK. Depending on which one will merge first, the other PR should change to validate the projectJDK

let timeout: NodeJS.Timeout | undefined = undefined;
workspace.onDidChangeConfiguration(params => {
if (timeout) {
Expand Down
32 changes: 32 additions & 0 deletions java/java.lsp.server/vscode/src/jdk/validation/extensionUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import * as vscode from 'vscode';
import { client as nblsClient } from '../../extension';

const RH_EXTENSION_ID = 'redhat.java';

export function isRHExtensionActive(): boolean {
const rh = vscode.extensions.getExtension(RH_EXTENSION_ID);
return rh ? true : false;
}

export async function waitForNblsCommandToBeAvailable() {
await nblsClient;
}
78 changes: 78 additions & 0 deletions java/java.lsp.server/vscode/src/jdk/validation/javaUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as cp from 'child_process';

const JAVA_VERSION_REGEX = /version\s+"(\S+)"/;

function findExecutable(program: string, home: string): string | undefined {
if (home) {
let executablePath = path.join(home, 'bin', program);
if (process.platform === 'win32') {
if (fs.existsSync(executablePath + '.cmd')) {
return executablePath + '.cmd';
}
if (fs.existsSync(executablePath + '.exe')) {
return executablePath + '.exe';
}
} else if (fs.existsSync(executablePath)) {
return executablePath;
}
}
return undefined;
}

export function normalizeJavaVersion(version: string): string {
return version.startsWith("1.") ? version.substring(2) : version;
}

export async function getJavaVersion(homeFolder: string): Promise<string | undefined> {
return new Promise<string | undefined>(resolve => {
if (homeFolder && fs.existsSync(homeFolder)) {
const executable: string | undefined = findExecutable('java', homeFolder);
if (executable) {
cp.execFile(executable, ['-version'], { encoding: 'utf8' }, (_error, _stdout, stderr) => {
if (stderr) {
let javaVersion: string | undefined;
stderr.split('\n').forEach((line: string) => {
const javaInfo: string[] | null = line.match(JAVA_VERSION_REGEX);
if (javaInfo && javaInfo.length > 1) {
javaVersion = javaInfo[1];
}
});
if (javaVersion) {
let majorVersion = normalizeJavaVersion(javaVersion);
let i = majorVersion.indexOf('.');
if (i > -1) {
majorVersion = majorVersion.slice(0, i);
}
resolve(majorVersion);
return;
}
}
resolve(undefined);
});
}
} else {
resolve(undefined);
}
});
}
Loading
Loading