Skip to content

Support for include.gradle from plugins #1135

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 5 commits into from
Nov 11, 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
3 changes: 3 additions & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface IProjectData {
projectFilePath: string;
projectId?: string;
dependencies: any;
appDirectoryPath: string;
appResourcesDirectoryPath: string;
}

interface IProjectDataService {
Expand Down Expand Up @@ -55,6 +57,7 @@ interface IPlatformProjectService {
afterPrepareAllPlugins(): IFuture<void>;
getAppResourcesDestinationDirectoryPath(): IFuture<string>;
deploy(deviceIdentifier: string): IFuture<void>;
processConfigurationFilesFromAppResources(): IFuture<void>;
}

interface IAndroidProjectPropertiesManager {
Expand Down
11 changes: 8 additions & 3 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
///<reference path=".d.ts"/>
"use strict";

import * as constants from "./constants";
import * as path from "path";
import * as os from "os";
import {EOL} from "os";

export class ProjectData implements IProjectData {
private static OLD_PROJECT_FILE_NAME = ".tnsproject";
Expand All @@ -12,6 +13,8 @@ export class ProjectData implements IProjectData {
public projectFilePath: string;
public projectId: string;
public projectName: string;
public appDirectoryPath: string;
public appResourcesDirectoryPath: string;
public dependencies: any;

constructor(private $fs: IFileSystem,
Expand All @@ -37,8 +40,8 @@ export class ProjectData implements IProjectData {
fileContent = this.$fs.readJson(this.projectFilePath).wait();
data = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
} catch (err) {
this.$errors.fail({formatStr: "The project file %s is corrupted." + os.EOL +
"Consider restoring an earlier version from your source control or backup." + os.EOL +
this.$errors.fail({formatStr: "The project file %s is corrupted." + EOL +
"Consider restoring an earlier version from your source control or backup." + EOL +
"Additional technical info: %s",
suppressCommandHelp: true},
this.projectFilePath, err.toString());
Expand Down Expand Up @@ -101,6 +104,8 @@ export class ProjectData implements IProjectData {
this.projectName = this.$projectHelper.sanitizeName(path.basename(projectDir));
this.platformsDir = path.join(projectDir, "platforms");
this.projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
this.appDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME);
this.appResourcesDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
}
}
$injector.register("projectData", ProjectData);
47 changes: 32 additions & 15 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
private static VALUES_DIRNAME = "values";
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v";
private static ANDROID_PLATFORM_NAME = "android";
private static LIBS_FOLDER_NAME = "libs";
private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.3.0";

private _androidProjectPropertiesManagers: IDictionary<IAndroidProjectPropertiesManager>;
Expand Down Expand Up @@ -252,9 +251,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
this.$fs.ensureDirectoryExists(targetPath).wait();

shell.cp("-f", path.join(libraryPath, "*.jar"), targetPath);
let projectLibsDir = path.join(this.platformData.projectRoot, "libs");
this.$fs.ensureDirectoryExists(projectLibsDir).wait();
shell.cp("-f", path.join(libraryPath, "*.jar"), projectLibsDir);
}).future<void>()();
}

Expand All @@ -280,25 +276,46 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
public preparePluginNativeCode(pluginData: IPluginData): IFuture<void> {
return (() => {
let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
this.processResourcesFromPlugin(pluginData.name, pluginPlatformsFolderPath).wait();
}).future<void>()();
}

// Handle *.jars inside libs folder
let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME);
if(this.$fs.exists(libsFolderPath).wait()) {
this.addLibrary(libsFolderPath).wait();
public processConfigurationFilesFromAppResources(): IFuture<void> {
return (() => {
// Process androidManifest.xml from App_Resources
let manifestFilePath = path.join(this.$projectData.appResourcesDirectoryPath, this.platformData.normalizedPlatformName, this.platformData.configurationFileName);
if (this.$fs.exists(manifestFilePath).wait()) {
this.processResourcesFromPlugin("NativescriptAppResources", path.dirname(manifestFilePath)).wait();
}
}).future<void>()();
}

private processResourcesFromPlugin(pluginName: string, pluginPlatformsFolderPath: string): IFuture<void> {
return (() => {
let configurationsDirectoryPath = path.join(this.platformData.projectRoot, "configurations");
this.$fs.ensureDirectoryExists(configurationsDirectoryPath).wait();

let pluginConfigurationDirectoryPath = path.join(configurationsDirectoryPath, pluginName);
this.$fs.ensureDirectoryExists(pluginConfigurationDirectoryPath).wait();

// Copy include.gradle file
let includeGradleFilePath = path.join(pluginPlatformsFolderPath, "include.gradle");
if(this.$fs.exists(includeGradleFilePath).wait()) {
shell.cp("-f", includeGradleFilePath, pluginConfigurationDirectoryPath);
}

// Copy all resources from plugin
let resourcesDestinationDirectoryPath = path.join(this.platformData.projectRoot, "src", pluginName);
this.$fs.ensureDirectoryExists(resourcesDestinationDirectoryPath).wait();
shell.cp("-Rf", path.join(pluginPlatformsFolderPath, "*"), resourcesDestinationDirectoryPath);
}).future<void>()();
}

public removePluginNativeCode(pluginData: IPluginData): IFuture<void> {
return (() => {
try {
let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME);

if(this.$fs.exists(libsFolderPath).wait()) {
let pluginJars = this.$fs.enumerateFilesInDirectorySync(libsFolderPath);
_.each(pluginJars, jarName => this.$fs.deleteFile(path.join(libsFolderPath, jarName)).wait());
}
this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, "configurations", pluginData.name)).wait();
this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, "src", pluginData.name)).wait();
} catch(e) {
if (e.code === "ENOENT") {
this.$logger.debug("No native code jars found: " + e.message);
Expand Down
4 changes: 4 additions & 0 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
}).future<void>()();
}

public processConfigurationFilesFromAppResources(): IFuture<void> {
return Future.fromResult();
}

private get projectPodFilePath(): string {
return path.join(this.platformData.projectRoot, "Podfile");
}
Expand Down
3 changes: 3 additions & 0 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ export class PlatformService implements IPlatformService {
let excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME];
this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs).wait();

// Process configurations files from App_Resources
platformData.platformProjectService.processConfigurationFilesFromAppResources().wait();

this.$logger.out("Project successfully prepared");
}).future<void>()();
}
Expand Down
3 changes: 2 additions & 1 deletion test/npm-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ function setupProject(): IFuture<any> {
prepareProject: () => Future.fromResult(),
prepareAppResources: () => Future.fromResult(),
afterPrepareAllPlugins: () => Future.fromResult(),
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
getAppResourcesDestinationDirectoryPath: () => Future.fromResult(""),
processConfigurationFilesFromAppResources: () => Future.fromResult()
}
};
};
Expand Down
6 changes: 4 additions & 2 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ describe('Platform Service Tests', () => {
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
interpolateData: (projectRoot: string) => Future.fromResult(),
afterCreateProject: (projectRoot: string) => Future.fromResult(),
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
getAppResourcesDestinationDirectoryPath: () => Future.fromResult(""),
processConfigurationFilesFromAppResources: () => Future.fromResult()
}
};
};
Expand Down Expand Up @@ -279,7 +280,8 @@ describe('Platform Service Tests', () => {
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
interpolateData: (projectRoot: string) => Future.fromResult(),
afterCreateProject: (projectRoot: string) => Future.fromResult(),
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
getAppResourcesDestinationDirectoryPath: () => Future.fromResult(""),
processConfigurationFilesFromAppResources: () => Future.fromResult()
}
};
};
Expand Down
7 changes: 6 additions & 1 deletion test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ export class ProjectDataStub implements IProjectData {
projectFilePath: string;
projectId: string;
dependencies: any;
appDirectoryPath: string;
appResourcesDirectoryPath: string;
}

export class PlatformsDataStub implements IPlatformsData {
Expand All @@ -265,7 +267,7 @@ export class PlatformsDataStub implements IPlatformsData {
deviceBuildOutputPath: "",
validPackageNamesForDevice: [],
frameworkFilesExtensions: [],
relativeToFrameworkConfigurationFilePath: "",
relativeToFrameworkConfigurationFilePath: ""
};
}

Expand Down Expand Up @@ -340,6 +342,9 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
deploy(deviceIdentifier: string): IFuture<void> {
return Future.fromResult();
}
processConfigurationFilesFromAppResources(): IFuture<void> {
return Future.fromResult();
}
}

export class ProjectDataService implements IProjectDataService {
Expand Down