cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nim...@apache.org
Subject android commit: CB-13031: Fix bug with case-sensitivity of android-packageName
Date Fri, 28 Jul 2017 11:19:23 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master 458e47968 -> 36d07d7a1


CB-13031: Fix bug with case-sensitivity of android-packageName

this closes #397


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

Branch: refs/heads/master
Commit: 36d07d7a15432e0bade5dd0c4ab0f0c38cb56fb2
Parents: 458e479
Author: Nikita Matrosov <v-nimatr@microsoft.com>
Authored: Fri Jul 28 14:05:53 2017 +0300
Committer: Nikita Matrosov <v-nimatr@microsoft.com>
Committed: Fri Jul 28 14:05:53 2017 +0300

----------------------------------------------------------------------
 bin/lib/create.js                    |  2 +-
 bin/templates/cordova/lib/prepare.js | 21 +++++++++++++--------
 spec/unit/create.spec.js             |  2 +-
 3 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/36d07d7a/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index ae32ce4..40df366 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -247,7 +247,7 @@ exports.create = function (project_path, config, options, events) {
         return Q.reject(new CordovaError('Project already exists! Delete and recreate'));
     }
 
-    var package_name = config.packageName() || 'my.cordova.project';
+    var package_name = config.android_packageName() || config.packageName() || 'my.cordova.project';
     var project_name = config.name() ?
         config.name().replace(/[^\w.]/g, '_') : 'CordovaExample';
 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/36d07d7a/bin/templates/cordova/lib/prepare.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js
index b0bfb29..39f9ae4 100644
--- a/bin/templates/cordova/lib/prepare.js
+++ b/bin/templates/cordova/lib/prepare.js
@@ -24,6 +24,7 @@ var path = require('path');
 var shell = require('shelljs');
 var events = require('cordova-common').events;
 var AndroidManifest = require('./AndroidManifest');
+var checkReqs = require('./check_reqs');
 var xmlHelpers = require('cordova-common').xmlHelpers;
 var CordovaError = require('cordova-common').CordovaError;
 var ConfigParser = require('cordova-common').ConfigParser;
@@ -181,10 +182,10 @@ function updateProjectAccordingTo (platformConfig, locations) {
     events.emit('verbose', 'Wrote out android application name "' + name + '" to ' + locations.strings);
 
     // Java packages cannot support dashes
-    var pkg = (platformConfig.android_packageName() || platformConfig.packageName()).replace(/-/g,
'_');
+    var androidPkgName = (platformConfig.android_packageName() || platformConfig.packageName()).replace(/-/g,
'_');
 
     var manifest = new AndroidManifest(locations.manifest);
-    var orig_pkg = manifest.getPackageId();
+    var manifestId = manifest.getPackageId();
 
     manifest.getActivity()
         .setOrientation(platformConfig.getPreference('orientation'))
@@ -192,13 +193,13 @@ function updateProjectAccordingTo (platformConfig, locations) {
 
     manifest.setVersionName(platformConfig.version())
         .setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
-        .setPackageId(pkg)
+        .setPackageId(androidPkgName)
         .setMinSdkVersion(platformConfig.getPreference('android-minSdkVersion', 'android'))
         .setMaxSdkVersion(platformConfig.getPreference('android-maxSdkVersion', 'android'))
         .setTargetSdkVersion(platformConfig.getPreference('android-targetSdkVersion', 'android'))
         .write();
 
-    var javaPattern = path.join(locations.root, 'src', orig_pkg.replace(/\./g, '/'), '*.java');
+    var javaPattern = path.join(locations.root, 'src', manifestId.replace(/\./g, '/'), '*.java');
     var java_files = shell.ls(javaPattern).filter(function (f) {
         return shell.grep(/extends\s+CordovaActivity/g, f);
     });
@@ -209,12 +210,16 @@ function updateProjectAccordingTo (platformConfig, locations) {
         events.emit('log', 'Multiple candidate Java files that extend CordovaActivity found.
Guessing at the first one, ' + java_files[0]);
     }
 
-    var destFile = path.join(locations.root, 'src', pkg.replace(/\./g, '/'), path.basename(java_files[0]));
+    var destFile = path.join(locations.root, 'src', androidPkgName.replace(/\./g, '/'), path.basename(java_files[0]));
     shell.mkdir('-p', path.dirname(destFile));
-    shell.sed(/package [\w\.]*;/, 'package ' + pkg + ';', java_files[0]).to(destFile);
-    events.emit('verbose', 'Wrote out Android package name "' + pkg + '" to ' + destFile);
+    shell.sed(/package [\w\.]*;/, 'package ' + androidPkgName + ';', java_files[0]).to(destFile);
+    events.emit('verbose', 'Wrote out Android package name "' + androidPkgName + '" to '
+ destFile);
 
-    if (orig_pkg !== pkg) {
+    var removeOrigPkg = checkReqs.isWindows() || checkReqs.isDarwin() ?
+        manifestId.toUpperCase() !== androidPkgName.toUpperCase() :
+        manifestId !== androidPkgName;
+
+    if (removeOrigPkg) {
         // If package was name changed we need to remove old java with main activity
         shell.rm('-Rf', java_files[0]);
         // remove any empty directories

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/36d07d7a/spec/unit/create.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/create.spec.js b/spec/unit/create.spec.js
index 8fdbdb8..bfd6295 100644
--- a/spec/unit/create.spec.js
+++ b/spec/unit/create.spec.js
@@ -148,7 +148,7 @@ describe('create', function () {
             spyOn(shell, 'cp');
             spyOn(shell, 'mkdir');
             spyOn(shell, 'sed');
-            config_mock = jasmine.createSpyObj('ConfigParser mock instance', ['packageName',
'name', 'android_activityName']);
+            config_mock = jasmine.createSpyObj('ConfigParser mock instance', ['packageName',
'android_packageName', 'name', 'android_activityName']);
             events_mock = jasmine.createSpyObj('EventEmitter mock instance', ['emit']);
             spyOn(check_reqs, 'get_target').and.returnValue(fake_android_target);
         });


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


Mime
View raw message