Skip to content

removing unnecessary functionality #2099

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 4 commits into from
Oct 7, 2016
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
120 changes: 2 additions & 118 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as projectServiceBaseLib from "./platform-project-service-base";
import {DeviceAndroidDebugBridge} from "../common/mobile/android/device-android-debug-bridge";
import {AndroidDeviceHashService} from "../common/mobile/android/android-device-hash-service";
import {EOL} from "os";
import { createGUID } from "../common/helpers";

export class AndroidProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
private static VALUES_DIRNAME = "values";
Expand Down Expand Up @@ -307,31 +306,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
}

public prepareProject(): IFuture<void> {
return (() => {
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath().wait();
let androidManifestPath = path.join(resDestinationDir, this.platformData.configurationFileName);

// In case the file is not correct, looks like we are still using the default AndroidManifest.xml from runtime and the current file (in res dir)
// should be merged with it.
if (this.isAndroidManifestFileCorrect(androidManifestPath).wait()) {
// Delete the AndroidManifest.xml file from res directory as the runtime will consider it as addition to the one in src/main and will try to merge them.
// However now they are the same file.
this.$fs.deleteFile(androidManifestPath).wait();
}
}).future<void>()();
return Future.fromResult();
}

public ensureConfigurationFileInAppResources(): IFuture<void> {
return (() => {
let originalAndroidManifestFilePath = path.join(this.$projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName),
hasAndroidManifestInAppResources = this.$fs.exists(originalAndroidManifestFilePath).wait(),
shouldExtractDefaultManifest = !hasAndroidManifestInAppResources || !this.isAndroidManifestFileCorrect(originalAndroidManifestFilePath).wait();

// In case we should extract the manifest from default template, but for some reason we cannot, break the execution,
// so the original file from Android runtime will be used.
if (shouldExtractDefaultManifest && !this.extractAndroidManifestFromDefaultTemplate(originalAndroidManifestFilePath).wait()) {
return;
}
let originalAndroidManifestFilePath = path.join(this.$projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName);

// Overwrite the AndroidManifest from runtime.
this.$fs.copyFile(originalAndroidManifestFilePath, this.platformData.configurationFilePath).wait();
Expand Down Expand Up @@ -526,101 +506,5 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject

}).future<void>()();
}

private isAndroidManifestFileCorrect(pathToAndroidManifest: string): IFuture<boolean> {
return ((): boolean => {
try {
// Check if the AndroidManifest in app/App_Resouces is the correct one
// Use a real magic to detect if this is the correct file, by checking some mandatory strings.
let fileContent = this.$fs.readText(pathToAndroidManifest).wait(),
isFileCorrect = !!(~fileContent.indexOf("android:minSdkVersion") && ~fileContent.indexOf("android:targetSdkVersion")
&& ~fileContent.indexOf("uses-permission") && ~fileContent.indexOf("<application")
&& ~fileContent.indexOf("<activity") && ~fileContent.indexOf("<intent-filter>")
&& ~fileContent.indexOf("android.intent.action.MAIN")
&& ~fileContent.indexOf("android:versionCode")
&& !this.$xmlValidator.getXmlFileErrors(pathToAndroidManifest).wait());

this.$logger.trace(`Existing ${this.platformData.configurationFileName} is ${isFileCorrect ? "" : "NOT "}correct.`);
return isFileCorrect;
} catch (err) {
this.$logger.trace(`Error while checking ${pathToAndroidManifest}: `, err);
return false;
}
}).future<boolean>()();
}

private _configurationFileBackupName: string;

private getConfigurationFileBackupName(originalAndroidManifestFilePath: string): IFuture<string> {
return (() => {
if (!this._configurationFileBackupName) {
let defaultBackupName = this.platformData.configurationFileName + ".backup";
if (this.$fs.exists(path.join(path.dirname(originalAndroidManifestFilePath), defaultBackupName)).wait()) {
defaultBackupName += `_${createGUID(false)}`;
}
this._configurationFileBackupName = defaultBackupName;
}

return this._configurationFileBackupName;
}).future<string>()();
}

private backupOriginalAndroidManifest(originalAndroidManifestFilePath: string): IFuture<void> {
return (() => {
let newPathForOriginalManifest = path.join(path.dirname(originalAndroidManifestFilePath), this.getConfigurationFileBackupName(originalAndroidManifestFilePath).wait());
shell.mv(originalAndroidManifestFilePath, newPathForOriginalManifest);
}).future<void>()();
}

private revertBackupOfOriginalAndroidManifest(originalAndroidManifestFilePath: string): IFuture<void> {
return (() => {
let pathToBackupFile = path.join(path.dirname(originalAndroidManifestFilePath), this.getConfigurationFileBackupName(originalAndroidManifestFilePath).wait());
if (this.$fs.exists(pathToBackupFile).wait()) {
this.$logger.trace(`Could not extract ${this.platformData.configurationFileName} from default template. Reverting the change of your app/App_Resources/${this.platformData.configurationFileName}.`);
shell.mv(pathToBackupFile, originalAndroidManifestFilePath);
}
}).future<void>()();
}

private extractAndroidManifestFromDefaultTemplate(originalAndroidManifestFilePath: string): IFuture<boolean> {
return ((): boolean => {
let defaultTemplatePath = this.$projectTemplatesService.defaultTemplatePath.wait();
let templateAndroidManifest = path.join(defaultTemplatePath, constants.APP_RESOURCES_FOLDER_NAME, this.$devicePlatformsConstants.Android, this.platformData.configurationFileName);
let alreadyHasAndroidManifest = this.$fs.exists(originalAndroidManifestFilePath).wait();
if (this.$fs.exists(templateAndroidManifest).wait()) {
this.$logger.trace(`${originalAndroidManifestFilePath} is missing. Upgrading the source of the project with one from the new project template. Copy ${templateAndroidManifest} to ${originalAndroidManifestFilePath}`);
try {
if (alreadyHasAndroidManifest) {
this.backupOriginalAndroidManifest(originalAndroidManifestFilePath).wait();
}

let content = this.$fs.readText(templateAndroidManifest).wait();

// We do not want to force launch screens on old projects.
let themeMeta = `<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />`;
content = content
.replace(`\n\t\t\tandroid:theme="@style/LaunchScreenTheme">\n`, `>\n\t\t\t<!-- android:theme="@style/LaunchScreenTheme" -->\n`)
.replace(themeMeta, "<!-- " + themeMeta + " -->");

this.$fs.writeFile(originalAndroidManifestFilePath, content).wait();
} catch (e) {
this.$logger.trace(`Copying template's ${this.platformData.configurationFileName} failed. `, e);
this.revertBackupOfOriginalAndroidManifest(originalAndroidManifestFilePath).wait();
return false;
}
} else {
this.$logger.trace(`${originalAndroidManifestFilePath} is missing but the template ${templateAndroidManifest} is missing too, can not upgrade ${this.platformData.configurationFileName}.`);
return false;
}

if (alreadyHasAndroidManifest) {
this.$logger.warn(`Your ${this.platformData.configurationFileName} in app/App_Resources/Android will be replaced by the default one from hello-world template.`);
this.$logger.printMarkdown(`The original file will be moved to \`${this.getConfigurationFileBackupName(originalAndroidManifestFilePath).wait()}\`. Merge it **manually** with the new \`${this.platformData.configurationFileName}\` in your app/App_Resources/Android.`);
}

this.interpolateConfigurationFile().wait();
return true;
}).future<boolean>()();
}
}
$injector.register("androidProjectService", AndroidProjectService);
21 changes: 1 addition & 20 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,26 +624,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
);
}
public ensureConfigurationFileInAppResources(): IFuture<void> {
return (() => {
let infoPlistPath = this.getInfoPlistPath();
if (!this.$fs.exists(infoPlistPath).wait()) {
// The project is missing Info.plist, try to populate it from the project template.
let projectTemplateService: IProjectTemplatesService = this.$injector.resolve("projectTemplatesService");
let defaultTemplatePath = projectTemplateService.defaultTemplatePath.wait();
let templateInfoPlist = path.join(defaultTemplatePath, constants.APP_RESOURCES_FOLDER_NAME, this.$devicePlatformsConstants.iOS, this.platformData.configurationFileName);
if (this.$fs.exists(templateInfoPlist).wait()) {
this.$logger.trace("Info.plist: app/App_Resources/iOS/Info.plist is missing. Upgrading the source of the project with one from the new project template. Copy " + templateInfoPlist + " to " + infoPlistPath);
try {
this.$fs.copyFile(templateInfoPlist, infoPlistPath).wait();
} catch (e) {
this.$logger.trace("Copying template's Info.plist failed. " + e);
}
} else {
this.$logger.trace("Info.plist: app/App_Resources/iOS/Info.plist is missing but the template " + templateInfoPlist + " is missing too, can not upgrade Info.plist.");
}
}

}).future<void>()();
return Future.fromResult();
}

private mergeInfoPlists(): IFuture<void> {
Expand Down
6 changes: 0 additions & 6 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,6 @@ export class PlatformService implements IPlatformService {
sourceFiles = sourceFiles.filter(source => source.indexOf(testsFolderPath) === -1);
}

let hasTnsModulesInAppFolder = this.$fs.exists(path.join(appSourceDirectoryPath, constants.TNS_MODULES_FOLDER_NAME)).wait();
if (hasTnsModulesInAppFolder && this.$projectData.dependencies && this.$projectData.dependencies[constants.TNS_CORE_MODULES_NAME]) {
this.$logger.warn("You have tns_modules dir in your app folder and tns-core-modules in your package.json file. Tns_modules dir in your app folder will not be used and you can safely remove it.");
sourceFiles = sourceFiles.filter(source => !minimatch(source, `**/${constants.TNS_MODULES_FOLDER_NAME}/**`, { nocase: true }));
}

// verify .xml files are well-formed
this.$xmlValidator.validateXmlFiles(sourceFiles).wait();

Expand Down
8 changes: 2 additions & 6 deletions lib/services/plugins-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,13 @@ export class PluginsService implements IPluginsService {
}

if (exists) {
this.$fs.ensureDirectoryExists(pluginDestinationPath).wait();
shelljs.cp("-Rf", pluginData.fullPath, pluginDestinationPath);

//prepare platform speciffic files, .map and .ts files
this.$projectFilesManager.processPlatformSpecificFiles(pluginDestinationPath, platform).wait();

//deal with platforms/android folder in ns plugin
pluginData.pluginPlatformsFolderPath = (_platform: string) => path.join(pluginData.fullPath, "platforms", _platform);
platformData.platformProjectService.preparePluginNativeCode(pluginData).wait();

shelljs.rm("-rf", path.join(pluginDestinationPath, pluginData.name, "platforms"));
// Remove node_modules of the plugin. The destination path should have flattened node_modules.
shelljs.rm("-rf", path.join(pluginDestinationPath, pluginData.name, constants.NODE_MODULES_FOLDER_NAME));

// Show message
this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`);
Expand Down