Skip to content

Commit b5b3965

Browse files
ThadHouseakaroml
authored andcommitted
Fix Java Version Parsing (#144)
The Java Version Parsing did not work for OpenJDK 11. Updated to do exactly the parsing the redhat java extension does. Also updates package-lock.json, because my npm install did that and they should match
1 parent f66e302 commit b5b3965

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

package-lock.json

Lines changed: 5 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/java-runtime/index.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,38 @@ const isWindows = process.platform.indexOf("win") === 0;
1414
const JAVAC_FILENAME = path.join("bin", "javac" + (isWindows ? ".exe" : "")) ;
1515
const JAVA_FILENAME = path.join("bin", "java" + (isWindows ? ".exe" : ""));
1616

17+
// Taken from https://github.com/Microsoft/vscode-java-debug/blob/7abda575111e9ce2221ad9420330e7764ccee729/src/launchCommand.ts
18+
19+
function parseMajorVersion(content: string): number {
20+
let regexp = /version "(.*)"/g;
21+
let match = regexp.exec(content);
22+
if (!match) {
23+
return 0;
24+
}
25+
let version = match[1];
26+
// Ignore '1.' prefix for legacy Java versions
27+
if (version.startsWith("1.")) {
28+
version = version.substring(2);
29+
}
30+
31+
// look into the interesting bits now
32+
regexp = /\d+/g;
33+
match = regexp.exec(version);
34+
let javaVersion = 0;
35+
if (match) {
36+
javaVersion = parseInt(match[0], 10);
37+
}
38+
return javaVersion;
39+
}
40+
1741
async function getJavaVersion(javaHome: string | undefined): Promise<number> {
1842
if (!javaHome) {
1943
return Promise.resolve(0);
2044
}
2145

2246
return new Promise<number>((resolve, reject) => {
2347
cp.execFile(path.resolve(javaHome, JAVA_FILENAME),["-version"], {}, (err, stdout, stderr) => {
24-
const regex = /version "(\d+)\.(\d+).*"/g;
25-
const match = regex.exec(stderr);
26-
if (!match) {
27-
resolve(0);
28-
return;
29-
}
30-
31-
let major = parseInt(match[1]), minor = parseInt(match[2]);
32-
if (major === 1) {
33-
resolve(minor);
34-
}
35-
36-
resolve(major);
48+
resolve(parseMajorVersion(stderr));
3749
});
3850
});
3951
}

0 commit comments

Comments
 (0)