CB-3445 Copy gradle wrapper in build instead of create

This should play nicer with updates to the android SDK.


Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/2d71d89c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/2d71d89c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/2d71d89c

Branch: refs/heads/master
Commit: 2d71d89c4d72b73dae8f6ad62036d7d80dd38b2d
Parents: 94650c0
Author: Andrew Grieve <[email protected]>
Authored: Mon Aug 18 14:51:10 2014 -0400
Committer: Archana Naik <[email protected]>
Committed: Mon Aug 18 12:41:39 2014 -0700

----------------------------------------------------------------------
 bin/lib/check_reqs.js              | 17 -----------------
 bin/lib/create.js                  | 17 -----------------
 bin/templates/cordova/lib/build.js | 19 +++++++++++++++++++
 3 files changed, 19 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/2d71d89c/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index 844ce6e..ce71e1a 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -64,23 +64,6 @@ module.exports.get_target = function() {
     }
 }
 
-// Returns a promise.
-module.exports.sdk_dir = function() {
-    var d = Q.defer();
-    which('android', function(err, path) {
-        if (err) {
-            d.reject(new Error('ERROR: Cannot find Android SDK. android 
command not found.'));
-        } else {
-            var toolsDir = path.substring(0, path.lastIndexOf('/'));
-            if (toolsDir.substring(toolsDir.length-6) != "/tools") {
-                d.reject(new Error('ERROR: Cannot find Android SDK. android 
command not found in tools dir.'));
-            }
-            d.resolve(toolsDir.substring(0, toolsDir.length-6));
-        }
-    });
-    return d.promise;
-};
-
 // Returns a promise. Called only by build and clean commands.
 module.exports.check_ant = function() {
     return tryCommand('ant -version', 'Failed to run "ant -version", make sure 
you have ant installed and added to your PATH.');

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/2d71d89c/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index cc36c67..b588f60 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -122,13 +122,6 @@ function copyScripts(projectPath) {
     shell.cp(path.join(ROOT, 'bin', 'lib', 'android_sdk_version.js'), 
path.join(projectPath, 'cordova', 'lib', 'android_sdk_version.js'));
 }
 
-function copyGradleWrapper(sdkPath, projectPath) {
-    var wrapperDir = path.join(sdkPath, 'tools', 
'templates','gradle','wrapper');
-    shell.cp(path.join(wrapperDir, 'gradlew'), projectPath);
-    shell.cp(path.join(wrapperDir, 'gradlew.bat'), projectPath);
-    shell.cp('-r', path.join(wrapperDir, 'gradle'), projectPath);
-}
-
 /**
  * Test whether a package name is acceptable for use as an android project.
  * Returns a promise, fulfilled if the package name is acceptable; rejected
@@ -258,16 +251,6 @@ exports.createProject = function(project_path, 
package_name, project_name, proje
             shell.cp('-r', path.join(project_template_dir, 'assets'), 
project_path);
             shell.cp('-r', path.join(ROOT, 'framework', 'res', 'xml'), 
path.join(project_path, 'res'));
 
-            shell.cp('-f', path.join(project_template_dir, 'build.gradle'), 
project_path);
-            shell.cp('-f', path.join(project_template_dir, 
'libraries.gradle'), project_path);
-            shell.cp('-f', path.join(project_template_dir, 'settings.gradle'), 
project_path);
-            check_reqs.sdk_dir().then(function(dir) {
-                console.log("Copying Gradle wrapper from " + dir);
-                copyGradleWrapper(dir, project_path);
-            }).catch(function(err) {
-                console.log("Cannot find Android SDK. Not installing Gradle 
wrapper.");
-            });
-
             // Manually create directories that would be empty within the 
template (since git doesn't track directories).
             shell.mkdir(path.join(project_path, 'libs'));
             // Add in the proper eclipse project file.

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/2d71d89c/bin/templates/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/build.js 
b/bin/templates/cordova/lib/build.js
index 1f0cd23..80e2282 100644
--- a/bin/templates/cordova/lib/build.js
+++ b/bin/templates/cordova/lib/build.js
@@ -51,6 +51,24 @@ function hasCustomRules() {
     return fs.existsSync(path.join(ROOT, 'custom_rules.xml'));
 }
 
+// Copy the gradle wrapper files on each build so that:
+// A) We don't require the Android SDK at project creation time, and
+// B) So that they are always up-to-date.
+function copyGradleWrapper() {
+    var projectPath = ROOT;
+    // check_reqs ensures that this is set.
+    var sdkDir = process.env['ANDROID_HOME'];
+    var wrapperDir = path.join(sdkDir, 'tools', 'templates', 'gradle', 
'wrapper');
+    if (process.platform == 'win32') {
+        shell.cp('-f', path.join(wrapperDir, 'gradlew.bat'), projectPath);
+    } else {
+        shell.cp('-f', path.join(wrapperDir, 'gradlew'), projectPath);
+    }
+    shell.rm('-rf', path.join(projectPath, 'gradle', 'wrapper'));
+    shell.mkdir('-p', path.join(projectPath, 'gradle'));
+    shell.cp('-r', path.join(wrapperDir, 'gradle', 'wrapper'), 
path.join(projectPath, 'gradle'));
+}
+
 module.exports.builders = {
     ant: {
         getArgs: function(cmd) {
@@ -129,6 +147,7 @@ module.exports.builders = {
             var builder = this;
             var wrapper = path.join(ROOT, 'gradlew');
             var args = builder.getArgs('build');
+            copyGradleWrapper();
             return Q().then(function() {
                 return spawn(wrapper, args);
             }).then(function() {

Reply via email to