Skip to content

Commit

Permalink
change regex pattern to find java version
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Mar 1, 2024
1 parent 664f924 commit 1d7f7f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IJavaHomeInfo } from "@viperproject/locate-java-home/js/es5/lib/interfaces";
import path from "path";

const exampleJavaVersionString = `openjdk 17.0.1 2021-10-19
const exampleJavaVersionString = `openjdk "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39)
OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)`;

Expand Down
4 changes: 2 additions & 2 deletions packages/metals-languageclient/src/getJavaHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getJavaHome(
return fromEnvValue ? fromEnvValue : await locate(javaVersion);
}

const versionRegex = /\d+\.\d+\.\d+/;
const versionRegex = /\"\d\d/;
async function validateJavaVersion(
javaHome: string,
javaVersion: JavaVersion,
Expand All @@ -55,7 +55,7 @@ async function validateJavaVersion(
const javaInfoStr = (await javaVersionOut).stderr as string;
const matches = javaInfoStr.match(versionRegex);
if (matches) {
return +matches[0].slice(0, 2) >= +javaVersion;
return +matches[0].slice(1, 3) >= +javaVersion;
}
} catch (error) {
outputChannel.appendLine(`failed while running ${javaBin} -version`);
Expand Down

0 comments on commit 1d7f7f4

Please sign in to comment.