Skip to content

stop gradle daemons when removing platform #2533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface IPlatformService {
* @param {string[]} platforms Platforms to be removed.
* @returns {void}
*/
removePlatforms(platforms: string[]): void;
removePlatforms(platforms: string[]): Promise<void>;

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

Expand Down
7 changes: 7 additions & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ interface IPlatformProjectService {
* @returns {void}
*/
ensureConfigurationFileInAppResources(): void;

/**
* Stops all running processes that might hold a lock on the filesystem.
* Android: Gradle daemon processes are terminated.
* @returns {void}
*/
stopServices(): Promise<ISpawnResult>;
}

interface IAndroidProjectPropertiesManager {
Expand Down
10 changes: 10 additions & 0 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,16 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
}
}

public async stopServices(): Promise<ISpawnResult> {
let projectRoot = this.platformData.projectRoot;
let gradleBin = path.join(projectRoot, "gradlew");
if (this.$hostInfo.isWindows) {
gradleBin += ".bat";
}

return this.$childProcess.spawnFromEvent(gradleBin, ["--stop", "--quiet"], "close", { stdio: "inherit", cwd: projectRoot });
}

private async cleanProject(projectRoot: string, options: string[]): Promise<void> {
options.unshift("clean");

Expand Down
4 changes: 4 additions & 0 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,10 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
return null;
}

public async stopServices(): Promise<ISpawnResult> {
return Promise.resolve({stderr: "", stdout: "", exitCode: 0});
}

private async mergeInfoPlists(): Promise<void> {
let projectDir = this.$projectData.projectDir;
let infoPlistPath = this.$options.baseConfig || path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME, this.platformData.normalizedPlatformName, this.platformData.configurationFileName);
Expand Down
10 changes: 6 additions & 4 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,21 @@ export class PlatformService implements IPlatformService {
this.$logger.info(`Copied file '${packageFile}' to '${targetPath}'.`);
}

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

_.each(platforms, platform => {
for (let platform of platforms) {
this.validatePlatformInstalled(platform);
let platformData = this.$platformsData.getPlatformData(platform);

await this.$platformsData.getPlatformData(platform).platformProjectService.stopServices();

let platformDir = path.join(this.$projectData.platformsDir, platform);
this.$fs.deleteDirectory(platformDir);
this.$projectDataService.removeProperty(platformData.frameworkPackageName);

this.$logger.out(`Platform ${platform} successfully removed.`);
});
}
}

public async updatePlatforms(platforms: string[]): Promise<void> {
Expand Down Expand Up @@ -744,7 +746,7 @@ export class PlatformService implements IPlatformService {

private async updatePlatformCore(platformData: IPlatformData, currentVersion: string, newVersion: string, canUpdate: boolean): Promise<void> {
let packageName = platformData.normalizedPlatformName.toLowerCase();
this.removePlatforms([packageName]);
await this.removePlatforms([packageName]);
packageName = newVersion ? `${packageName}@${newVersion}` : packageName;
await this.addPlatform(packageName);
this.$logger.out("Successfully updated to version ", newVersion);
Expand Down
2 changes: 1 addition & 1 deletion test/platform-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ describe('Platform Service Tests', () => {
testInjector.registerCommand("platform|clean", CleanCommand);
let cleanCommand = testInjector.resolveCommand("platform|clean");

platformService.removePlatforms = (platforms: string[]) => {
platformService.removePlatforms = async (platforms: string[]) => {
platformActions.push({ action: "removePlatforms", platforms });
};

Expand Down
21 changes: 18 additions & 3 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,25 @@ describe('Platform Service Tests', () => {
});

describe("remove platform unit tests", () => {
it("should fail when platforms are not added", () => {
it("should fail when platforms are not added", async () => {
const ExpectedErrorsCaught = 2;
let errorsCaught = 0;

testInjector.resolve("fs").exists = () => false;
(() => platformService.removePlatforms(["android"])).should.throw();
(() => platformService.removePlatforms(["ios"])).should.throw();

try {
await platformService.removePlatforms(["android"]);
} catch (e) {
errorsCaught++;
}

try {
await platformService.removePlatforms(["ios"]);
} catch (e) {
errorsCaught++;
}

assert.isTrue(errorsCaught === ExpectedErrorsCaught);
});
it("shouldn't fail when platforms are added", async () => {
testInjector.resolve("fs").exists = () => false;
Expand Down
5 changes: 4 additions & 1 deletion test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
ensureConfigurationFileInAppResources(): void {
return null;
}
async stopServices(): Promise<ISpawnResult> {
return Promise.resolve({stderr: "", stdout: "", exitCode: 0});
}
}

export class ProjectDataService implements IProjectDataService {
Expand Down Expand Up @@ -589,7 +592,7 @@ export class PlatformServiceStub implements IPlatformService {
return [];
}

public removePlatforms(platforms: string[]): void {
public async removePlatforms(platforms: string[]): Promise<void> {

}

Expand Down