Skip to content

Update correctly ant template to gradle #886

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
Sep 8, 2015
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
6 changes: 5 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ interface IPlatformProjectService {
isPlatformPrepared(projectRoot: string): IFuture<boolean>;
addLibrary(libraryPath: string): IFuture<void>;
canUpdatePlatform(currentVersion: string, newVersion: string): IFuture<boolean>;
updatePlatform(currentVersion: string, newVersion: string): IFuture<void>;
/**
* 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<void>): IFuture<boolean>;
preparePluginNativeCode(pluginData: IPluginData, options?: any): IFuture<void>;
removePluginNativeCode(pluginData: IPluginData): IFuture<void>;
afterPrepareAllPlugins(): IFuture<void>;
Expand Down
19 changes: 14 additions & 5 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
private $androidToolsInfo: IAndroidToolsInfo,
private $childProcess: IChildProcess,
private $errors: IErrors,
$fs: IFileSystem,
private $hostInfo: IHostInfo,
private $injector: IInjector,
private $logger: ILogger,
private $options: IOptions,
private $projectData: IProjectData,
private $projectDataService: IProjectDataService,
private $propertiesParser: IPropertiesParser,
private $sysInfo: ISysInfo,
$fs: IFileSystem) {
private $sysInfo: ISysInfo) {
super($fs);
this._androidProjectPropertiesManagers = Object.create(null);
}
Expand Down Expand Up @@ -152,11 +152,20 @@ class AndroidProjectService extends projectServiceBaseLib.PlatformProjectService
}

public canUpdatePlatform(currentVersion: string, newVersion: string): IFuture<boolean> {
return Future.fromResult<boolean>(true);
return Future.fromResult(true);
}

public updatePlatform(currentVersion: string, newVersion: string): IFuture<void> {
return Future.fromResult();
public updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean, addPlatform?: Function, removePlatforms?: (platforms: string[]) => IFuture<void>): IFuture<boolean> {
return (() => {
if(semver.eq(newVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE)) {
let platformLowercase = this.platformData.normalizedPlatformName.toLowerCase();
removePlatforms([platformLowercase.split("@")[0]]).wait();
addPlatform(platformLowercase).wait();
return false;
}

return true;
}).future<boolean>()();
}

public buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void> {
Expand Down
48 changes: 29 additions & 19 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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__";
Expand All @@ -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);
}

Expand Down Expand Up @@ -240,24 +241,33 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
}).future<boolean>()();
}

public updatePlatform(currentVersion: string, newVersion: string): IFuture<void> {
public updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): IFuture<boolean> {
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<void>()();
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 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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, you can use template string, but not a merge stopper.

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();
}

return isUpdateConfirmed;
}

return true;
}).future<boolean>()();
}

public prepareProject(): IFuture<void> {
Expand Down
86 changes: 42 additions & 44 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>()();
}

private updatePlatformCore(platformData: IPlatformData, currentVersion: string, newVersion: string): IFuture<void> {
private updatePlatformCore(platformData: IPlatformData, currentVersion: string, newVersion: string, canUpdate: boolean): IFuture<void> {
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, this.addPlatform.bind(this), this.removePlatforms.bind(this)).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<void>()();
}

Expand Down
4 changes: 2 additions & 2 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
canUpdatePlatform(currentVersion: string, newVersion: string): IFuture<boolean> {
return Future.fromResult(false);
}
updatePlatform(currentVersion: string, newVersion: string): IFuture<void> {
return Future.fromResult();
updatePlatform(currentVersion: string, newVersion: string, canUpdate: boolean): IFuture<boolean> {
return Future.fromResult(true);
}
prepareAppResources(appResourcesDirectoryPath: string): IFuture<void> {
return Future.fromResult();
Expand Down