Skip to content

Commit 757b01b

Browse files
Merge pull request #40 from NativeScript/vladimirov/fix-java-check-again
fix: Check for Local Android build disregards issues in Javac version
2 parents 81fe42a + b7351b2 commit 757b01b

File tree

2 files changed

+98
-3
lines changed

2 files changed

+98
-3
lines changed

lib/local-build-requirements/android-local-build-requirements.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ export class AndroidLocalBuildRequirements {
44

55
public async checkRequirements(projectDir?: string, runtimeVersion?: string): Promise<boolean> {
66
const androidToolsInfo = await this.androidToolsInfo.validateInfo();
7-
const javacVersion = await this.sysInfo.getJavaCompilerVersion();
7+
const javacVersion = await this.sysInfo.getJavaCompilerVersion();
8+
const isJavacVersionInvalid = !javacVersion || (await this.androidToolsInfo.validateJavacVersion(javacVersion, projectDir, runtimeVersion)).length;
89
if (androidToolsInfo.length ||
9-
!javacVersion ||
1010
!await this.sysInfo.getAdbVersion() ||
11-
!await this.androidToolsInfo.validateJavacVersion(javacVersion, projectDir, runtimeVersion)) {
11+
isJavacVersionInvalid) {
1212
return false;
1313
}
1414

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { AndroidLocalBuildRequirements } from '../lib/local-build-requirements/android-local-build-requirements';
2+
import { assert } from "chai";
3+
4+
interface ITestCaseData {
5+
testName: string;
6+
validateInfo?: NativeScriptDoctor.IWarning[];
7+
validateJavacVersion?: NativeScriptDoctor.IWarning[];
8+
getJavaCompilerVersion?: string;
9+
getAdbVersion?: string;
10+
}
11+
12+
describe("androidLocalBuildRequirements", () => {
13+
describe("checkRequirements", () => {
14+
const setupTestCase = (results: ITestCaseData): AndroidLocalBuildRequirements => {
15+
const androidToolsInfo: NativeScriptDoctor.IAndroidToolsInfo = {
16+
validateInfo: (): NativeScriptDoctor.IWarning[] => results.validateInfo || [],
17+
validateAndroidHomeEnvVariable: (): NativeScriptDoctor.IWarning[] => [],
18+
getToolsInfo: (): NativeScriptDoctor.IAndroidToolsInfoData => null,
19+
validateJavacVersion: (installedJavaVersion: string, projectDir?: string, runtimeVersion?: string): NativeScriptDoctor.IWarning[] => results.validateJavacVersion || [],
20+
getPathToAdbFromAndroidHome: async (): Promise<string> => undefined,
21+
getPathToEmulatorExecutable: (): string => undefined
22+
};
23+
24+
const sysInfo: NativeScriptDoctor.ISysInfo = {
25+
getJavaCompilerVersion: async (): Promise<string> => results.hasOwnProperty("getJavaCompilerVersion") ? results.getJavaCompilerVersion : "8.0.0",
26+
getAdbVersion: async (pathToAdb?: string): Promise<string> => results.hasOwnProperty("getAdbVersion") ? results.getAdbVersion : "1.0.39",
27+
getXcodeVersion: async (): Promise<string> => undefined,
28+
getNodeVersion: async (): Promise<string> => undefined,
29+
getNpmVersion: async (): Promise<string> => undefined,
30+
getNodeGypVersion: async (): Promise<string> => undefined,
31+
getXcodeprojLocation: async (): Promise<string> => undefined,
32+
isITunesInstalled: async (): Promise<boolean> => false,
33+
getCocoaPodsVersion: async (): Promise<string> => undefined,
34+
getOs: async (): Promise<string> => undefined,
35+
isAndroidInstalled: async (): Promise<boolean> => false,
36+
getMonoVersion: async (): Promise<string> => undefined,
37+
getGitVersion: async (): Promise<string> => undefined,
38+
getGitPath: async (): Promise<string> => undefined,
39+
getGradleVersion: async (): Promise<string> => undefined,
40+
isCocoaPodsWorkingCorrectly: async (): Promise<boolean> => false,
41+
getNativeScriptCliVersion: async (): Promise<string> => undefined,
42+
getXcprojInfo: async (): Promise<NativeScriptDoctor.IXcprojInfo> => null,
43+
isCocoaPodsUpdateRequired: async (): Promise<boolean> => true,
44+
isAndroidSdkConfiguredCorrectly: async (): Promise<boolean> => true,
45+
getSysInfo: async (config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.ISysInfoData> => null,
46+
setShouldCacheSysInfo: (shouldCache: boolean): void => undefined
47+
};
48+
49+
const androidLocalBuildRequirements = new AndroidLocalBuildRequirements(androidToolsInfo, sysInfo);
50+
return androidLocalBuildRequirements;
51+
};
52+
53+
it("returns true when everything is setup correctly", async () => {
54+
const androidLocalBuildRequirements = setupTestCase({ testName: "returns true when everything is setup correctly" });
55+
const result = await androidLocalBuildRequirements.checkRequirements();
56+
assert.isTrue(result);
57+
});
58+
59+
describe("returns false", () => {
60+
const getWarnings = (): NativeScriptDoctor.IWarning[] => {
61+
return [{
62+
warning: "warning",
63+
additionalInformation: "additional info",
64+
platforms: ["android"]
65+
}];
66+
};
67+
const testData: ITestCaseData[] = [
68+
{
69+
testName: "when java is not installed",
70+
getJavaCompilerVersion: null
71+
},
72+
{
73+
testName: "when java is installed, but it is not compatible for current project",
74+
validateJavacVersion: getWarnings()
75+
},
76+
{
77+
testName: "when Android tools are not installed correctly",
78+
validateInfo: getWarnings()
79+
},
80+
{
81+
testName: "when adb cannot be found",
82+
getAdbVersion: null
83+
}
84+
];
85+
86+
testData.forEach(testCase => {
87+
it(testCase.testName, async () => {
88+
const androidLocalBuildRequirements = setupTestCase(testCase);
89+
const result = await androidLocalBuildRequirements.checkRequirements();
90+
assert.isFalse(result);
91+
});
92+
});
93+
});
94+
});
95+
});

0 commit comments

Comments
 (0)