cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [4/5] git commit: package id changes supported in android
Date Wed, 10 Oct 2012 22:15:19 GMT
package id changes supported in android


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/3b42d944
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/3b42d944
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/3b42d944

Branch: refs/heads/cordova-client
Commit: 3b42d9442548f07b15347274aae65962839c4ed8
Parents: 1c4e9b5
Author: Fil Maj <maj.fil@gmail.com>
Authored: Wed Oct 10 11:08:57 2012 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Wed Oct 10 11:08:57 2012 -0700

----------------------------------------------------------------------
 .../projects/native/android/AndroidManifest.xml    |    2 +-
 .../src/io/cordova/hellocordova/HelloCordova.java  |   35 +++++++++++++++
 .../org/apache/cordova/example/cordovaExample.java |   35 ---------------
 spec/fixtures/projects/test/www/config.xml         |    2 +-
 spec/metadata/android_parser.spec.js               |   23 +++++++++-
 src/metadata/android_parser.js                     |   18 +++++++-
 6 files changed, 76 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/3b42d944/spec/fixtures/projects/native/android/AndroidManifest.xml
----------------------------------------------------------------------
diff --git a/spec/fixtures/projects/native/android/AndroidManifest.xml b/spec/fixtures/projects/native/android/AndroidManifest.xml
index 1e7b31b..8a06d72 100644
--- a/spec/fixtures/projects/native/android/AndroidManifest.xml
+++ b/spec/fixtures/projects/native/android/AndroidManifest.xml
@@ -18,7 +18,7 @@
        under the License.
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
-      package="org.apache.cordova.example" android:versionName="1.1" android:versionCode="5"
android:hardwareAccelerated="true">
+      package="io.cordova.hellocordova" android:versionName="1.1" android:versionCode="5"
android:hardwareAccelerated="true">
     <supports-screens
         android:largeScreens="true"
         android:normalScreens="true"

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/3b42d944/spec/fixtures/projects/native/android/src/io/cordova/hellocordova/HelloCordova.java
----------------------------------------------------------------------
diff --git a/spec/fixtures/projects/native/android/src/io/cordova/hellocordova/HelloCordova.java
b/spec/fixtures/projects/native/android/src/io/cordova/hellocordova/HelloCordova.java
new file mode 100644
index 0000000..8a2c820
--- /dev/null
+++ b/spec/fixtures/projects/native/android/src/io/cordova/hellocordova/HelloCordova.java
@@ -0,0 +1,35 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+ */
+
+package io.cordova.hellocordova;
+
+import android.app.Activity;
+import android.os.Bundle;
+import org.apache.cordova.*;
+
+public class HelloCordova extends DroidGap
+{
+    @Override
+    public void onCreate(Bundle savedInstanceState)
+    {
+        super.onCreate(savedInstanceState);
+        super.loadUrl("file:///android_asset/www/index.html");
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/3b42d944/spec/fixtures/projects/native/android/src/org/apache/cordova/example/cordovaExample.java
----------------------------------------------------------------------
diff --git a/spec/fixtures/projects/native/android/src/org/apache/cordova/example/cordovaExample.java
b/spec/fixtures/projects/native/android/src/org/apache/cordova/example/cordovaExample.java
deleted file mode 100644
index 56b8dd3..0000000
--- a/spec/fixtures/projects/native/android/src/org/apache/cordova/example/cordovaExample.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-       Licensed to the Apache Software Foundation (ASF) under one
-       or more contributor license agreements.  See the NOTICE file
-       distributed with this work for additional information
-       regarding copyright ownership.  The ASF licenses this file
-       to you under the Apache License, Version 2.0 (the
-       "License"); you may not use this file except in compliance
-       with the License.  You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-       Unless required by applicable law or agreed to in writing,
-       software distributed under the License is distributed on an
-       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-       KIND, either express or implied.  See the License for the
-       specific language governing permissions and limitations
-       under the License.
- */
-
-package org.apache.cordova.example;
-
-import android.app.Activity;
-import android.os.Bundle;
-import org.apache.cordova.*;
-
-public class cordovaExample extends DroidGap
-{
-    @Override
-    public void onCreate(Bundle savedInstanceState)
-    {
-        super.onCreate(savedInstanceState);
-        super.loadUrl("file:///android_asset/www/index.html");
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/3b42d944/spec/fixtures/projects/test/www/config.xml
----------------------------------------------------------------------
diff --git a/spec/fixtures/projects/test/www/config.xml b/spec/fixtures/projects/test/www/config.xml
index 7926c49..1cec68b 100644
--- a/spec/fixtures/projects/test/www/config.xml
+++ b/spec/fixtures/projects/test/www/config.xml
@@ -1,4 +1,4 @@
 <?xml version='1.0' encoding='utf-8'?>
-<widget id="com.phonegap.hello-world" version="2.0.0" xmlns="http://www.w3.org/ns/widgets"
xmlns:gap="http://phonegap.com/ns/1.0">
+<widget id="io.cordova.hellocordova" version="2.0.0" xmlns="http://www.w3.org/ns/widgets"
xmlns:gap="http://phonegap.com/ns/1.0">
     <name>bond. james bond.</name>
 </widget>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/3b42d944/spec/metadata/android_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/android_parser.spec.js b/spec/metadata/android_parser.spec.js
index 33fb88a..18adccc 100644
--- a/spec/metadata/android_parser.spec.js
+++ b/spec/metadata/android_parser.spec.js
@@ -7,12 +7,15 @@ var android_parser = require('../../src/metadata/android_parser'),
     cfg_path = path.join(__dirname, '..', 'fixtures', 'projects', 'test', 'www', 'config.xml'),
     android_path = path.join(__dirname, '..', 'fixtures', 'projects', 'native', 'android'),
     android_strings = path.join(android_path, 'res', 'values', 'strings.xml'),
+    android_manifest = path.join(android_path, 'AndroidManifest.xml'),
     tempDir = path.join(__dirname, '..', '..', 'temp'),
     cordova = require('../../cordova');
 
 var cwd = process.cwd();
 
 var original_strings = fs.readFileSync(android_strings, 'utf-8');
+var original_manifest = fs.readFileSync(android_manifest, 'utf-8');
+var original_config = fs.readFileSync(cfg_path, 'utf-8');
 
 describe('android project parser', function() {
     it('should throw an exception with a path that is not a native android project', function()
{
@@ -37,6 +40,8 @@ describe('android project parser', function() {
         });
         afterEach(function() {
             fs.writeFileSync(android_strings, original_strings, 'utf-8');
+            fs.writeFileSync(android_manifest, original_manifest, 'utf-8');
+            fs.writeFileSync(cfg_path, original_config, 'utf-8');
         });
         it('should throw an exception if a non config_parser object is passed into it', function()
{
             expect(function() {
@@ -52,7 +57,23 @@ describe('android project parser', function() {
 
             expect(app_name).toBe('bond. james bond.');
         });
-        it('should update the application package name properly');
+        it('should update the application package name properly', function() {
+            var javs = path.join(android_path, 'src', 'ca', 'filmaj', 'dewd', 'HelloCordova.java');
+            var orig_javs = path.join(android_path, 'src', 'io', 'cordova', 'hellocordova',
'HelloCordova.java');
+            var orig_contents = fs.readFileSync(orig_javs, 'utf-8');
+            this.after(function() {
+                fs.writeFileSync(orig_javs, orig_contents, 'utf-8');
+                shell.rm('-rf', path.join(android_path, 'src', 'ca'));
+            });
+            config.packageName('ca.filmaj.dewd');
+            project.update_from_config(config);
+
+            var manifest = new et.ElementTree(et.XML(fs.readFileSync(android_manifest, 'utf-8')));
+            expect(manifest.getroot().attrib.package).toEqual('ca.filmaj.dewd');
+
+            expect(fs.existsSync(javs)).toBe(true);
+            expect(fs.readFileSync(javs, 'utf-8')).toMatch(/package ca.filmaj.dewd/i);
+        });
     });
 
     describe('update_www method', function() {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/3b42d944/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index 04b8698..ffa06ea 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -10,7 +10,8 @@ module.exports = function android_parser(project) {
         throw 'The provided path is not an Android project.';
     }
     this.path = project;
-    this.strings = path.join(this.path, 'res', 'values', 'strings.xml')
+    this.strings = path.join(this.path, 'res', 'values', 'strings.xml');
+    this.manifest = path.join(this.path, 'AndroidManifest.xml');
 };
 
 module.exports.prototype = {
@@ -22,6 +23,21 @@ module.exports.prototype = {
         var strings = new et.ElementTree(et.XML(fs.readFileSync(this.strings, 'utf-8')));
         strings.find('string[@name="app_name"]').text = name;
         fs.writeFileSync(this.strings, strings.write({indent: 4}), 'utf-8');
+
+        var manifest = new et.ElementTree(et.XML(fs.readFileSync(this.manifest, 'utf-8')));
+        var pkg = config.packageName();
+        var orig_pkg = manifest.getroot().attrib.package;
+        manifest.getroot().attrib.package = pkg;
+        fs.writeFileSync(this.manifest, manifest.write({indent: 4}), 'utf-8');
+        var orig_pkgDir = path.join(this.path, 'src', path.join.apply(null, orig_pkg.split('.')));
+        var orig_java_class = fs.readdirSync(orig_pkgDir)[0];
+        var pkgDir = path.join(this.path, 'src', path.join.apply(null, pkg.split('.')));
+        shell.mkdir('-p', pkgDir);
+        var orig_javs = path.join(orig_pkgDir, orig_java_class);
+        var new_javs = path.join(pkgDir, orig_java_class);
+        var javs_contents = fs.readFileSync(orig_javs, 'utf-8');
+        javs_contents = javs_contents.replace(/package [\w\.]*;/, 'package ' + pkg + ';');
+        fs.writeFileSync(new_javs, javs_contents, 'utf-8');
     },
     update_www:function() {
         var projectRoot = util.isCordova(process.cwd());


Mime
View raw message