cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject android commit: CB-8390 Add Gradle support for Play Services and Support libraries
Date Tue, 03 Feb 2015 04:27:22 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master 26ee1c454 -> ce351f5c3


CB-8390 Add Gradle support for Play Services and Support libraries


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

Branch: refs/heads/master
Commit: ce351f5c38a4fc11bddb7b5ab976ee8fdda6dfeb
Parents: 26ee1c4
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Mon Feb 2 23:26:53 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Feb 2 23:26:53 2015 -0500

----------------------------------------------------------------------
 bin/templates/cordova/lib/build.js | 56 ++++++++++++++++++++++++---------
 1 file changed, 41 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/ce351f5c/bin/templates/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/build.js b/bin/templates/cordova/lib/build.js
index 66fb704..40eec84 100644
--- a/bin/templates/cordova/lib/build.js
+++ b/bin/templates/cordova/lib/build.js
@@ -97,23 +97,21 @@ function extractProjectNameFromManifest(projectPath) {
     return m[1];
 }
 
-function extractSubProjectPaths() {
-    var data = fs.readFileSync(path.join(ROOT, 'project.properties'), 'utf8');
-    var libsSet = {};
-    var r = /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg
+function findAllUniq(data, r) {
+    var s = {};
     var m;
     while (m = r.exec(data)) {
-        libsSet[m[1]] = 1;
-    }
-    var gradleSet = {};
-    r = /^\s*cordova\.gradle\.include\.\d+=(.*)(?:\s|$)/mg
-    m;
-    while (m = r.exec(data)) {
-        gradleSet[m[1]] = 1;
+        s[m[1]] = 1;
     }
+    return Object.keys(s);
+}
+
+function readProjectProperties() {
+    var data = fs.readFileSync(path.join(ROOT, 'project.properties'), 'utf8');
     return {
-      libs: Object.keys(libsSet),
-      gradleIncludes: Object.keys(gradleSet)
+        libs: findAllUniq(data, /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg),
+        gradleIncludes: findAllUniq(data, /^\s*cordova\.gradle\.include\.\d+=(.*)(?:\s|$)/mg),
+        systemLibs: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=(.*)(?:\s|$)/mg)
     };
 }
 
@@ -143,11 +141,15 @@ var builders = {
                         fs.writeFileSync(path.join(projectPath, 'local.properties'), LOCAL_PROPERTIES_TEMPLATE);
                     }
                 }
-                var subProjects = extractSubProjectPaths().libs;
                 writeBuildXml(ROOT);
+                var propertiesObj = readProjectProperties();
+                var subProjects = propertiesObj.libs;
                 for (var i = 0; i < subProjects.length; ++i) {
                     writeBuildXml(path.join(ROOT, subProjects[i]));
                 }
+                if (propertiesObj.systemLibs.length > 0) {
+                    throw new Error('Project contains at least one plugin that requires a
system library. This is not supported with ANT. Please build using gradle.');
+                }
             });
         },
 
@@ -233,7 +235,7 @@ var builders = {
 
                 // Update the version of build.gradle in each dependent library.
                 var pluginBuildGradle = path.join(projectPath, 'cordova', 'lib', 'plugin-build.gradle');
-                var propertiesObj = extractSubProjectPaths();
+                var propertiesObj = readProjectProperties();
                 var subProjects = propertiesObj.libs;
                 for (var i = 0; i < subProjects.length; ++i) {
                     if (subProjects[i] !== 'CordovaLib') {
@@ -254,6 +256,30 @@ var builders = {
                     depsList += '    debugCompile project(path: "' + p + '", configuration:
"debug")\n';
                     depsList += '    releaseCompile project(path: "' + p + '", configuration:
"release")\n';
                 });
+                // For why we do this mapping: https://issues.apache.org/jira/browse/CB-8390
+                var SYSTEM_LIBRARY_MAPPINGS = [
+                    [/^\/?extras\/android\/support\/(.*)$/, 'com.android.support:support-$1:+'],
+                    [/^\/?google\/google_play_services\/libproject\/google-play-services_lib\/?$/,
'com.google.android.gms:play-services:+']
+                ];
+                propertiesObj.systemLibs.forEach(function(p) {
+                    var mavenRef;
+                    // It's already in gradle form if it has two ':'s
+                    if (/:.*:/.exec(p)) {
+                        mavenRef = p;
+                    } else {
+                        for (var i = 0; i < SYSTEM_LIBRARY_MAPPINGS.length; ++i) {
+                            var pair = SYSTEM_LIBRARY_MAPPINGS[i];
+                            if (pair[0].exec(p)) {
+                                mavenRef = p.replace(pair[0], pair[1]);
+                                break;
+                            }
+                        }
+                        if (!mavenRef) {
+                            throw new Error('Unsupported system library (does not work with
gradle): ' + p);
+                        }
+                    }
+                    depsList += '    compile "' + mavenRef + '"\n';
+                });
                 buildGradle = buildGradle.replace(/(SUB-PROJECT DEPENDENCIES START)[\s\S]*(\/\/
SUB-PROJECT DEPENDENCIES END)/, '$1\n' + depsList + '    $2');
                 var includeList = '';
                 propertiesObj.gradleIncludes.forEach(function(includePath) {


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


Mime
View raw message