forked from apache/netbeans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#7555 from petrovic-d/GCN-4643-java-source-l…
…evel-check VSNetBeans: Check for source level java compatibility
- Loading branch information
Showing
7 changed files
with
439 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
java/java.lsp.server/vscode/src/jdk/validation/extensionUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
78
java/java.lsp.server/vscode/src/jdk/validation/javaUtil.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} |
Oops, something went wrong.