From e1154ff5d72192ff92a58f3a85640ab94f32b4fa Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Thu, 12 Jul 2018 15:22:47 +0300 Subject: [PATCH 1/2] fix: start tracking the AAR and include.gradle changes during livesync --- lib/services/livesync/livesync-service.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/services/livesync/livesync-service.ts b/lib/services/livesync/livesync-service.ts index 9228fbe621..5b1589380d 100644 --- a/lib/services/livesync/livesync-service.ts +++ b/lib/services/livesync/livesync-service.ts @@ -2,7 +2,7 @@ import * as path from "path"; import * as choki from "chokidar"; import { EOL } from "os"; import { EventEmitter } from "events"; -import { hook, isAllowedFinalFile } from "../../common/helpers"; +import { hook } from "../../common/helpers"; import { PACKAGE_JSON_FILE_NAME, LiveSyncTrackActionNames, USER_INTERACTION_NEEDED_EVENT_NAME, DEBUGGER_ATTACHED_EVENT_NAME, DEBUGGER_DETACHED_EVENT_NAME, TrackActionNames } from "../../constants"; import { DeviceTypes, DeviceDiscoveryEventNames } from "../../common/constants"; import { cache } from "../../common/decorators"; @@ -671,12 +671,10 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi this.$logger.trace(`Chokidar raised event ${event} for ${filePath}.`); - if (!isAllowedFinalFile(filePath)) { - if (event === "add" || event === "addDir" || event === "change" /* <--- what to do when change event is raised ? */) { - filesToSync.push(filePath); - } else if (event === "unlink" || event === "unlinkDir") { - filesToRemove.push(filePath); - } + if (event === "add" || event === "addDir" || event === "change" /* <--- what to do when change event is raised ? */) { + filesToSync.push(filePath); + } else if (event === "unlink" || event === "unlinkDir") { + filesToRemove.push(filePath); } startSyncFilesTimeout(); From c4deddfd9b07439ac2dbf8fb319f7e3d68365ec4 Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Thu, 12 Jul 2018 15:27:12 +0300 Subject: [PATCH 2/2] fix: stop overriding the include.gradle files on each livesync --- lib/common | 2 +- lib/services/android-plugin-build-service.ts | 25 ++++++----- test/services/android-plugin-build-service.ts | 45 ++++++++++++------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/lib/common b/lib/common index 2b71367bac..218dbb7bb1 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 2b71367bac3e91289e2c9312841914b4ac2dfe7b +Subproject commit 218dbb7bb1b7dc2429431c8c01aac400974a0de8 diff --git a/lib/services/android-plugin-build-service.ts b/lib/services/android-plugin-build-service.ts index 20baf645ba..6c03ecaa4e 100644 --- a/lib/services/android-plugin-build-service.ts +++ b/lib/services/android-plugin-build-service.ts @@ -127,14 +127,14 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { private getScope(scopeName: string, content: string): string { const indexOfScopeName = content.indexOf(scopeName); - let result = ""; const openingBracket = "{"; const closingBracket = "}"; - let openBrackets = 0; let foundFirstBracket = false; + let openBrackets = 0; + let result = ""; let i = indexOfScopeName; - while (i < content.length) { + while (i !== -1 && i < content.length) { const currCharacter = content[i]; if (currCharacter === openingBracket) { if (openBrackets === 0) { @@ -337,15 +337,16 @@ export class AndroidPluginBuildService implements IAndroidPluginBuildService { } const productFlavorsScope = this.getScope("productFlavors", includeGradleFileContent); - - try { - const newIncludeGradleFileContent = includeGradleFileContent.replace(productFlavorsScope, ""); - this.$fs.writeFile(includeGradleFilePath, newIncludeGradleFileContent); - - return true; - } catch (e) { - this.$errors.failWithoutHelp(`Failed to write the updated include.gradle ` + - `in - ${includeGradleFilePath}. Error is: ${e.toString()}`); + if (productFlavorsScope) { + try { + const newIncludeGradleFileContent = includeGradleFileContent.replace(productFlavorsScope, ""); + this.$fs.writeFile(includeGradleFilePath, newIncludeGradleFileContent); + + return true; + } catch (e) { + this.$errors.failWithoutHelp(`Failed to write the updated include.gradle ` + + `in - ${includeGradleFilePath}. Error is: ${e.toString()}`); + } } } diff --git a/test/services/android-plugin-build-service.ts b/test/services/android-plugin-build-service.ts index 0e57af0368..bcb4ccb458 100644 --- a/test/services/android-plugin-build-service.ts +++ b/test/services/android-plugin-build-service.ts @@ -22,6 +22,7 @@ describe('androidPluginBuildService', () => { addManifest?: boolean, addResFolder?: boolean, addAssetsFolder?: boolean, + addIncludeGradle?: boolean, addLegacyIncludeGradle?: boolean, addProjectDir?: boolean, addProjectRuntime?: boolean, @@ -111,6 +112,7 @@ describe('androidPluginBuildService', () => { addManifest?: boolean, addResFolder?: boolean, addAssetsFolder?: boolean, + addIncludeGradle?: boolean, addLegacyIncludeGradle?: boolean }) { const validAndroidManifestContent = ` @@ -122,21 +124,23 @@ describe('androidPluginBuildService', () => { name="string_name" >text_string `; - const validIncludeGradleContent = `android { - productFlavors { - "nativescript-pro-ui" { - dimension "nativescript-pro-ui" - } - } + const validIncludeGradleContent = +`android {` + + (options.addLegacyIncludeGradle ? ` + productFlavors { + "nativescript-pro-ui" { + dimension "nativescript-pro-ui" } + }` : ``) + ` +} - def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "23.3.0" +def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "23.3.0" - dependencies { - compile "com.android.support:appcompat-v7:$supportVersion" - compile "com.android.support:recyclerview-v7:$supportVersion" - compile "com.android.support:design:$supportVersion" - }`; +dependencies { + compile "com.android.support:appcompat-v7:$supportVersion" + compile "com.android.support:recyclerview-v7:$supportVersion" + compile "com.android.support:design:$supportVersion" +}`; if (options.addManifest) { fs.writeFile(path.join(pluginFolder, "AndroidManifest.xml"), validAndroidManifestContent); @@ -154,7 +158,7 @@ describe('androidPluginBuildService', () => { fs.writeFile(path.join(imagesFolder, "myicon.png"), "123"); } - if (options.addLegacyIncludeGradle) { + if (options.addLegacyIncludeGradle || options.addIncludeGradle) { fs.writeFile(path.join(pluginFolder, INCLUDE_GRADLE_NAME), validIncludeGradleContent); } } @@ -291,12 +295,23 @@ describe('androidPluginBuildService', () => { addLegacyIncludeGradle: true }); - await androidBuildPluginService.migrateIncludeGradle(config); - + const isMigrated = await androidBuildPluginService.migrateIncludeGradle(config); const includeGradleContent = fs.readText(path.join(pluginFolder, INCLUDE_GRADLE_NAME).toString()); const areProductFlavorsRemoved = includeGradleContent.indexOf("productFlavors") === -1; + + assert.isTrue(isMigrated); assert.isTrue(areProductFlavorsRemoved); }); + + it('if there is an already migrated include.gradle file', async () => { + const config: IBuildOptions = setup({ + addIncludeGradle: true + }); + + const isMigrated = await androidBuildPluginService.migrateIncludeGradle(config); + + assert.isFalse(isMigrated); + }); }); function getGradleAndroidPluginVersion() {