Skip to content

Commit b40c688

Browse files
Mihail Slavchevfealebenpae
authored andcommitted
generate build.xml file(s) for the reference project(s)
1 parent 1e30cb8 commit b40c688

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

lib/services/android-project-service.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AndroidProjectService implements IPlatformProjectService {
1919
private $errors: IErrors,
2020
private $fs: IFileSystem,
2121
private $logger: ILogger,
22-
private $projectData: IProjectData,
22+
private $projectData: IProjectData,
2323
private $propertiesParser: IPropertiesParser) {
2424

2525
}
@@ -133,6 +133,12 @@ class AndroidProjectService implements IPlatformProjectService {
133133
return this.$fs.exists(path.join(projectRoot, "assets", constants.APP_FOLDER_NAME));
134134
}
135135

136+
private generateBuildFile(projDir: string, targetSdk: string): void {
137+
this.$logger.info("Generate build.xml for %s", projDir);
138+
var cmd = util.format("android update project -p %s --target %s --subprojects", projDir, targetSdk);
139+
this.$childProcess.exec(cmd).wait();
140+
}
141+
136142
private parseProjectProrperies(projDir: string, destDir: string): void {
137143

138144
var projProp = path.join(projDir, "project.properties");
@@ -148,22 +154,47 @@ class AndroidProjectService implements IPlatformProjectService {
148154
var match = elem.match(/android\.library\.reference\.(\d+)=(.*)/);
149155
if (match) {
150156
var libRef: ILibRef = { idx: parseInt(match[1]), path: match[2] };
151-
libRef.adjustedPath = path.join(projDir, libRef.path);
157+
libRef.adjustedPath = thiz.$fs.isRelativePath(libRef.path) ? path.join(projDir, libRef.path) : libRef.path;
152158
thiz.parseProjectProrperies(libRef.adjustedPath, destDir);
153159
}
154160
});
155161

156162
this.$logger.info("Copying %s", projDir);
157163
shell.cp("-Rf", projDir, destDir);
164+
165+
var targetDir = path.join(destDir, path.basename(projDir));
166+
// TODO: parametrize targetSdk
167+
var targetSdk = "android-17";
168+
this.generateBuildFile(targetDir, targetSdk);
169+
}
170+
171+
private updateProjectReferences(projDir: string, libraryPath: string): void {
172+
var projProp = path.join(projDir, "project.properties");
173+
174+
var lines = fs.readFileSync(projProp, { encoding: "utf-8" }).split("\n");
175+
var thiz = this;
176+
177+
lines.forEach(function (elem, idx, arr) {
178+
var match = elem.match(/android\.library\.reference\.(\d+)=(.*)/);
179+
if (match) {
180+
var libRef: ILibRef = { idx: parseInt(match[1]), path: match[2] };
181+
// TODO: handle path.join of two absolute paths
182+
libRef.adjustedPath = path.join(projDir, libRef.path);
183+
thiz.parseProjectProrperies(libRef.adjustedPath, "###");
184+
}
185+
});
158186
}
159187

160188
public addLibrary(platformData: IPlatformData, libraryPath: string): IFuture<void> {
161189
var name = path.basename(libraryPath);
162-
var targetPath = path.join(this.$projectData.projectDir, "lib", platformData.normalizedPlatformName);
190+
var projDir = this.$projectData.projectDir;
191+
var targetPath = path.join(projDir, "lib", platformData.normalizedPlatformName);
163192
this.$fs.ensureDirectoryExists(targetPath).wait();
164193

165194
this.parseProjectProrperies(libraryPath, targetPath);
166195

196+
this.updateProjectReferences(projDir, libraryPath);
197+
167198
this.$errors.fail("Implement me!");
168199
return Future.fromResult();
169200
}

0 commit comments

Comments
 (0)