Skip to content

Commit 23577ef

Browse files
Fatme HavaluovaFatme
Fatme Havaluova
authored andcommitted
Support for android native libraries in plugin
1 parent 012a406 commit 23577ef

10 files changed

+478
-140
lines changed

lib/definitions/libref.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ interface ILibRef {
22
idx: number;
33
path: string;
44
adjustedPath?: string;
5+
key?: string;
56
}

lib/definitions/plugins.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ interface IPluginsService {
77
}
88

99
interface IPluginData extends INodeModuleData {
10-
platformsData: IPluginPlatformsData;
10+
platformsData: IPluginPlatformsData;
11+
pluginPlatformsFolderPath(platform: string): string;
1112
}
1213

1314
interface INodeModuleData {

lib/definitions/project.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ interface IPlatformProjectService {
3333
addLibrary(platformData: IPlatformData, libraryPath: string): IFuture<void>;
3434
canUpdatePlatform(currentVersion: string, newVersion: string): IFuture<boolean>;
3535
updatePlatform(currentVersion: string, newVersion: string): IFuture<void>;
36+
preparePluginNativeCode(pluginData: IPluginData): IFuture<void>;
37+
removePluginNativeCode(pluginData: IPluginData): IFuture<void>;
38+
}
39+
40+
interface IAndroidProjectPropertiesManager {
41+
getProjectReferences(): IFuture<ILibRef[]>;
42+
addProjectReference(referencePath: string): IFuture<void>;
43+
removeProjectReference(referencePath: string): IFuture<void>;
3644
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
///<reference path="../.d.ts"/>
2+
"use strict";
3+
4+
import path = require("path");
5+
6+
export class AndroidProjectPropertiesManager implements IAndroidProjectPropertiesManager {
7+
private static LIBRARY_REFERENCE_KEY_PREFIX = "android.library.reference.";
8+
9+
private _editor: IPropertiesParserEditor = null;
10+
private filePath: string = null;
11+
private projectReferences: ILibRef[];
12+
private dirty = false;
13+
14+
constructor(private $propertiesParser: IPropertiesParser,
15+
private $fs: IFileSystem,
16+
directoryPath: string) {
17+
this.filePath = path.join(directoryPath, "project.properties");
18+
}
19+
20+
public addToPropertyList(key: string, value: string): IFuture<void> {
21+
return (() => {
22+
let editor = this.createEditor().wait();
23+
let i = 1;
24+
while (editor.get(this.buildKeyName(key, i))) {
25+
i++;
26+
}
27+
28+
editor.set(this.buildKeyName(key, i), value);
29+
this.$propertiesParser.saveEditor().wait();
30+
this.dirty = true;
31+
}).future<void>()();
32+
}
33+
34+
public removeFromPropertyList(key: string, value: string): IFuture<void> {
35+
return (() => {
36+
let editor = this.createEditor().wait();
37+
let valueLowerCase = value.toLowerCase();
38+
let i = 1;
39+
let currentValue: any;
40+
while (currentValue = editor.get(this.buildKeyName(key, i))) {
41+
if (currentValue.toLowerCase() === valueLowerCase) {
42+
while (currentValue = editor.get(this.buildKeyName(key, i+1))) {
43+
editor.set(this.buildKeyName(key, i), currentValue);
44+
i++;
45+
}
46+
editor.set(this.buildKeyName(key, i));
47+
break;
48+
}
49+
i++;
50+
}
51+
this.$propertiesParser.saveEditor().wait();
52+
this.dirty = true;
53+
}).future<void>()();
54+
}
55+
56+
public getProjectReferences(): IFuture<ILibRef[]> {
57+
return (() => {
58+
if(!this.projectReferences || this.dirty) {
59+
let allProjectProperties = this.getAllProjectProperties().wait();
60+
let allProjectPropertiesKeys = _.keys(allProjectProperties);
61+
this.projectReferences = _(allProjectPropertiesKeys)
62+
.filter(key => _.startsWith(key, "android.library.reference."))
63+
.map(key => this.createLibraryReference(key, allProjectProperties[key]))
64+
.value();
65+
}
66+
67+
return this.projectReferences;
68+
}).future<ILibRef[]>()();
69+
}
70+
71+
public addProjectReference(referencePath: string): IFuture<void> {
72+
return (() => {
73+
let references = this.getProjectReferences().wait();
74+
let libRefExists = _.any(references, r => path.normalize(r.path) === path.normalize(referencePath));
75+
if(!libRefExists) {
76+
this.addToPropertyList("android.library.reference", referencePath).wait();
77+
}
78+
}).future<void>()();
79+
}
80+
81+
public removeProjectReference(referencePath: string): IFuture<void> {
82+
return (() => {
83+
let references = this.getProjectReferences().wait();
84+
let libRefExists = _.any(references, r => path.normalize(r.path) === path.normalize(referencePath));
85+
if(libRefExists) {
86+
this.removeFromPropertyList("android.library.reference", referencePath).wait();
87+
}
88+
}).future<void>()();
89+
}
90+
91+
private createEditor(): IFuture<any> {
92+
return (() => {
93+
return this._editor || this.$propertiesParser.createEditor(this.filePath).wait();
94+
}).future<any>()();
95+
}
96+
97+
private buildKeyName(key: string, index: number): string {
98+
return `${key}.${index}`;
99+
}
100+
101+
private getAllProjectProperties(): IFuture<IStringDictionary> {
102+
return this.$propertiesParser.read(this.filePath);
103+
}
104+
105+
private createLibraryReference(referenceName: string, referencePath: string): ILibRef {
106+
return {
107+
idx: parseInt(referenceName.split("android.library.reference.")[1]),
108+
key: referenceName,
109+
path: referencePath,
110+
adjustedPath: path.join(path.dirname(this.filePath), referencePath)
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)