Skip to content

Commit

Permalink
feature: Try and resolve java home if it's a symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Aug 8, 2022
1 parent 35aa218 commit 29478bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/__tests__/getJavaHome.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe("getJavaHome", () => {
expect(javaHome).toBe(javaHomeConfig);
});

it("infers-from-symlink", async () => {
const javaHomeConfig = "/usr/bin/java";
const javaHome = await getJavaHome(javaHomeConfig);
expect(javaHome).not.toBe(javaHomeConfig);
});

it("reads from JAVA_HOME", async () => {
const JAVA_HOME = "/path/to/java";
process.env = { ...originalEnv, JAVA_HOME };
Expand Down
8 changes: 8 additions & 0 deletions src/getJavaHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ function fromConfig(
typeof configuredJavaHome === "string" &&
configuredJavaHome.trim() !== ""
) {
if (fs.existsSync(configuredJavaHome)) {
const stat = fs.lstatSync(configuredJavaHome);
const realpath = fs.realpathSync(configuredJavaHome);
if (stat.isSymbolicLink() && realpath.endsWith(`bin${path.sep}java`)) {
const javaHome = path.dirname(path.dirname(realpath));
return TE.right(javaHome);
}
}
return TE.right(configuredJavaHome);
} else {
return TE.left({});
Expand Down

0 comments on commit 29478bd

Please sign in to comment.