Skip to content

Commit e3435eb

Browse files
authored
stop gradle daemons when removing platform (#2533)
* stop gradle daemons when removing platform * Update platform-service.ts
1 parent 63a165c commit e3435eb

8 files changed

+51
-10
lines changed

lib/definitions/platform.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface IPlatformService {
2424
* @param {string[]} platforms Platforms to be removed.
2525
* @returns {void}
2626
*/
27-
removePlatforms(platforms: string[]): void;
27+
removePlatforms(platforms: string[]): Promise<void>;
2828

2929
updatePlatforms(platforms: string[]): Promise<void>;
3030

lib/definitions/project.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ interface IPlatformProjectService {
208208
* @returns {void}
209209
*/
210210
ensureConfigurationFileInAppResources(): void;
211+
212+
/**
213+
* Stops all running processes that might hold a lock on the filesystem.
214+
* Android: Gradle daemon processes are terminated.
215+
* @returns {void}
216+
*/
217+
stopServices(): Promise<ISpawnResult>;
211218
}
212219

213220
interface IAndroidProjectPropertiesManager {

lib/services/android-project-service.ts

+10
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,16 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
395395
}
396396
}
397397

398+
public async stopServices(): Promise<ISpawnResult> {
399+
let projectRoot = this.platformData.projectRoot;
400+
let gradleBin = path.join(projectRoot, "gradlew");
401+
if (this.$hostInfo.isWindows) {
402+
gradleBin += ".bat";
403+
}
404+
405+
return this.$childProcess.spawnFromEvent(gradleBin, ["--stop", "--quiet"], "close", { stdio: "inherit", cwd: projectRoot });
406+
}
407+
398408
private async cleanProject(projectRoot: string, options: string[]): Promise<void> {
399409
options.unshift("clean");
400410

lib/services/ios-project-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
632632
return null;
633633
}
634634

635+
public async stopServices(): Promise<ISpawnResult> {
636+
return Promise.resolve({stderr: "", stdout: "", exitCode: 0});
637+
}
638+
635639
private async mergeInfoPlists(): Promise<void> {
636640
let projectDir = this.$projectData.projectDir;
637641
let infoPlistPath = this.$options.baseConfig || path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME, this.platformData.normalizedPlatformName, this.platformData.configurationFileName);

lib/services/platform-service.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -571,19 +571,21 @@ export class PlatformService implements IPlatformService {
571571
this.$logger.info(`Copied file '${packageFile}' to '${targetPath}'.`);
572572
}
573573

574-
public removePlatforms(platforms: string[]): void {
574+
public async removePlatforms(platforms: string[]): Promise<void> {
575575
this.$projectDataService.initialize(this.$projectData.projectDir);
576576

577-
_.each(platforms, platform => {
577+
for (let platform of platforms) {
578578
this.validatePlatformInstalled(platform);
579579
let platformData = this.$platformsData.getPlatformData(platform);
580580

581+
await this.$platformsData.getPlatformData(platform).platformProjectService.stopServices();
582+
581583
let platformDir = path.join(this.$projectData.platformsDir, platform);
582584
this.$fs.deleteDirectory(platformDir);
583585
this.$projectDataService.removeProperty(platformData.frameworkPackageName);
584586

585587
this.$logger.out(`Platform ${platform} successfully removed.`);
586-
});
588+
}
587589
}
588590

589591
public async updatePlatforms(platforms: string[]): Promise<void> {
@@ -745,7 +747,7 @@ export class PlatformService implements IPlatformService {
745747

746748
private async updatePlatformCore(platformData: IPlatformData, currentVersion: string, newVersion: string, canUpdate: boolean): Promise<void> {
747749
let packageName = platformData.normalizedPlatformName.toLowerCase();
748-
this.removePlatforms([packageName]);
750+
await this.removePlatforms([packageName]);
749751
packageName = newVersion ? `${packageName}@${newVersion}` : packageName;
750752
await this.addPlatform(packageName);
751753
this.$logger.out("Successfully updated to version ", newVersion);

test/platform-commands.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ describe('Platform Service Tests', () => {
408408
testInjector.registerCommand("platform|clean", CleanCommand);
409409
let cleanCommand = testInjector.resolveCommand("platform|clean");
410410

411-
platformService.removePlatforms = (platforms: string[]) => {
411+
platformService.removePlatforms = async (platforms: string[]) => {
412412
platformActions.push({ action: "removePlatforms", platforms });
413413
};
414414

test/platform-service.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,25 @@ describe('Platform Service Tests', () => {
168168
});
169169

170170
describe("remove platform unit tests", () => {
171-
it("should fail when platforms are not added", () => {
171+
it("should fail when platforms are not added", async () => {
172+
const ExpectedErrorsCaught = 2;
173+
let errorsCaught = 0;
174+
172175
testInjector.resolve("fs").exists = () => false;
173-
(() => platformService.removePlatforms(["android"])).should.throw();
174-
(() => platformService.removePlatforms(["ios"])).should.throw();
176+
177+
try {
178+
await platformService.removePlatforms(["android"]);
179+
} catch (e) {
180+
errorsCaught++;
181+
}
182+
183+
try {
184+
await platformService.removePlatforms(["ios"]);
185+
} catch (e) {
186+
errorsCaught++;
187+
}
188+
189+
assert.isTrue(errorsCaught === ExpectedErrorsCaught);
175190
});
176191
it("shouldn't fail when platforms are added", async () => {
177192
testInjector.resolve("fs").exists = () => false;

test/stubs.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
342342
ensureConfigurationFileInAppResources(): void {
343343
return null;
344344
}
345+
async stopServices(): Promise<ISpawnResult> {
346+
return Promise.resolve({stderr: "", stdout: "", exitCode: 0});
347+
}
345348
}
346349

347350
export class ProjectDataService implements IProjectDataService {
@@ -589,7 +592,7 @@ export class PlatformServiceStub implements IPlatformService {
589592
return [];
590593
}
591594

592-
public removePlatforms(platforms: string[]): void {
595+
public async removePlatforms(platforms: string[]): Promise<void> {
593596

594597
}
595598

0 commit comments

Comments
 (0)