Skip to content

Commit f39fd09

Browse files
committed
Merge pull request #1135 from NativeScript/fatme/aapt
Support for include.gradle from plugins
2 parents 433334c + cb2c4b5 commit f39fd09

8 files changed

+62
-22
lines changed

lib/definitions/project.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface IProjectData {
1010
projectFilePath: string;
1111
projectId?: string;
1212
dependencies: any;
13+
appDirectoryPath: string;
14+
appResourcesDirectoryPath: string;
1315
}
1416

1517
interface IProjectDataService {
@@ -55,6 +57,7 @@ interface IPlatformProjectService {
5557
afterPrepareAllPlugins(): IFuture<void>;
5658
getAppResourcesDestinationDirectoryPath(): IFuture<string>;
5759
deploy(deviceIdentifier: string): IFuture<void>;
60+
processConfigurationFilesFromAppResources(): IFuture<void>;
5861
}
5962

6063
interface IAndroidProjectPropertiesManager {

lib/project-data.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
///<reference path=".d.ts"/>
22
"use strict";
33

4+
import * as constants from "./constants";
45
import * as path from "path";
5-
import * as os from "os";
6+
import {EOL} from "os";
67

78
export class ProjectData implements IProjectData {
89
private static OLD_PROJECT_FILE_NAME = ".tnsproject";
@@ -12,6 +13,8 @@ export class ProjectData implements IProjectData {
1213
public projectFilePath: string;
1314
public projectId: string;
1415
public projectName: string;
16+
public appDirectoryPath: string;
17+
public appResourcesDirectoryPath: string;
1518
public dependencies: any;
1619

1720
constructor(private $fs: IFileSystem,
@@ -37,8 +40,8 @@ export class ProjectData implements IProjectData {
3740
fileContent = this.$fs.readJson(this.projectFilePath).wait();
3841
data = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
3942
} catch (err) {
40-
this.$errors.fail({formatStr: "The project file %s is corrupted." + os.EOL +
41-
"Consider restoring an earlier version from your source control or backup." + os.EOL +
43+
this.$errors.fail({formatStr: "The project file %s is corrupted." + EOL +
44+
"Consider restoring an earlier version from your source control or backup." + EOL +
4245
"Additional technical info: %s",
4346
suppressCommandHelp: true},
4447
this.projectFilePath, err.toString());
@@ -101,6 +104,8 @@ export class ProjectData implements IProjectData {
101104
this.projectName = this.$projectHelper.sanitizeName(path.basename(projectDir));
102105
this.platformsDir = path.join(projectDir, "platforms");
103106
this.projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
107+
this.appDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME);
108+
this.appResourcesDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
104109
}
105110
}
106111
$injector.register("projectData", ProjectData);

lib/services/android-project-service.ts

+32-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
1212
private static VALUES_DIRNAME = "values";
1313
private static VALUES_VERSION_DIRNAME_PREFIX = AndroidProjectService.VALUES_DIRNAME + "-v";
1414
private static ANDROID_PLATFORM_NAME = "android";
15-
private static LIBS_FOLDER_NAME = "libs";
1615
private static MIN_RUNTIME_VERSION_WITH_GRADLE = "1.3.0";
1716

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

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

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

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

293+
private processResourcesFromPlugin(pluginName: string, pluginPlatformsFolderPath: string): IFuture<void> {
294+
return (() => {
295+
let configurationsDirectoryPath = path.join(this.platformData.projectRoot, "configurations");
296+
this.$fs.ensureDirectoryExists(configurationsDirectoryPath).wait();
297+
298+
let pluginConfigurationDirectoryPath = path.join(configurationsDirectoryPath, pluginName);
299+
this.$fs.ensureDirectoryExists(pluginConfigurationDirectoryPath).wait();
300+
301+
// Copy include.gradle file
302+
let includeGradleFilePath = path.join(pluginPlatformsFolderPath, "include.gradle");
303+
if(this.$fs.exists(includeGradleFilePath).wait()) {
304+
shell.cp("-f", includeGradleFilePath, pluginConfigurationDirectoryPath);
305+
}
306+
307+
// Copy all resources from plugin
308+
let resourcesDestinationDirectoryPath = path.join(this.platformData.projectRoot, "src", pluginName);
309+
this.$fs.ensureDirectoryExists(resourcesDestinationDirectoryPath).wait();
310+
shell.cp("-Rf", path.join(pluginPlatformsFolderPath, "*"), resourcesDestinationDirectoryPath);
311+
}).future<void>()();
312+
}
313+
292314
public removePluginNativeCode(pluginData: IPluginData): IFuture<void> {
293315
return (() => {
294316
try {
295-
let pluginPlatformsFolderPath = this.getPluginPlatformsFolderPath(pluginData, AndroidProjectService.ANDROID_PLATFORM_NAME);
296-
let libsFolderPath = path.join(pluginPlatformsFolderPath, AndroidProjectService.LIBS_FOLDER_NAME);
297-
298-
if(this.$fs.exists(libsFolderPath).wait()) {
299-
let pluginJars = this.$fs.enumerateFilesInDirectorySync(libsFolderPath);
300-
_.each(pluginJars, jarName => this.$fs.deleteFile(path.join(libsFolderPath, jarName)).wait());
301-
}
317+
this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, "configurations", pluginData.name)).wait();
318+
this.$fs.deleteDirectory(path.join(this.platformData.projectRoot, "src", pluginData.name)).wait();
302319
} catch(e) {
303320
if (e.code === "ENOENT") {
304321
this.$logger.debug("No native code jars found: " + e.message);

lib/services/ios-project-service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
354354
}).future<void>()();
355355
}
356356

357+
public processConfigurationFilesFromAppResources(): IFuture<void> {
358+
return Future.fromResult();
359+
}
360+
357361
private get projectPodFilePath(): string {
358362
return path.join(this.platformData.projectRoot, "Podfile");
359363
}

lib/services/platform-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ export class PlatformService implements IPlatformService {
217217
let excludedDirs = [constants.APP_RESOURCES_FOLDER_NAME];
218218
this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs).wait();
219219

220+
// Process configurations files from App_Resources
221+
platformData.platformProjectService.processConfigurationFilesFromAppResources().wait();
222+
220223
this.$logger.out("Project successfully prepared");
221224
}).future<void>()();
222225
}

test/npm-support.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ function setupProject(): IFuture<any> {
123123
prepareProject: () => Future.fromResult(),
124124
prepareAppResources: () => Future.fromResult(),
125125
afterPrepareAllPlugins: () => Future.fromResult(),
126-
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
126+
getAppResourcesDestinationDirectoryPath: () => Future.fromResult(""),
127+
processConfigurationFilesFromAppResources: () => Future.fromResult()
127128
}
128129
};
129130
};

test/platform-service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ describe('Platform Service Tests', () => {
220220
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
221221
interpolateData: (projectRoot: string) => Future.fromResult(),
222222
afterCreateProject: (projectRoot: string) => Future.fromResult(),
223-
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
223+
getAppResourcesDestinationDirectoryPath: () => Future.fromResult(""),
224+
processConfigurationFilesFromAppResources: () => Future.fromResult()
224225
}
225226
};
226227
};
@@ -279,7 +280,8 @@ describe('Platform Service Tests', () => {
279280
createProject: (projectRoot: string, frameworkDir: string) => Future.fromResult(),
280281
interpolateData: (projectRoot: string) => Future.fromResult(),
281282
afterCreateProject: (projectRoot: string) => Future.fromResult(),
282-
getAppResourcesDestinationDirectoryPath: () => Future.fromResult("")
283+
getAppResourcesDestinationDirectoryPath: () => Future.fromResult(""),
284+
processConfigurationFilesFromAppResources: () => Future.fromResult()
283285
}
284286
};
285287
};

test/stubs.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ export class ProjectDataStub implements IProjectData {
249249
projectFilePath: string;
250250
projectId: string;
251251
dependencies: any;
252+
appDirectoryPath: string;
253+
appResourcesDirectoryPath: string;
252254
}
253255

254256
export class PlatformsDataStub implements IPlatformsData {
@@ -265,7 +267,7 @@ export class PlatformsDataStub implements IPlatformsData {
265267
deviceBuildOutputPath: "",
266268
validPackageNamesForDevice: [],
267269
frameworkFilesExtensions: [],
268-
relativeToFrameworkConfigurationFilePath: "",
270+
relativeToFrameworkConfigurationFilePath: ""
269271
};
270272
}
271273

@@ -340,6 +342,9 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
340342
deploy(deviceIdentifier: string): IFuture<void> {
341343
return Future.fromResult();
342344
}
345+
processConfigurationFilesFromAppResources(): IFuture<void> {
346+
return Future.fromResult();
347+
}
343348
}
344349

345350
export class ProjectDataService implements IProjectDataService {

0 commit comments

Comments
 (0)