You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2015/09/23 21:58:18 UTC

[07/45] android commit: CB-9149 Make gradle alias subprojects in order to handle libs that depend on libs. This closes #182

CB-9149 Make gradle alias subprojects in order to handle libs that depend on libs. This closes #182


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/dd1b2c44
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/dd1b2c44
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/dd1b2c44

Branch: refs/heads/5.0.x
Commit: dd1b2c44e7c5dd7e6077ab4b6d8acd0a2ac4fd3a
Parents: b008214
Author: Tony Homer <to...@intel.com>
Authored: Wed Jun 10 00:57:01 2015 -0400
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Aug 20 13:48:01 2015 -0700

----------------------------------------------------------------------
 bin/templates/cordova/lib/build.js | 34 ++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/dd1b2c44/bin/templates/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js
index 1794f93..9835172 100644
--- a/bin/templates/cordova/lib/build.js
+++ b/bin/templates/cordova/lib/build.js
@@ -102,6 +102,19 @@ function hasCustomRules() {
     return fs.existsSync(path.join(ROOT, 'custom_rules.xml'));
 }
 
+function extractRealProjectNameFromManifest(projectPath) {
+    var manifestPath = path.join(projectPath, 'AndroidManifest.xml');
+    var manifestData = fs.readFileSync(manifestPath, 'utf8');
+    var m = /<manifest[\s\S]*?package\s*=\s*"(.*?)"/i.exec(manifestData);
+    if (!m) {
+        throw new Error('Could not find package name in ' + manifestPath);
+    }
+
+    var packageName=m[1];
+    var lastDotIndex = packageName.lastIndexOf('.');
+    return packageName.substring(lastDotIndex + 1);
+}
+
 function extractProjectNameFromManifest(projectPath) {
     var manifestPath = path.join(projectPath, 'AndroidManifest.xml');
     var manifestData = fs.readFileSync(manifestPath, 'utf8');
@@ -245,18 +258,29 @@ var builders = {
                 }
             }
 
+            var name=extractRealProjectNameFromManifest(ROOT);
             var subProjectsAsGradlePaths = subProjects.map(function(p) { return ':' + p.replace(/[/\\]/g, ':'); });
+            //Remove the proj.id/name- prefix from projects: https://issues.apache.org/jira/browse/CB-9149
+            var settingsGradlePaths =  subProjects.map(function(p){
+                var realDir=p.replace(/[/\\]/g, ':');
+                var libName=realDir.replace(name+'-','');
+                var str='include ":'+libName+'"\n';
+                if(realDir.indexOf(name+'-')!==-1)
+                    str+='project(":'+libName+'").projectDir = new File("'+p+'")\n';
+                return str;
+            });
+
             // Write the settings.gradle file.
             fs.writeFileSync(path.join(projectPath, 'settings.gradle'),
                 '// GENERATED FILE - DO NOT EDIT\n' +
-                'include ":"\n' +
-                'include "' + subProjectsAsGradlePaths.join('"\ninclude "') + '"\n');
+                'include ":"\n' + settingsGradlePaths.join(''));
             // Update dependencies within build.gradle.
             var buildGradle = fs.readFileSync(path.join(projectPath, 'build.gradle'), 'utf8');
             var depsList = '';
-            subProjectsAsGradlePaths.forEach(function(p) {
-                depsList += '    debugCompile project(path: "' + p + '", configuration: "debug")\n';
-                depsList += '    releaseCompile project(path: "' + p + '", configuration: "release")\n';
+            subProjects.forEach(function(p) {
+                var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
+                depsList += '    debugCompile project(path: "' + libName + '", configuration: "debug")\n';
+                depsList += '    releaseCompile project(path: "' + libName + '", configuration: "release")\n';
             });
             // For why we do this mapping: https://issues.apache.org/jira/browse/CB-8390
             var SYSTEM_LIBRARY_MAPPINGS = [


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org