Skip to content

Commit 7cc3b06

Browse files
Merge pull request #37 from NativeScript/vladimirov/validate-against-runtime
feat: Validate Java version based on passed runtime version
2 parents 9f62ba9 + 87369a7 commit 7cc3b06

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

lib/android-tools-info.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
3838
return this.toolsInfo;
3939
}
4040

41-
public validateInfo(projectDir?: string): NativeScriptDoctor.IWarning[] {
41+
public validateInfo(): NativeScriptDoctor.IWarning[] {
4242
const errors: NativeScriptDoctor.IWarning[] = [];
4343
const toolsInfoData = this.getToolsInfo();
4444
const isAndroidHomeValid = this.isAndroidHomeValid();
@@ -88,7 +88,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
8888
return errors;
8989
}
9090

91-
public validateJavacVersion(installedJavaCompilerVersion: string, projectDir?: string): NativeScriptDoctor.IWarning[] {
91+
public validateJavacVersion(installedJavaCompilerVersion: string, projectDir?: string, runtimeVersion?: string): NativeScriptDoctor.IWarning[] {
9292
const errors: NativeScriptDoctor.IWarning[] = [];
9393

9494
let additionalMessage = "You will not be able to build your projects for Android." + EOL
@@ -107,7 +107,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
107107
if (semver.lt(installedJavaCompilerSemverVersion, AndroidToolsInfo.MIN_JAVA_VERSION)) {
108108
warning = `Javac version ${installedJavaCompilerVersion} is not supported. You have to install at least ${AndroidToolsInfo.MIN_JAVA_VERSION}.`;
109109
} else {
110-
const runtimeVersion = this.getAndroidRuntimeVersionFromProjectDir(projectDir);
110+
runtimeVersion = this.getRealRuntimeVersion(runtimeVersion || this.getAndroidRuntimeVersionFromProjectDir(projectDir));
111111
if (runtimeVersion) {
112112
// get the item from the dictionary that corresponds to our current Javac version:
113113
let runtimeMinVersion: string = null;
@@ -355,6 +355,10 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
355355
}
356356
}
357357

358+
return runtimeVersion;
359+
}
360+
361+
private getRealRuntimeVersion(runtimeVersion: string): string {
358362
if (runtimeVersion) {
359363
// Check if the version is not "next" or "rc", i.e. tag from npm
360364
if (!semver.valid(runtimeVersion)) {
@@ -370,7 +374,7 @@ export class AndroidToolsInfo implements NativeScriptDoctor.IAndroidToolsInfo {
370374

371375
if (runtimeVersion && !semver.valid(runtimeVersion)) {
372376
// If we got here, something terribly wrong happened.
373-
throw new Error(`The determined Android runtime version ${runtimeVersion} based on project directory ${projectDir} is not valid. Unable to verify if the current system is setup for Android development.`);
377+
throw new Error(`The determined Android runtime version ${runtimeVersion} is not valid. Unable to verify if the current system is setup for Android development.`);
374378
}
375379

376380
return runtimeVersion;

lib/doctor.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
1616
private sysInfo: NativeScriptDoctor.ISysInfo,
1717
private androidToolsInfo: NativeScriptDoctor.IAndroidToolsInfo) { }
1818

19-
public async canExecuteLocalBuild(platform: string, projectDir?: string): Promise<boolean> {
19+
public async canExecuteLocalBuild(platform: string, projectDir?: string, runtimeVersion?: string): Promise<boolean> {
2020
this.validatePlatform(platform);
2121

2222
if (platform.toLowerCase() === Constants.ANDROID_PLATFORM_NAME.toLowerCase()) {
23-
return await this.androidLocalBuildRequirements.checkRequirements(projectDir);
23+
return await this.androidLocalBuildRequirements.checkRequirements(projectDir, runtimeVersion);
2424
} else if (platform.toLowerCase() === Constants.IOS_PLATFORM_NAME.toLowerCase()) {
2525
return await this.iOSLocalBuildRequirements.checkRequirements();
2626
}
@@ -32,11 +32,11 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
3232
let result: NativeScriptDoctor.IInfo[] = [];
3333
const sysInfoData = await this.sysInfo.getSysInfo(config);
3434

35-
if (!config || !config.platform || config.platform === Constants.ANDROID_PLATFORM_NAME) {
36-
result = result.concat(this.getAndroidInfos(sysInfoData, config && config.projectDir));
35+
if (!config || !config.platform || config.platform.toLowerCase() === Constants.ANDROID_PLATFORM_NAME.toLowerCase()) {
36+
result = result.concat(this.getAndroidInfos(sysInfoData, config && config.projectDir, config && config.androidRuntimeVersion));
3737
}
3838

39-
if (!config || !config.platform || config.platform === Constants.IOS_PLATFORM_NAME) {
39+
if (!config || !config.platform || config.platform.toLowerCase() === Constants.IOS_PLATFORM_NAME.toLowerCase()) {
4040
result = result.concat(await this.getiOSInfos(sysInfoData));
4141
}
4242

@@ -58,7 +58,7 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
5858
.map(item => this.convertInfoToWarning(item));
5959
}
6060

61-
private getAndroidInfos(sysInfoData: NativeScriptDoctor.ISysInfoData, projectDir?: string): NativeScriptDoctor.IInfo[] {
61+
private getAndroidInfos(sysInfoData: NativeScriptDoctor.ISysInfoData, projectDir?: string, runtimeVersion?: string): NativeScriptDoctor.IInfo[] {
6262
let result: NativeScriptDoctor.IInfo[] = [];
6363

6464
result = result.concat(
@@ -92,7 +92,7 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
9292
platforms: [Constants.ANDROID_PLATFORM_NAME]
9393
}),
9494
this.processValidationErrors({
95-
warnings: this.androidToolsInfo.validateJavacVersion(sysInfoData.javacVersion, projectDir),
95+
warnings: this.androidToolsInfo.validateJavacVersion(sysInfoData.javacVersion, projectDir, runtimeVersion),
9696
infoMessage: "Javac is installed and is configured properly.",
9797
platforms: [Constants.ANDROID_PLATFORM_NAME]
9898
}),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ export class AndroidLocalBuildRequirements {
22
constructor(private androidToolsInfo: NativeScriptDoctor.IAndroidToolsInfo,
33
private sysInfo: NativeScriptDoctor.ISysInfo) { }
44

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

lib/sys-info.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
221221
}
222222

223223
public async getSysInfo(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.ISysInfoData> {
224-
if (config && config.platform === Constants.ANDROID_PLATFORM_NAME) {
224+
if (config && config.platform && config.platform.toLowerCase() === Constants.ANDROID_PLATFORM_NAME.toLowerCase()) {
225225
return <NativeScriptDoctor.ISysInfoData>Object.assign(await this.getCommonSysInfo(), await this.getAndroidSysInfo(config));
226226
}
227227

228-
if (config && config.platform === Constants.IOS_PLATFORM_NAME) {
228+
if (config && config.platform && config.platform.toLowerCase() === Constants.IOS_PLATFORM_NAME.toLowerCase()) {
229229
return <NativeScriptDoctor.ISysInfoData>Object.assign(await this.getCommonSysInfo(), await this.getiOSSysInfo());
230230
}
231231

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-doctor",
3-
"version": "1.1.0",
3+
"version": "1.2.0-rc.0",
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",

typings/interfaces.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ declare module NativeScriptDoctor {
166166
* If it is not passed or the project does not have Android runtime, this validation is skipped.
167167
*/
168168
projectDir?: string;
169+
170+
/**
171+
* The runtime version against which the validation is executed. In case this parameter is passed, it takes precedence over the projectDir argument.
172+
*/
173+
androidRuntimeVersion?: string;
169174
}
170175

171176
/**
@@ -175,9 +180,12 @@ declare module NativeScriptDoctor {
175180
/**
176181
* Checks if a local build can be executed on the current machine.
177182
* @param {string} platform The platform for which to check if local build is possible.
183+
* @param {string} projectDir @optional The project directory. Used to determine the Android Runtime version and validate the Java compiler version against it.
184+
* If it is not passed or the project does not have Android runtime, this validation is skipped.
185+
* @param {string} runtimeVersion @optional The runtime version against which the validation is executed. In case this parameter is passed, it takes precedence over the projectDir argument.
178186
* @return {Promise<boolean>} true if local build can be executed for the provided platform.
179187
*/
180-
canExecuteLocalBuild(platform: string): Promise<boolean>;
188+
canExecuteLocalBuild(platform: string, projectDir?: string, runtimeVersion?: string): Promise<boolean>;
181189

182190
/**
183191
* Executes all checks for the current environment and returns the warnings from each check.
@@ -430,20 +438,19 @@ declare module NativeScriptDoctor {
430438

431439
/**
432440
* Checks if the Android tools are valid.
433-
* @param {string} projectDir @optional The project directory. Used to determine the Android Runtime version and validate the Java compiler version against it.
434-
* If it is not passed or the project does not have Android runtime, this validation is skipped.
435441
* @return {NativeScriptDoctor.IWarning[]} An array of errors from the validation checks. If there are no errors will return [].
436442
*/
437-
validateInfo(projectDir?: string): NativeScriptDoctor.IWarning[];
443+
validateInfo(): NativeScriptDoctor.IWarning[];
438444

439445
/**
440446
* Checks if the current javac version is valid.
441447
* @param {string} installedJavaVersion The version of javac to check.
442448
* @param {string} projectDir @optional The project directory. Used to determine the Android Runtime version and validate the Java compiler version against it.
443449
* If it is not passed or the project does not have Android runtime, this validation is skipped.
450+
* @param {string} runtimeVersion @optional The runtime version against which the validation is executed. In case this parameter is passed, it takes precedence over the projectDir argument.
444451
* @return {NativeScriptDoctor.IWarning[]} An array of errors from the validation checks. If there are no errors will return [].
445452
*/
446-
validateJavacVersion(installedJavaVersion: string, projectDir?: string): NativeScriptDoctor.IWarning[];
453+
validateJavacVersion(installedJavaVersion: string, projectDir?: string, runtimeVersion?: string): NativeScriptDoctor.IWarning[];
447454

448455
/**
449456
* Returns the path to the adb which is located in ANDROID_HOME.

0 commit comments

Comments
 (0)