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

chore: Improve output information for the users #1502

Merged
merged 1 commit into from
May 29, 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
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
Loading