From 69a5c058dbbcb7f8132554c46d8ee80cd3bc3a54 Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Mon, 7 Sep 2015 16:40:30 +0300 Subject: [PATCH 1/2] Update correctly ant template to gradle --- lib/definitions/project.d.ts | 2 +- lib/services/android-project-service.ts | 19 ++++-- lib/services/ios-project-service.ts | 48 ++++++++------ lib/services/platform-service.ts | 86 ++++++++++++------------- test/stubs.ts | 4 +- 5 files changed, 88 insertions(+), 71 deletions(-) diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 62c4ceab7d..ec03bc8be4 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -42,7 +42,7 @@ interface IPlatformProjectService { isPlatformPrepared(projectRoot: string): IFuture; addLibrary(libraryPath: string): IFuture; canUpdatePlatform(currentVersion: string, newVersion: string): IFuture; - updatePlatform(currentVersion: string, newVersion: string): IFuture; + updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): IFuture; preparePluginNativeCode(pluginData: IPluginData, options?: any): IFuture; removePluginNativeCode(pluginData: IPluginData): IFuture; afterPrepareAllPlugins(): IFuture; diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 81aada713b..041e5361a7 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -20,7 +20,9 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService constructor(private $androidEmulatorServices: Mobile.IEmulatorPlatformServices, private $androidToolsInfo: IAndroidToolsInfo, private $childProcess: IChildProcess, + private $commandsService: ICommandsService, private $errors: IErrors, + $fs: IFileSystem, private $hostInfo: IHostInfo, private $injector: IInjector, private $logger: ILogger, @@ -28,8 +30,7 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService private $projectData: IProjectData, private $projectDataService: IProjectDataService, private $propertiesParser: IPropertiesParser, - private $sysInfo: ISysInfo, - $fs: IFileSystem) { + private $sysInfo: ISysInfo) { super($fs); this._androidProjectPropertiesManagers = Object.create(null); } @@ -152,11 +153,19 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService } public canUpdatePlatform(currentVersion: string, newVersion: string): IFuture { - return Future.fromResult(true); + return Future.fromResult(true); } - public updatePlatform(currentVersion: string, newVersion: string): IFuture { - return Future.fromResult(); + public updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): IFuture { + return (() => { + if(semver.eq(newVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) { + this.$commandsService.tryExecuteCommand(process.argv[2], ["remove"].concat(process.argv.slice(4))).wait(); + this.$commandsService.tryExecuteCommand(process.argv[2], process.argv.slice(3)).wait(); + return false; + } + + return true; + }).future()(); } public buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture { diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index aa837f5e4c..393b2131c7 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -11,7 +11,7 @@ import * as constants from "../constants"; import * as helpers from "../common/helpers"; import * as projectServiceBaseLib from "./platform-project-service-base"; -export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService { +export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService { private static XCODE_PROJECT_EXT_NAME = ".xcodeproj"; private static XCODEBUILD_MIN_VERSION = "6.0"; private static IOS_PROJECT_NAME_PLACEHOLDER = "__PROJECT_NAME__"; @@ -30,7 +30,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ private $iOSEmulatorServices: Mobile.IEmulatorPlatformServices, private $options: IOptions, private $injector: IInjector, - private $projectDataService: IProjectDataService) { + private $projectDataService: IProjectDataService, + private $prompter: IPrompter) { super($fs); } @@ -240,24 +241,33 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ }).future()(); } - public updatePlatform(currentVersion: string, newVersion: string): IFuture { + public updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): IFuture { return (() => { - // Copy old file to options["profile-dir"] - let sourceFile = path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName)); - let destinationFile = path.join(this.$options.profileDir, "xcodeproj"); - this.$fs.deleteDirectory(destinationFile).wait(); - shell.cp("-R", path.join(sourceFile, "*"), destinationFile); - this.$logger.info("Backup file %s at location %s", sourceFile, destinationFile); - this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName))).wait(); - - // Copy xcodeProject file - let cachedPackagePath = path.join(this.$npmInstallationManager.getCachedPackagePath(this.platformData.frameworkPackageName, newVersion), constants.PROJECT_FRAMEWORK_FOLDER_NAME, util.format("%s.xcodeproj", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER)); - shell.cp("-R", path.join(cachedPackagePath, "*"), path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName))); - this.$logger.info("Copied from %s at %s.", cachedPackagePath, this.platformData.projectRoot); - - let pbxprojFilePath = path.join(this.platformData.projectRoot, this.$projectData.projectName + IOSProjectService.XCODE_PROJECT_EXT_NAME, "project.pbxproj"); - this.replaceFileContent(pbxprojFilePath).wait(); - }).future()(); + if(!canUpdate) { + let isUpdateConfirmed = this.$prompter.confirm(`We need to override xcodeproj file. The old one will be saved at ${this.$options.profileDir}. Are you sure?`, () => true).wait(); + if(isUpdateConfirmed) { + // Copy old file to options["profile-dir"] + let sourceFile = path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName)); + let destinationFile = path.join(this.$options.profileDir, "xcodeproj"); + this.$fs.deleteDirectory(destinationFile).wait(); + shell.cp("-R", path.join(sourceFile, "*"), destinationFile); + this.$logger.info("Backup file %s at location %s", sourceFile, destinationFile); + this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName))).wait(); + + // Copy xcodeProject file + let cachedPackagePath = path.join(this.$npmInstallationManager.getCachedPackagePath(this.platformData.frameworkPackageName, newVersion), constants.PROJECT_FRAMEWORK_FOLDER_NAME, util.format("%s.xcodeproj", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER)); + shell.cp("-R", path.join(cachedPackagePath, "*"), path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName))); + this.$logger.info("Copied from %s at %s.", cachedPackagePath, this.platformData.projectRoot); + + let pbxprojFilePath = path.join(this.platformData.projectRoot, this.$projectData.projectName + IOSProjectService.XCODE_PROJECT_EXT_NAME, "project.pbxproj"); + this.replaceFileContent(pbxprojFilePath).wait(); + } + + return isUpdateConfirmed; + } + + return true; + }).future()(); } public prepareProject(): IFuture { diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index c8680b7327..c7ee7da683 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -425,74 +425,72 @@ export class PlatformService implements IPlatformService { this.ensurePackageIsCached(platformData.frameworkPackageName, newVersion).wait(); - if(platformData.platformProjectService.canUpdatePlatform(currentVersion, newVersion).wait()) { - + let canUpdate = platformData.platformProjectService.canUpdatePlatform(currentVersion, newVersion).wait(); + if(canUpdate) { if(!semver.valid(newVersion)) { this.$errors.fail("The version %s is not valid. The version should consists from 3 parts separated by dot.", newVersion); } if(semver.gt(currentVersion, newVersion)) { // Downgrade - let isUpdateConfirmed = this.$prompter.confirm(`You are going to downgrade to android runtime v.${newVersion}. Are you sure?`, () => false).wait(); + let isUpdateConfirmed = this.$prompter.confirm(`You are going to downgrade to runtime v.${newVersion}. Are you sure?`, () => false).wait(); if(isUpdateConfirmed) { - this.updatePlatformCore(platformData, currentVersion, newVersion).wait(); + this.updatePlatformCore(platformData, currentVersion, newVersion, canUpdate).wait(); } } else if(semver.eq(currentVersion, newVersion)) { this.$errors.fail("Current and new version are the same."); } else { - this.updatePlatformCore(platformData, currentVersion, newVersion).wait(); + this.updatePlatformCore(platformData, currentVersion, newVersion, canUpdate).wait(); } } else { - let isUpdateConfirmed = this.$prompter.confirm(`We need to override xcodeproj file. The old one will be saved at ${this.$options.profileDir}. Are you sure?`, () => true).wait(); - if(isUpdateConfirmed) { - platformData.platformProjectService.updatePlatform(currentVersion, newVersion).wait(); - this.updatePlatformCore(platformData, currentVersion, newVersion).wait(); - } + this.updatePlatformCore(platformData, currentVersion, newVersion, canUpdate).wait(); } }).future()(); } - private updatePlatformCore(platformData: IPlatformData, currentVersion: string, newVersion: string): IFuture { + private updatePlatformCore(platformData: IPlatformData, currentVersion: string, newVersion: string, canUpdate: boolean): IFuture { return (() => { - // Remove old framework files - let oldFrameworkData = this.getFrameworkFiles(platformData, currentVersion).wait(); - - _.each(oldFrameworkData.frameworkFiles, file => { - let fileToDelete = path.join(platformData.projectRoot, file); - this.$logger.trace("Deleting %s", fileToDelete); - this.$fs.deleteFile(fileToDelete).wait(); - }); - - _.each(oldFrameworkData.frameworkDirectories, dir => { - let dirToDelete = path.join(platformData.projectRoot, dir); - this.$logger.trace("Deleting %s", dirToDelete); - this.$fs.deleteDirectory(dirToDelete).wait(); - }); + let update = platformData.platformProjectService.updatePlatform(currentVersion, newVersion, canUpdate).wait(); + if(update) { + // Remove old framework files + let oldFrameworkData = this.getFrameworkFiles(platformData, currentVersion).wait(); + + _.each(oldFrameworkData.frameworkFiles, file => { + let fileToDelete = path.join(platformData.projectRoot, file); + this.$logger.trace("Deleting %s", fileToDelete); + this.$fs.deleteFile(fileToDelete).wait(); + }); - // Add new framework files - let newFrameworkData = this.getFrameworkFiles(platformData, newVersion).wait(); - let cacheDirectoryPath = this.$npmInstallationManager.getCachedPackagePath(platformData.frameworkPackageName, newVersion); + _.each(oldFrameworkData.frameworkDirectories, dir => { + let dirToDelete = path.join(platformData.projectRoot, dir); + this.$logger.trace("Deleting %s", dirToDelete); + this.$fs.deleteDirectory(dirToDelete).wait(); + }); - _.each(newFrameworkData.frameworkFiles, file => { - let sourceFile = path.join(cacheDirectoryPath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, file); - let destinationFile = path.join(platformData.projectRoot, file); - this.$logger.trace("Replacing %s with %s", sourceFile, destinationFile); - shell.cp("-f", sourceFile, destinationFile); - }); + // Add new framework files + let newFrameworkData = this.getFrameworkFiles(platformData, newVersion).wait(); + let cacheDirectoryPath = this.$npmInstallationManager.getCachedPackagePath(platformData.frameworkPackageName, newVersion); - _.each(newFrameworkData.frameworkDirectories, dir => { - let sourceDirectory = path.join(cacheDirectoryPath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, dir); - let destinationDirectory = path.join(platformData.projectRoot, dir); - this.$logger.trace("Copying %s to %s", sourceDirectory, destinationDirectory); - shell.cp("-fR", path.join(sourceDirectory, "*"), destinationDirectory); - }); + _.each(newFrameworkData.frameworkFiles, file => { + let sourceFile = path.join(cacheDirectoryPath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, file); + let destinationFile = path.join(platformData.projectRoot, file); + this.$logger.trace("Replacing %s with %s", sourceFile, destinationFile); + shell.cp("-f", sourceFile, destinationFile); + }); - // Update .tnsproject file - this.$projectDataService.initialize(this.$projectData.projectDir); - this.$projectDataService.setValue(platformData.frameworkPackageName, {version: newVersion}).wait(); + _.each(newFrameworkData.frameworkDirectories, dir => { + let sourceDirectory = path.join(cacheDirectoryPath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, dir); + let destinationDirectory = path.join(platformData.projectRoot, dir); + this.$logger.trace("Copying %s to %s", sourceDirectory, destinationDirectory); + shell.cp("-fR", path.join(sourceDirectory, "*"), destinationDirectory); + }); - this.$logger.out("Successfully updated to version ", newVersion); + // Update .tnsproject file + this.$projectDataService.initialize(this.$projectData.projectDir); + this.$projectDataService.setValue(platformData.frameworkPackageName, {version: newVersion}).wait(); + this.$logger.out("Successfully updated to version ", newVersion); + } }).future()(); } diff --git a/test/stubs.ts b/test/stubs.ts index f022554de5..70545e8233 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -307,8 +307,8 @@ export class PlatformProjectServiceStub implements IPlatformProjectService { canUpdatePlatform(currentVersion: string, newVersion: string): IFuture { return Future.fromResult(false); } - updatePlatform(currentVersion: string, newVersion: string): IFuture { - return Future.fromResult(); + updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): IFuture { + return Future.fromResult(true); } prepareAppResources(appResourcesDirectoryPath: string): IFuture { return Future.fromResult(); From f3f7ea34072c8b5bd241f65e25cece55e53ee5f8 Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Tue, 8 Sep 2015 12:31:00 +0300 Subject: [PATCH 2/2] Fix PR comments --- lib/definitions/project.d.ts | 6 +++++- lib/services/android-project-service.ts | 8 ++++---- lib/services/ios-project-service.ts | 16 ++++++++-------- lib/services/platform-service.ts | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index ec03bc8be4..29108c0432 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -42,7 +42,11 @@ interface IPlatformProjectService { isPlatformPrepared(projectRoot: string): IFuture; addLibrary(libraryPath: string): IFuture; canUpdatePlatform(currentVersion: string, newVersion: string): IFuture; - updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): IFuture; + /** + * Provides a platform specific update logic for the specified runtime versions. + * @return true in cases when the update procedure should continue. + */ + updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean, addPlatform?: Function, removePlatform?: (platforms: string[]) => IFuture): IFuture; preparePluginNativeCode(pluginData: IPluginData, options?: any): IFuture; removePluginNativeCode(pluginData: IPluginData): IFuture; afterPrepareAllPlugins(): IFuture; diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 041e5361a7..dcf4a1338f 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -20,7 +20,6 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService constructor(private $androidEmulatorServices: Mobile.IEmulatorPlatformServices, private $androidToolsInfo: IAndroidToolsInfo, private $childProcess: IChildProcess, - private $commandsService: ICommandsService, private $errors: IErrors, $fs: IFileSystem, private $hostInfo: IHostInfo, @@ -156,11 +155,12 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService return Future.fromResult(true); } - public updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): IFuture { + public updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean, addPlatform?: Function, removePlatforms?: (platforms: string[]) => IFuture): IFuture { return (() => { if(semver.eq(newVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) { - this.$commandsService.tryExecuteCommand(process.argv[2], ["remove"].concat(process.argv.slice(4))).wait(); - this.$commandsService.tryExecuteCommand(process.argv[2], process.argv.slice(3)).wait(); + let platformLowercase = this.platformData.normalizedPlatformName.toLowerCase(); + removePlatforms([platformLowercase.split("@")[0]]).wait(); + addPlatform(platformLowercase).wait(); return false; } diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index 393b2131c7..606d881832 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -247,17 +247,17 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ let isUpdateConfirmed = this.$prompter.confirm(`We need to override xcodeproj file. The old one will be saved at ${this.$options.profileDir}. Are you sure?`, () => true).wait(); if(isUpdateConfirmed) { // Copy old file to options["profile-dir"] - let sourceFile = path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName)); - let destinationFile = path.join(this.$options.profileDir, "xcodeproj"); - this.$fs.deleteDirectory(destinationFile).wait(); - shell.cp("-R", path.join(sourceFile, "*"), destinationFile); - this.$logger.info("Backup file %s at location %s", sourceFile, destinationFile); - this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName))).wait(); + let sourceDir = path.join(this.platformData.projectRoot, `${this.$projectData.projectName}.xcodeproj`); + let destinationDir = path.join(this.$options.profileDir, "xcodeproj"); + this.$fs.deleteDirectory(destinationDir).wait(); + shell.cp("-R", path.join(sourceDir, "*"), destinationDir); + this.$logger.info(`Backup file ${sourceDir} at location ${destinationDir}`); + this.$fs.deleteDirectory(sourceDir).wait(); // Copy xcodeProject file let cachedPackagePath = path.join(this.$npmInstallationManager.getCachedPackagePath(this.platformData.frameworkPackageName, newVersion), constants.PROJECT_FRAMEWORK_FOLDER_NAME, util.format("%s.xcodeproj", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER)); - shell.cp("-R", path.join(cachedPackagePath, "*"), path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName))); - this.$logger.info("Copied from %s at %s.", cachedPackagePath, this.platformData.projectRoot); + shell.cp("-R", path.join(cachedPackagePath, "*"), sourceDir); + this.$logger.info(`Copied from ${cachedPackagePath} at ${this.platformData.projectRoot}.`); let pbxprojFilePath = path.join(this.platformData.projectRoot, this.$projectData.projectName + IOSProjectService.XCODE_PROJECT_EXT_NAME, "project.pbxproj"); this.replaceFileContent(pbxprojFilePath).wait(); diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index c7ee7da683..258801bc53 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -450,7 +450,7 @@ export class PlatformService implements IPlatformService { private updatePlatformCore(platformData: IPlatformData, currentVersion: string, newVersion: string, canUpdate: boolean): IFuture { return (() => { - let update = platformData.platformProjectService.updatePlatform(currentVersion, newVersion, canUpdate).wait(); + let update = platformData.platformProjectService.updatePlatform(currentVersion, newVersion, canUpdate, this.addPlatform.bind(this), this.removePlatforms.bind(this)).wait(); if(update) { // Remove old framework files let oldFrameworkData = this.getFrameworkFiles(platformData, currentVersion).wait();