You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/08/19 18:03:19 UTC
[13/19] android commit: CB-3445 Copy gradle wrapper in build instead
of create
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-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/ca8bb75b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/ca8bb75b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/ca8bb75b
Branch: refs/heads/4.0.x
Commit: ca8bb75b4021566667743ac2b8a3da268b05d6be
Parents: 36eab71
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Aug 18 14:51:10 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Aug 18 14:51:40 2014 -0400
----------------------------------------------------------------------
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-android/blob/ca8bb75b/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index 6f20c19..61bd449 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-android/blob/ca8bb75b/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index d1f43e6..cc42f19 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -111,13 +111,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
@@ -225,16 +218,6 @@ exports.createProject = function(project_path, package_name, project_name, proje
shell.cp('-r', path.join(project_template_dir, 'res'), 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'));
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/ca8bb75b/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() {