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 2013/09/14 05:08:29 UTC

[09/11] android commit: [CB-4817] Avoid generating unused files in create script

[CB-4817] Avoid generating unused files in create script

by using "android update project" instead of "android create project"


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

Branch: refs/heads/master
Commit: cad673f8cd2d172d6796301c90b28a86416ea954
Parents: 7c446b2
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Sep 13 22:47:18 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Sep 13 22:49:15 2013 -0400

----------------------------------------------------------------------
 bin/lib/create.js                            | 25 +++++++++++------------
 bin/templates/project/res/values/strings.xml |  4 ++++
 2 files changed, 16 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/cad673f8/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index fc1f8da..6826b9f 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -127,7 +127,6 @@ exports.createProject = function(project_path, package_name, project_name, proje
     var activity_dir    = path.join(project_path, 'src', package_as_path);
     var activity_path   = path.join(activity_dir, safe_activity_name + '.java');
     var target_api      = check_reqs.get_target();
-    var strings_path    = path.join(project_path, 'res', 'values', 'strings.xml');
     var manifest_path   = path.join(project_path, 'AndroidManifest.xml');
 
     // Check if project already exists
@@ -147,25 +146,23 @@ exports.createProject = function(project_path, package_name, project_name, proje
     }
 
     // Log the given values for the project
-    console.log('Creating Cordova project for the Android platform :');
-    console.log('\tPath : ' + project_path);
-    console.log('\tPackage : ' + package_name);
-    console.log('\tName : ' + project_name);
-    console.log('\tAndroid target : ' + target_api);
+    console.log('Creating Cordova project for the Android platform:');
+    console.log('\tPath: ' + project_path);
+    console.log('\tPackage: ' + package_name);
+    console.log('\tName: ' + project_name);
+    console.log('\tAndroid target: ' + target_api);
 
     // build from source. distro should have these files
     ensureJarIsBuilt(VERSION, target_api);
 
-    // create new android project
-    var create_cmd = 'android create project --target "'+target_api+'" --path "'+ project_path+'" --package "'+package_name+'" --activity "'+safe_activity_name+'"';
-    exec(create_cmd);
-
     console.log('Copying template files...');
 
     setShellFatal(true, function() {
         // copy project template
         shell.cp('-r', path.join(project_template_dir, 'assets'), project_path);
         shell.cp('-r', path.join(project_template_dir, 'res'), project_path);
+        // Manually create directories that would be empty within the template (since git doesn't track directories).
+        shell.mkdir(path.join(project_path, 'libs'));
 
         // copy cordova.js, cordova.jar and res/xml
         shell.cp('-r', path.join(ROOT, 'framework', 'res', 'xml'), path.join(project_path, 'res'));
@@ -175,17 +172,19 @@ exports.createProject = function(project_path, package_name, project_name, proje
         shell.mkdir('-p', activity_dir);
         shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path);
         shell.sed('-i', /__ACTIVITY__/, safe_activity_name, activity_path);
+        shell.sed('-i', /__NAME__/, project_name, path.join(project_path, 'res', 'values', 'strings.xml'));
         shell.sed('-i', /__ID__/, package_name, activity_path);
 
-        // interpolate the app name into strings.xml
-        shell.sed('-i', />Cordova</, '>' + project_name + '<', strings_path);
-
         shell.cp('-f', path.join(project_template_dir, 'AndroidManifest.xml'), manifest_path);
         shell.sed('-i', /__ACTIVITY__/, safe_activity_name, manifest_path);
         shell.sed('-i', /__PACKAGE__/, package_name, manifest_path);
         shell.sed('-i', /__APILEVEL__/, target_api.split('-')[1], manifest_path);
         copyScripts(project_path);
     });
+    // Link it to local android install.
+    console.log('Running "android update project"');
+    exec('android --silent update project --target "'+target_api+'" --path "'+ project_path+'"');
+    console.log('Project successfully created.');
 }
 
 exports.updateProject = function(projectPath) {

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/cad673f8/bin/templates/project/res/values/strings.xml
----------------------------------------------------------------------
diff --git a/bin/templates/project/res/values/strings.xml b/bin/templates/project/res/values/strings.xml
new file mode 100644
index 0000000..e8ed749
--- /dev/null
+++ b/bin/templates/project/res/values/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">__NAME__</string>
+</resources>