Skip to content

fix: start tracking the AAR and include.gradle changes during livesync #3745

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
Jul 14, 2018
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/common
Submodule common updated 2 files
+3 −0 .travis.yml
+0 −48 helpers.ts
25 changes: 13 additions & 12 deletions lib/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()}`);
}
}
}

Expand Down
12 changes: 5 additions & 7 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand Down
45 changes: 30 additions & 15 deletions test/services/android-plugin-build-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('androidPluginBuildService', () => {
addManifest?: boolean,
addResFolder?: boolean,
addAssetsFolder?: boolean,
addIncludeGradle?: boolean,
addLegacyIncludeGradle?: boolean,
addProjectDir?: boolean,
addProjectRuntime?: boolean,
Expand Down Expand Up @@ -111,6 +112,7 @@ describe('androidPluginBuildService', () => {
addManifest?: boolean,
addResFolder?: boolean,
addAssetsFolder?: boolean,
addIncludeGradle?: boolean,
addLegacyIncludeGradle?: boolean
}) {
const validAndroidManifestContent = `<?xml version="1.0" encoding="UTF-8"?>
Expand All @@ -122,21 +124,23 @@ describe('androidPluginBuildService', () => {
name="string_name"
>text_string</string>
</resources>`;
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);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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() {
Expand Down