Skip to content

Commit 3a61cee

Browse files
committed
chore: remove the legacy code from android-project-service
1 parent 573da91 commit 3a61cee

File tree

7 files changed

+17
-353
lines changed

7 files changed

+17
-353
lines changed

lib/common/helpers.ts

-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ export function regExpEscape(input: string): string {
9797
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
9898
}
9999

100-
export function isRecommendedAarFile(foundAarFile: string, packageJsonPluginName: string): boolean {
101-
const filename = foundAarFile.replace(/^.*[\\\/]/, '');
102-
packageJsonPluginName = getShortPluginName(packageJsonPluginName);
103-
return `${packageJsonPluginName}.aar` === filename;
104-
}
105-
106100
export function getShortPluginName(pluginName: string): string {
107101
return sanitizePluginName(pluginName).replace(/[\-]/g, "_");
108102
}

lib/definitions/project.d.ts

-10
Original file line numberDiff line numberDiff line change
@@ -461,16 +461,6 @@ interface IPlatformProjectService extends NodeJS.EventEmitter, IPlatformProjectS
461461
*/
462462
checkForChanges(changeset: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): Promise<void>;
463463

464-
/**
465-
* Build native part of a nativescript plugins if necessary
466-
*/
467-
prebuildNativePlugin(buildOptions: IPluginBuildOptions): Promise<void>;
468-
469-
/**
470-
* Traverse through the production dependencies and find plugins that need build/rebuild
471-
*/
472-
checkIfPluginsNeedBuild(projectData: IProjectData): Promise<Array<any>>;
473-
474464
/**
475465
* Get the deployment target's version
476466
* Currently implemented only for iOS -> returns the value of IPHONEOS_DEPLOYMENT_TARGET property from xcconfig file

lib/services/android-project-service.ts

+16-205
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as constants from "../constants";
44
import * as semver from "semver";
55
import * as projectServiceBaseLib from "./platform-project-service-base";
66
import { DeviceAndroidDebugBridge } from "../common/mobile/android/device-android-debug-bridge";
7-
import { attachAwaitDetach, isRecommendedAarFile } from "../common/helpers";
7+
import { attachAwaitDetach } from "../common/helpers";
88
import { Configurations, LiveSyncPaths } from "../common/constants";
99
import { SpawnOptions } from "child_process";
1010
import { performanceLog } from ".././common/decorators";
@@ -14,7 +14,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
1414
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v";
1515
private static ANDROID_PLATFORM_NAME = "android";
1616
private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.5.0";
17-
private static MIN_RUNTIME_VERSION_WITHOUT_DEPS = "4.2.0-2018-06-29-02";
1817

1918
private isAndroidStudioTemplate: boolean;
2019

@@ -26,9 +25,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
2625
private $logger: ILogger,
2726
$projectDataService: IProjectDataService,
2827
private $injector: IInjector,
29-
private $pluginVariablesService: IPluginVariablesService,
3028
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
31-
private $packageManager: INodePackageManager,
3229
private $androidPluginBuildService: IAndroidPluginBuildService,
3330
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
3431
private $androidResourcesMigrationService: IAndroidResourcesMigrationService,
@@ -186,52 +183,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
186183
}
187184

188185
this.cleanResValues(targetSdkVersion, projectData);
189-
190-
if (semver.lt(frameworkVersion, AndroidProjectService.MIN_RUNTIME_VERSION_WITHOUT_DEPS)) {
191-
await this.installRuntimeDeps(projectData, config);
192-
}
193-
}
194-
195-
private async installRuntimeDeps(projectData: IProjectData, config: ICreateProjectOptions) {
196-
const requiredDevDependencies = [
197-
{ name: "babel-traverse", version: "^6.4.5" },
198-
{ name: "babel-types", version: "^6.4.5" },
199-
{ name: "babylon", version: "^6.4.5" },
200-
{ name: "lazy", version: "^1.0.11" }
201-
];
202-
203-
const npmConfig: INodePackageManagerInstallOptions = {
204-
save: true,
205-
"save-dev": true,
206-
"save-exact": true,
207-
silent: true,
208-
disableNpmInstall: false,
209-
frameworkPath: config.frameworkPath,
210-
ignoreScripts: config.ignoreScripts
211-
};
212-
213-
const projectPackageJson: any = this.$fs.readJson(projectData.projectFilePath);
214-
215-
for (const dependency of requiredDevDependencies) {
216-
let dependencyVersionInProject = (projectPackageJson.dependencies && projectPackageJson.dependencies[dependency.name]) ||
217-
(projectPackageJson.devDependencies && projectPackageJson.devDependencies[dependency.name]);
218-
219-
if (!dependencyVersionInProject) {
220-
await this.$packageManager.install(`${dependency.name}@${dependency.version}`, projectData.projectDir, npmConfig);
221-
} else {
222-
const cleanedVersion = semver.clean(dependencyVersionInProject);
223-
224-
// The plugin version is not valid. Check node_modules for the valid version.
225-
if (!cleanedVersion) {
226-
const pathToPluginPackageJson = path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME, dependency.name, constants.PACKAGE_JSON_FILE_NAME);
227-
dependencyVersionInProject = this.$fs.exists(pathToPluginPackageJson) && this.$fs.readJson(pathToPluginPackageJson).version;
228-
}
229-
230-
if (!semver.satisfies(dependencyVersionInProject || cleanedVersion, dependency.version)) {
231-
this.$errors.failWithoutHelp(`Your project have installed ${dependency.name} version ${cleanedVersion} but Android platform requires version ${dependency.version}.`);
232-
}
233-
}
234-
}
235186
}
236187

237188
private cleanResValues(targetSdkVersion: number, projectData: IProjectData): void {
@@ -442,166 +393,37 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
442393
}
443394

444395
public async preparePluginNativeCode(pluginData: IPluginData, projectData: IProjectData): Promise<void> {
445-
if (!this.runtimeVersionIsGreaterThanOrEquals(projectData, "3.3.0")) {
446-
const pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
447-
await this.processResourcesFromPlugin(pluginData, pluginPlatformsFolderPath, projectData);
448-
} else if (this.runtimeVersionIsGreaterThanOrEquals(projectData, "4.0.0")) {
449-
// build Android plugins which contain AndroidManifest.xml and/or resources
450-
const pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
451-
if (this.$fs.exists(pluginPlatformsFolderPath)) {
452-
const options: IPluginBuildOptions = {
453-
projectDir: projectData.projectDir,
454-
pluginName: pluginData.name,
455-
platformsAndroidDirPath: pluginPlatformsFolderPath,
456-
aarOutputDir: pluginPlatformsFolderPath,
457-
tempPluginDirPath: path.join(projectData.platformsDir, "tempPlugin")
458-
};
396+
// build Android plugins which contain AndroidManifest.xml and/or resources
397+
const pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
398+
if (this.$fs.exists(pluginPlatformsFolderPath)) {
399+
const options: IPluginBuildOptions = {
400+
projectDir: projectData.projectDir,
401+
pluginName: pluginData.name,
402+
platformsAndroidDirPath: pluginPlatformsFolderPath,
403+
aarOutputDir: pluginPlatformsFolderPath,
404+
tempPluginDirPath: path.join(projectData.platformsDir, "tempPlugin")
405+
};
459406

460-
await this.prebuildNativePlugin(options);
407+
if (await this.$androidPluginBuildService.buildAar(options)) {
408+
this.$logger.info(`Built aar for ${options.pluginName}`);
461409
}
462-
}
463-
464-
// Do nothing, the Android Gradle script will configure itself based on the input dependencies.json
465-
}
466-
467-
public async checkIfPluginsNeedBuild(projectData: IProjectData): Promise<Array<{ platformsAndroidDirPath: string, pluginName: string }>> {
468-
const detectedPlugins: Array<{ platformsAndroidDirPath: string, pluginName: string }> = [];
469-
470-
const platformsAndroid = path.join(constants.PLATFORMS_DIR_NAME, "android");
471-
const pathToPlatformsAndroid = path.join(projectData.projectDir, platformsAndroid);
472-
const dependenciesJson = await this.$fs.readJson(path.join(pathToPlatformsAndroid, constants.DEPENDENCIES_JSON_NAME));
473-
const productionDependencies = dependenciesJson.map((item: any) => {
474-
return path.resolve(pathToPlatformsAndroid, item.directory);
475-
});
476410

477-
for (const dependency of productionDependencies) {
478-
const jsonContent = this.$fs.readJson(path.join(dependency, constants.PACKAGE_JSON_FILE_NAME));
479-
const isPlugin = !!jsonContent.nativescript;
480-
const pluginName = jsonContent.name;
481-
if (isPlugin) {
482-
const platformsAndroidDirPath = path.join(dependency, platformsAndroid);
483-
if (this.$fs.exists(platformsAndroidDirPath)) {
484-
let hasGeneratedAar = false;
485-
let generatedAarPath = "";
486-
const nativeFiles = this.$fs.enumerateFilesInDirectorySync(platformsAndroidDirPath).filter((item) => {
487-
if (isRecommendedAarFile(item, pluginName)) {
488-
generatedAarPath = item;
489-
hasGeneratedAar = true;
490-
}
491-
return this.isAllowedFile(item);
492-
});
493-
494-
if (hasGeneratedAar) {
495-
const aarStat = this.$fs.getFsStats(generatedAarPath);
496-
nativeFiles.forEach((item) => {
497-
const currentItemStat = this.$fs.getFsStats(item);
498-
if (currentItemStat.mtime > aarStat.mtime) {
499-
detectedPlugins.push({
500-
platformsAndroidDirPath,
501-
pluginName
502-
});
503-
}
504-
});
505-
} else if (nativeFiles.length > 0) {
506-
detectedPlugins.push({
507-
platformsAndroidDirPath,
508-
pluginName
509-
});
510-
}
511-
}
512-
}
411+
this.$androidPluginBuildService.migrateIncludeGradle(options);
513412
}
514-
return detectedPlugins;
515-
}
516-
517-
private isAllowedFile(item: string): boolean {
518-
return item.endsWith(constants.MANIFEST_FILE_NAME) || item.endsWith(constants.RESOURCES_DIR);
519-
}
520-
521-
public async prebuildNativePlugin(options: IPluginBuildOptions): Promise<void> {
522-
if (await this.$androidPluginBuildService.buildAar(options)) {
523-
this.$logger.info(`Built aar for ${options.pluginName}`);
524-
}
525-
526-
this.$androidPluginBuildService.migrateIncludeGradle(options);
527413
}
528414

529415
public async processConfigurationFilesFromAppResources(): Promise<void> {
530416
return;
531417
}
532418

533-
private async processResourcesFromPlugin(pluginData: IPluginData, pluginPlatformsFolderPath: string, projectData: IProjectData): Promise<void> {
534-
const configurationsDirectoryPath = path.join(this.getPlatformData(projectData).projectRoot, "configurations");
535-
this.$fs.ensureDirectoryExists(configurationsDirectoryPath);
536-
537-
const pluginConfigurationDirectoryPath = path.join(configurationsDirectoryPath, pluginData.name);
538-
if (this.$fs.exists(pluginPlatformsFolderPath)) {
539-
this.$fs.ensureDirectoryExists(pluginConfigurationDirectoryPath);
540-
541-
const isScoped = pluginData.name.indexOf("@") === 0;
542-
const flattenedDependencyName = isScoped ? pluginData.name.replace("/", "_") : pluginData.name;
543-
544-
// Copy all resources from plugin
545-
const resourcesDestinationDirectoryPath = path.join(this.getPlatformData(projectData).projectRoot, constants.SRC_DIR, flattenedDependencyName);
546-
this.$fs.ensureDirectoryExists(resourcesDestinationDirectoryPath);
547-
shell.cp("-Rf", path.join(pluginPlatformsFolderPath, "*"), resourcesDestinationDirectoryPath);
548-
549-
const filesForInterpolation = this.$fs.enumerateFilesInDirectorySync(resourcesDestinationDirectoryPath, file => this.$fs.getFsStats(file).isDirectory() || path.extname(file) === constants.XML_FILE_EXTENSION) || [];
550-
for (const file of filesForInterpolation) {
551-
this.$logger.trace(`Interpolate data for plugin file: ${file}`);
552-
await this.$pluginVariablesService.interpolate(pluginData, file, projectData.projectDir, projectData.projectIdentifiers.android);
553-
}
554-
}
555-
556-
// Copy include.gradle file
557-
const includeGradleFilePath = path.join(pluginPlatformsFolderPath, constants.INCLUDE_GRADLE_NAME);
558-
if (this.$fs.exists(includeGradleFilePath)) {
559-
shell.cp("-f", includeGradleFilePath, pluginConfigurationDirectoryPath);
560-
}
561-
}
562-
563419
public async removePluginNativeCode(pluginData: IPluginData, projectData: IProjectData): Promise<void> {
564-
try {
565-
if (!this.runtimeVersionIsGreaterThanOrEquals(projectData, "3.3.0")) {
566-
const pluginConfigDir = path.join(this.getPlatformData(projectData).projectRoot, "configurations", pluginData.name);
567-
if (this.$fs.exists(pluginConfigDir)) {
568-
await this.cleanProject(this.getPlatformData(projectData).projectRoot, projectData);
569-
}
570-
}
571-
} catch (e) {
572-
if (e.code === "ENOENT") {
573-
this.$logger.debug("No native code jars found: " + e.message);
574-
} else {
575-
throw e;
576-
}
577-
}
420+
// not implemented
578421
}
579422

580423
public async beforePrepareAllPlugins(projectData: IProjectData, dependencies?: IDependencyData[]): Promise<void> {
581-
const shouldUseNewRoutine = this.runtimeVersionIsGreaterThanOrEquals(projectData, "3.3.0");
582-
583424
if (dependencies) {
584425
dependencies = this.filterUniqueDependencies(dependencies);
585-
if (shouldUseNewRoutine) {
586-
this.provideDependenciesJson(projectData, dependencies);
587-
} else {
588-
const platformDir = path.join(projectData.platformsDir, AndroidProjectService.ANDROID_PLATFORM_NAME);
589-
const buildDir = path.join(platformDir, "build-tools");
590-
const checkV8dependants = path.join(buildDir, "check-v8-dependants.js");
591-
if (this.$fs.exists(checkV8dependants)) {
592-
const stringifiedDependencies = JSON.stringify(dependencies);
593-
try {
594-
await this.spawn('node', [checkV8dependants, stringifiedDependencies, projectData.platformsDir], { stdio: "inherit" });
595-
} catch (e) {
596-
this.$logger.info("Checking for dependants on v8 public API failed. This is likely caused because of cyclic production dependencies. Error code: " + e.code + "\nMore information: https://github.com/NativeScript/nativescript-cli/issues/2561");
597-
}
598-
}
599-
}
600-
}
601-
602-
if (!shouldUseNewRoutine) {
603-
const projectRoot = this.getPlatformData(projectData).projectRoot;
604-
await this.cleanProject(projectRoot, projectData);
426+
this.provideDependenciesJson(projectData, dependencies);
605427
}
606428
}
607429

@@ -763,17 +585,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
763585
return semver.gte(normalizedPlatformVersion, androidStudioCompatibleTemplate);
764586
}
765587

766-
private runtimeVersionIsGreaterThanOrEquals(projectData: IProjectData, versionString: string): boolean {
767-
const platformVersion = this.getCurrentPlatformVersion(this.getPlatformData(projectData), projectData);
768-
769-
if (platformVersion === constants.PackageVersion.NEXT) {
770-
return true;
771-
}
772-
773-
const normalizedPlatformVersion = `${semver.major(platformVersion)}.${semver.minor(platformVersion)}.0`;
774-
return semver.gte(normalizedPlatformVersion, versionString);
775-
}
776-
777588
private getLegacyAppResourcesDestinationDirPath(projectData: IProjectData): string {
778589
const resourcePath: string[] = [constants.SRC_DIR, constants.MAIN_DIR, constants.RESOURCES_DIR];
779590
if (this.isAndroidStudioTemplate) {

lib/services/ios-project-service.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1038,12 +1038,6 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
10381038
}
10391039
}
10401040

1041-
public async prebuildNativePlugin(options: IPluginBuildOptions): Promise<void> { /** */ }
1042-
1043-
public async checkIfPluginsNeedBuild(projectData: IProjectData): Promise<Array<any>> {
1044-
return [];
1045-
}
1046-
10471041
public getDeploymentTarget(projectData: IProjectData): semver.SemVer {
10481042
const target = this.$xcconfigService.readPropertyValue(this.getBuildXCConfigFilePath(projectData), "IPHONEOS_DEPLOYMENT_TARGET");
10491043
if (!target) {

lib/services/platform-service.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
757757

758758
platform = platform.split("@")[0].toLowerCase();
759759

760-
if (!this.isValidPlatform(platform, projectData)) {
760+
if (!this.$platformsData.getPlatformData(platform, projectData)) {
761761
this.$errors.fail("Invalid platform %s. Valid platforms are %s.", platform, helpers.formatListOfNames(this.$platformsData.platformsNames));
762762
}
763763
}
@@ -822,10 +822,6 @@ export class PlatformService extends EventEmitter implements IPlatformService {
822822
return this.$fs.exists(path.join(projectData.platformsDir, platform.toLowerCase()));
823823
}
824824

825-
private isValidPlatform(platform: string, projectData: IProjectData) {
826-
return this.$platformsData.getPlatformData(platform, projectData);
827-
}
828-
829825
public isPlatformSupportedForOS(platform: string, projectData: IProjectData): boolean {
830826
const targetedOS = this.$platformsData.getPlatformData(platform, projectData).targetedOS;
831827
const res = !targetedOS || targetedOS.indexOf("*") >= 0 || targetedOS.indexOf(process.platform) >= 0;

0 commit comments

Comments
 (0)