Skip to content

Commit 2faf235

Browse files
Merge pull request #3626 from NativeScript/vladimirov/fix-platform-commands
fix: platform update/clean commands may fail with Java 10
2 parents 47c4c70 + 4f98f8b commit 2faf235

11 files changed

+71
-41
lines changed

lib/commands/platform-clean.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class CleanCommand implements ICommand {
55
private $projectData: IProjectData,
66
private $platformService: IPlatformService,
77
private $errors: IErrors,
8-
private $platformsData: IPlatformsData) {
8+
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements) {
99
this.$projectData.initializeProjectData();
1010
}
1111

@@ -18,12 +18,15 @@ export class CleanCommand implements ICommand {
1818
this.$errors.fail("No platform specified. Please specify a platform to clean");
1919
}
2020

21+
_.each(args, platform => {
22+
this.$platformService.validatePlatform(platform, this.$projectData);
23+
});
24+
2125
for (const platform of args) {
2226
this.$platformService.validatePlatformInstalled(platform, this.$projectData);
2327

24-
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
25-
const platformProjectService = platformData.platformProjectService;
26-
await platformProjectService.validate(this.$projectData);
28+
const currentRuntimeVersion = this.$platformService.getCurrentPlatformVersion(platform, this.$projectData);
29+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(platform, this.$projectData.projectDir, currentRuntimeVersion);
2730
}
2831

2932
return true;

lib/commands/update-platform.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export class UpdatePlatformCommand implements ICommand {
44
constructor(private $options: IOptions,
55
private $projectData: IProjectData,
66
private $platformService: IPlatformService,
7-
private $errors: IErrors,
8-
private $platformsData: IPlatformsData) {
7+
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
8+
private $errors: IErrors) {
99
this.$projectData.initializeProjectData();
1010
}
1111

@@ -18,12 +18,24 @@ export class UpdatePlatformCommand implements ICommand {
1818
this.$errors.fail("No platform specified. Please specify platforms to update.");
1919
}
2020

21-
for (const arg of args) {
21+
_.each(args, arg => {
2222
const platform = arg.split("@")[0];
2323
this.$platformService.validatePlatform(platform, this.$projectData);
24-
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
25-
const platformProjectService = platformData.platformProjectService;
26-
await platformProjectService.validate(this.$projectData);
24+
});
25+
26+
for (const arg of args) {
27+
const [ platform, versionToBeInstalled ] = arg.split("@");
28+
this.$platformService.validatePlatformInstalled(platform, this.$projectData);
29+
const argsToCheckEnvironmentRequirements: string[] = [ platform ];
30+
// If version is not specified, we know the command will install the latest compatible Android runtime.
31+
// The latest compatible Android runtime supports Java version, so we do not need to pass it here.
32+
// Passing projectDir to the nativescript-doctor validation will cause it to check the runtime from the current package.json
33+
// So in this case, where we do not want to validate the runtime, just do not pass both projectDir and runtimeVersion.
34+
if (versionToBeInstalled) {
35+
argsToCheckEnvironmentRequirements.push(this.$projectData.projectDir, versionToBeInstalled);
36+
}
37+
38+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(...argsToCheckEnvironmentRequirements);
2739
}
2840

2941
return true;

lib/common

lib/definitions/platform.d.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
214214
* @returns {void}
215215
*/
216216
saveBuildInfoFile(platform: string, projectDir: string, buildInfoFileDirname: string): void;
217+
218+
/**
219+
* Gives information for the current version of the runtime.
220+
* @param {string} platform The platform to be checked.
221+
* @param {IProjectData} projectData The data describing the project
222+
* @returns {string} Runtime version
223+
*/
224+
getCurrentPlatformVersion(platform: string, projectData: IProjectData): string;
217225
}
218226

219227
interface IPlatformOptions extends IPlatformSpecificData, ICreateProjectOptions { }
@@ -381,5 +389,5 @@ interface IUpdateAppOptions extends IOptionalFilesToSync, IOptionalFilesToRemove
381389
}
382390

383391
interface IPlatformEnvironmentRequirements {
384-
checkEnvironmentRequirements(platform?: string, projectDir?: string): Promise<boolean>;
385-
}
392+
checkEnvironmentRequirements(platform?: string, projectDir?: string, runtimeVersion?: string): Promise<boolean>;
393+
}

lib/services/doctor-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class DoctorService implements IDoctorService {
1717
private $terminalSpinnerService: ITerminalSpinnerService,
1818
private $versionsService: IVersionsService) { }
1919

20-
public async printWarnings(configOptions?: { trackResult: boolean , projectDir?: string }): Promise<void> {
20+
public async printWarnings(configOptions?: { trackResult: boolean , projectDir?: string, runtimeVersion?: string }): Promise<void> {
2121
const infos = await this.$terminalSpinnerService.execute<NativeScriptDoctor.IInfo[]>({
2222
text: `Getting environment information ${EOL}`
23-
}, () => doctor.getInfos({ projectDir: configOptions && configOptions.projectDir }));
23+
}, () => doctor.getInfos({ projectDir: configOptions && configOptions.projectDir, androidRuntimeVersion: configOptions && configOptions.runtimeVersion }));
2424

2525
const warnings = infos.filter(info => info.type === constants.WARNING_TYPE_NAME);
2626
const hasWarnings = warnings.length > 0;
@@ -80,12 +80,12 @@ class DoctorService implements IDoctorService {
8080
});
8181
}
8282

83-
public async canExecuteLocalBuild(platform?: string, projectDir?: string): Promise<boolean> {
83+
public async canExecuteLocalBuild(platform?: string, projectDir?: string, runtimeVersion?: string): Promise<boolean> {
8484
await this.$analyticsService.trackEventActionInGoogleAnalytics({
8585
action: TrackActionNames.CheckLocalBuildSetup,
8686
additionalData: "Starting",
8787
});
88-
const infos = await doctor.getInfos({ platform, projectDir });
88+
const infos = await doctor.getInfos({ platform, projectDir, androidRuntimeVersion: runtimeVersion });
8989

9090
const warnings = this.filterInfosByType(infos, constants.WARNING_TYPE_NAME);
9191
const hasWarnings = warnings.length > 0;

lib/services/platform-environment-requirements.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
3030
"deploy": "tns cloud deploy"
3131
};
3232

33-
public async checkEnvironmentRequirements(platform?: string, projectDir?: string): Promise<boolean> {
33+
public async checkEnvironmentRequirements(platform?: string, projectDir?: string, runtimeVersion?: string): Promise<boolean> {
3434
if (process.env.NS_SKIP_ENV_CHECK) {
3535
await this.$analyticsService.trackEventActionInGoogleAnalytics({
3636
action: TrackActionNames.CheckEnvironmentRequirements,
@@ -39,7 +39,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
3939
return true;
4040
}
4141

42-
const canExecute = await this.$doctorService.canExecuteLocalBuild(platform, projectDir);
42+
const canExecute = await this.$doctorService.canExecuteLocalBuild(platform, projectDir, runtimeVersion);
4343
if (!canExecute) {
4444
if (!isInteractive()) {
4545
await this.$analyticsService.trackEventActionInGoogleAnalytics({
@@ -71,7 +71,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
7171
if (selectedOption === PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME) {
7272
await this.$doctorService.runSetupScript();
7373

74-
if (await this.$doctorService.canExecuteLocalBuild(platform, projectDir)) {
74+
if (await this.$doctorService.canExecuteLocalBuild(platform, projectDir, runtimeVersion)) {
7575
return true;
7676
}
7777

@@ -102,7 +102,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
102102

103103
if (selectedOption === PlatformEnvironmentRequirements.BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME) {
104104
await this.processBothCloudBuildsAndSetupScript();
105-
if (await this.$doctorService.canExecuteLocalBuild(platform, projectDir)) {
105+
if (await this.$doctorService.canExecuteLocalBuild(platform, projectDir, runtimeVersion)) {
106106
return true;
107107
}
108108

lib/services/platform-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
7474
}
7575
}
7676

77-
private getCurrentPlatformVersion(platform: string, projectData: IProjectData): string {
77+
public getCurrentPlatformVersion(platform: string, projectData: IProjectData): string {
7878
const platformData = this.$platformsData.getPlatformData(platform, projectData);
7979
const currentPlatformData: any = this.$projectDataService.getNSValue(projectData.projectDir, platformData.frameworkPackageName);
8080
let version: string;

npm-shrinkwrap.json

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"minimatch": "3.0.2",
5454
"mkdirp": "0.5.1",
5555
"mute-stream": "0.0.5",
56-
"nativescript-doctor": "1.1.0",
56+
"nativescript-doctor": "1.2.0",
5757
"open": "0.0.5",
5858
"ora": "2.0.0",
5959
"osenv": "0.1.3",

test/platform-commands.ts

+3
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ function createTestInjector() {
165165
getPlaygroundInfo: () => Promise.resolve(null)
166166
});
167167
testInjector.register("filesHashService", {});
168+
testInjector.register("platformEnvironmentRequirements", {
169+
checkEnvironmentRequirements: async (platform?: string, projectDir?: string, runtimeVersion?: string): Promise<boolean> => true
170+
});
168171

169172
return testInjector;
170173
}

test/stubs.ts

+4
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,10 @@ export class PlatformServiceStub extends EventEmitter implements IPlatformServic
812812
public async trackActionForPlatform(actionData: ITrackPlatformAction): Promise<void> {
813813
return null;
814814
}
815+
816+
public getCurrentPlatformVersion(platform: string, projectData: IProjectData): string {
817+
return null;
818+
}
815819
}
816820

817821
export class EmulatorPlatformService implements IEmulatorPlatformService {

0 commit comments

Comments
 (0)