Skip to content

Commit 34c042c

Browse files
Merge pull request #51 from NativeScript/vladimirov/fix-javac-detection
fix: javac detection does not work as required by Gradle
2 parents 1d934b8 + 6cd9eaf commit 34c042c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

lib/sys-info.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
6161

6262
public getJavaCompilerVersion(): Promise<string> {
6363
return this.getValueForProperty(() => this.javaCompilerVerCache, async (): Promise<string> => {
64-
const javacVersion = (await this.getVersionOfJavaExecutableFromJavaHome(Constants.JAVAC_EXECUTABLE_NAME, SysInfo.JAVA_COMPILER_VERSION_REGEXP)) ||
64+
const javacVersion = process.env["JAVA_HOME"] ? (await this.getVersionOfJavaExecutableFromJavaHome(Constants.JAVAC_EXECUTABLE_NAME, SysInfo.JAVA_COMPILER_VERSION_REGEXP)) :
6565
(await this.getVersionOfJavaExecutableFromPath(Constants.JAVAC_EXECUTABLE_NAME, SysInfo.JAVA_COMPILER_VERSION_REGEXP));
6666

6767
return javacVersion;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-doctor",
3-
"version": "1.9.1",
3+
"version": "1.9.2",
44
"description": "Library that helps identifying if the environment can be used for development of {N} apps.",
55
"main": "lib/index.js",
66
"types": "./typings/nativescript-doctor.d.ts",

test/sys-info.ts

+25
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,31 @@ describe("SysInfo unit tests", () => {
241241
assert.deepEqual(execCommands, ['which javac', '"javac" -version']);
242242
});
243243

244+
it("null when there is incorrect JAVA_HOME on non-Windows OS", async () => {
245+
const originalJavaHome = process.env[JavaHomeName];
246+
process.env[JavaHomeName] = "/some/invalid/dir/name/where/java/does/not/exist";
247+
248+
const result = await sysInfo.getJavaCompilerVersion();
249+
250+
process.env[JavaHomeName] = originalJavaHome;
251+
252+
assert.deepEqual(result, null);
253+
assert.deepEqual(execCommands, []);
254+
});
255+
256+
it("null when there is incorrect JAVA_HOME on Window OS", async () => {
257+
const originalJavaHome = process.env[JavaHomeName];
258+
hostInfo.isWindows = true;
259+
process.env[JavaHomeName] = "C:\\Program Files\\Not existing dir";
260+
261+
const result = await sysInfo.getJavaCompilerVersion();
262+
263+
process.env[JavaHomeName] = originalJavaHome;
264+
265+
assert.deepEqual(result, null);
266+
assert.deepEqual(execCommands, []);
267+
});
268+
244269
it("java compiler version when there is no JAVA_HOME on Window OS", async () => {
245270
const originalJavaHome = process.env[JavaHomeName];
246271
hostInfo.isWindows = true;

0 commit comments

Comments
 (0)