(env, plat, readRc)
| 155 | * injectable for tests. |
| 156 | */ |
| 157 | export async function discoverJavaHome(env, plat, readRc) { |
| 158 | const e = env || {}; |
| 159 | if (e.JAVA_HOME) return e.JAVA_HOME; // already explicit in this process |
| 160 | if (plat === "win32") return null; // not a $JAVA_HOME/rc world |
| 161 | const home = e.HOME || ""; |
| 162 | if (!home) return null; |
| 163 | const shell = e.SHELL || (plat === "darwin" ? "/bin/zsh" : "/bin/bash"); |
| 164 | const names = /zsh/.test(shell) |
| 165 | ? [".zshenv", ".zprofile", ".zshrc"] |
| 166 | : /bash/.test(shell) |
| 167 | ? [".bash_profile", ".bashrc", ".profile"] |
| 168 | : [".profile"]; |
| 169 | const read = |
| 170 | readRc || |
| 171 | (async (p) => { |
| 172 | try { |
| 173 | return await readFile(p, "utf8"); |
| 174 | } catch { |
| 175 | return null; |
| 176 | } |
| 177 | }); |
| 178 | let found = null; |
| 179 | for (const name of names) { |
| 180 | let text = null; |
| 181 | try { |
| 182 | text = await read(join(home, name)); |
| 183 | } catch { |
| 184 | text = null; |
| 185 | } |
| 186 | const val = parseJavaHomeFromRc(text, e); |
| 187 | if (val) found = val; // later rc files (e.g. .zshrc) win |
| 188 | } |
| 189 | return found || null; |
| 190 | } |
| 191 | |
| 192 | /** Probe a single tool. Returns { key, found, version }. */ |
| 193 | export async function probeOne(def, exec) { |
no test coverage detected