Skip to content

Commit

Permalink
chore: Improve output information for the users
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed May 14, 2024
1 parent a082109 commit b0b0f4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ describe("getJavaHome", () => {
const javaPaths = [{ binPath: path.join(JAVA_HOME, "bin", "java") }];
mockSpawn(exampleJavaVersionString);
mockExistsFs(javaPaths);
const javaHome = await require("../getJavaHome").getJavaHome("17");
const javaHome = await require("../getJavaHome").getJavaHome(
"17",
new MockOutput()
);
expect(javaHome).toBe(JAVA_HOME);
});

Expand Down
17 changes: 15 additions & 2 deletions packages/metals-languageclient/src/getJavaHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function validateJavaVersion(

javaVersionOut.stderr?.on("data", (out: Buffer) => {
outputChannel.appendLine(`${javaBin} -version:`);
const msg = out.toString().trim();
const msg = "\t" + out.toString().trim().split("\n").join("\n\t");
outputChannel.appendLine(msg);
});

Expand All @@ -62,7 +62,7 @@ export async function fromPath(
if (javaExecutable) {
let realJavaPath = realpathSync(javaExecutable);
outputChannel.appendLine(
`Found java executable under ${javaExecutable} that resolves to ${realJavaPath}`
`Searching for Java on PATH. Found java executable under ${javaExecutable} that resolves to ${realJavaPath}`
);
const possibleJavaHome = path.dirname(path.dirname(realJavaPath));
const isValid = await validateJavaVersion(
Expand All @@ -71,6 +71,11 @@ export async function fromPath(
outputChannel
);
if (isValid) return possibleJavaHome;
else {
outputChannel.appendLine(
`Java version doesn't match the required one of ${javaVersion}`
);
}
}
}

Expand All @@ -80,12 +85,20 @@ export async function fromEnv(
): Promise<string | undefined> {
const javaHome = process.env["JAVA_HOME"];
if (javaHome) {
outputChannel.appendLine(
`Checking Java in JAVA_HOME, which points to ${javaHome}`
);
const isValid = await validateJavaVersion(
javaHome,
javaVersion,
outputChannel
);
if (isValid) return javaHome;
else {
outputChannel.appendLine(
`Java version doesn't match the required one of ${javaVersion}`
);
}
}

return undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/metals-languageclient/src/setupCoursier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function setupCoursier(
): Promise<{ coursier: string; javaHome: string }> {
const handleOutput = (out: Buffer) => {
const msg = out.toString().trim();
output.appendLine("Coursier: " + msg);
output.appendLine("Coursier: \n" + msg);
};

const resolveCoursier = async () => {
Expand Down

0 comments on commit b0b0f4f

Please sign in to comment.