cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cordova-lib git commit: CB-6698 Fix directory resolution of framework with parent. This closes #289
Date Sat, 05 Dec 2015 01:44:04 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 18eacea16 -> bc3e973cc


CB-6698 Fix directory resolution of framework with parent. This closes #289


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

Branch: refs/heads/master
Commit: bc3e973ccc18079194e9a3638d036a671b351ac8
Parents: 18eacea
Author: Martin Bektchiev <martin.bektchiev@telerik.com>
Authored: Thu Aug 27 12:44:45 2015 +0300
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Fri Dec 4 17:38:47 2015 -0800

----------------------------------------------------------------------
 .../spec-plugman/platforms/android.spec.js      | 71 ++++++++++++++++++++
 .../plugin-lib2/AndroidManifest.xml             |  5 ++
 .../plugin-lib2/libFile                         |  1 +
 .../plugin-lib2/project.properties              |  1 +
 .../org.test.plugins.dummyplugin/plugin.xml     |  1 +
 cordova-lib/src/plugman/platforms/android.js    |  9 ++-
 cordova-lib/src/plugman/util/android-project.js |  6 +-
 7 files changed, 91 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/bc3e973c/cordova-lib/spec-plugman/platforms/android.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/platforms/android.spec.js b/cordova-lib/spec-plugman/platforms/android.spec.js
index de0ccb3..b8699a4 100644
--- a/cordova-lib/spec-plugman/platforms/android.spec.js
+++ b/cordova-lib/spec-plugman/platforms/android.spec.js
@@ -213,6 +213,77 @@ describe('android project handler', function() {
             finalProjectProperties = fs.readFileSync(mainProjectPropsFile, 'utf8');
             expect(finalProjectProperties).not.toMatch('\ncordova.system.library.1=' + 'extras/android/support/v4',
'Sublibrary not added');
         });
+        it('with custom=true and parent', function () {
+            var packageIdSuffix = 'childapp';
+            var frameworkElement = { src: 'plugin-lib', custom: true };
+            var frameworkElementChild = { src: 'plugin-lib2', custom: true, parent: 'plugin-lib'
};
+            var parentDir = path.resolve(temp, dummy_id, packageIdSuffix + '-' + frameworkElementChild.parent);
+            var parentProjectPropsFile = path.resolve(parentDir, 'project.properties');
+            var subDir = path.resolve(temp, dummy_id, packageIdSuffix + '-' + frameworkElement.src);
+            var subProjectPropsFile = path.resolve(subDir, 'project.properties');
+
+            var exec = spyOn(shell, 'exec');
+
+            android['framework'].install(frameworkElement, dummyplugin, temp, dummy_id, {
platformVersion: '3.0.0' });
+            android['framework'].install(frameworkElementChild, dummyplugin, temp, dummy_id,
{ platformVersion: '3.0.0' });
+            android.parseProjectFile(temp).write();
+
+            var finalProjectProperties = fs.readFileSync(parentProjectPropsFile, 'utf8');
+            expect(finalProjectProperties).toMatch('\nandroid.library.reference.1=../' +
packageIdSuffix + '-plugin-lib2', 'Reference to library not added');
+            var subProjectProperties = fs.readFileSync(subProjectPropsFile, 'utf8');
+            expect(subProjectProperties).toMatch(/\btarget=android-19$/m, 'target SDK version
not copied to library');
+            expect(exec).toHaveBeenCalledWith('android update lib-project --path "' + subDir
+ '"');
+
+            // Now test uninstall
+            android.purgeProjectFileCache(temp);
+            android['framework'].uninstall(frameworkElementChild, temp, dummy_id, { platformVersion:
'3.0.0' });
+            android.parseProjectFile(temp).write();
+
+            finalProjectProperties = fs.readFileSync(parentProjectPropsFile, 'utf8');
+            expect(finalProjectProperties).not.toMatch('\nandroid.library.reference.1=../'
+ packageIdSuffix + '-plugin-lib2', 'Reference to library not removed');
+
+            android['framework'].uninstall(frameworkElement, temp, dummy_id, { platformVersion:
'3.0.0' });
+            android.parseProjectFile(temp).write();
+
+            expect(fs.existsSync(subDir)).toBe(false, 'Should delete subdir');
+        });
+        it('with custom=false and parent', function () {
+            var packageIdSuffix = 'childapp';
+            var frameworkElement = { src: 'plugin-lib', custom: true };
+            var frameworkElementChild = { src: 'extras/android/support/v4', custom: false,
parent: 'plugin-lib' };
+            var parentDir = path.resolve(temp, dummy_id, packageIdSuffix + '-' + frameworkElementChild.parent);
+            var parentProjectPropsFile = path.resolve(parentDir, 'project.properties');
+            var sdkLibRelativeDir = path.join('..', 'SDK', 'extras', 'android', 'support',
'v4');
+            var exec = spyOn(shell, 'exec');
+
+            android['framework'].install(frameworkElement, dummyplugin, temp, dummy_id, {
platformVersion: '3.0.0' });
+            fs.writeFileSync(path.join(temp, 'local.properties'), 'sdk.dir=' + path.join(temp,
'..', 'SDK').replace(/\\/g, '/'));
+            android['framework'].install(frameworkElementChild, dummyplugin, temp, dummy_id,
{ platformVersion: '3.0.0' });
+
+            android.parseProjectFile(temp).write();
+            android.parseProjectFile(parentDir).write();
+
+            exec.reset();
+
+            var finalProjectProperties = fs.readFileSync(parentProjectPropsFile, 'utf8');
+            var libReference = '\nandroid.library.reference.1=' + path.join('..', '..', sdkLibRelativeDir).replace(/\\/g,
'/');
+            expect(finalProjectProperties).toMatch(libReference, 'Reference to library not
added');
+            // exec doesn't get called since sublibrary dir doesn't actually exist.
+            expect(exec).not.toHaveBeenCalled();
+
+            // Now test uninstall
+            android.purgeProjectFileCache(temp);
+            android.purgeProjectFileCache(parentDir);
+            android['framework'].uninstall(frameworkElementChild, temp, dummy_id, { platformVersion:
'3.0.0' });
+            android.parseProjectFile(temp).write();
+            android.parseProjectFile(parentDir).write();
+
+            finalProjectProperties = fs.readFileSync(parentProjectPropsFile, 'utf8');
+            expect(finalProjectProperties).not.toMatch(libReference, 'Reference to library
not removed');
+
+            android['framework'].uninstall(frameworkElement, temp, dummy_id, { platformVersion:
'3.0.0' });
+            android.parseProjectFile(temp).write();
+        });
     });
     describe('uninstallation', function() {
         beforeEach(function() {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/bc3e973c/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/AndroidManifest.xml
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/AndroidManifest.xml
b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/AndroidManifest.xml
new file mode 100644
index 0000000..3c9499c
--- /dev/null
+++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/AndroidManifest.xml
@@ -0,0 +1,5 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+  android:versionCode="1" package="com.test.somelib">
+    <uses-sdk android:minSdkVersion="9"/>
+    <application/>
+</manifest>

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/bc3e973c/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/libFile
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/libFile
b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/libFile
new file mode 100644
index 0000000..c79df8e
--- /dev/null
+++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/libFile
@@ -0,0 +1 @@
+libFile contents

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/bc3e973c/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/project.properties
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/project.properties
b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/project.properties
new file mode 100644
index 0000000..c4a5b63
--- /dev/null
+++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin-lib2/project.properties
@@ -0,0 +1 @@
+target=android-11

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/bc3e973c/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml
index b2d7f75..f656661 100644
--- a/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml
+++ b/cordova-lib/spec-plugman/plugins/org.test.plugins.dummyplugin/plugin.xml
@@ -51,6 +51,7 @@
         </config-file>
 
         <framework src="plugin-lib" custom="true" />
+        <framework src="plugin-lib2" custom="true" parent="plugin-lib" />
         <framework src="extras/android/support/v7/appcompat" />
         <framework src="extra.gradle" type="gradleReference" />
         <resource-file src="android-resource.xml" target="res/xml/dummy.xml" />

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/bc3e973c/cordova-lib/src/plugman/platforms/android.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/platforms/android.js b/cordova-lib/src/plugman/platforms/android.js
index 0949392..e59025c 100644
--- a/cordova-lib/src/plugman/platforms/android.js
+++ b/cordova-lib/src/plugman/platforms/android.js
@@ -122,7 +122,10 @@ module.exports = {
 
             events.emit('verbose', 'Installing Android library: ' + src);
             var parent = obj.parent;
-            var parentDir = parent ? path.resolve(project_dir, parent) : project_dir;
+            var parentDir = parent ?
+                    path.resolve(project_dir, getCustomSubprojectRelativeDir(plugin_id, project_dir,
parent)) :
+                    project_dir;
+
             var subDir;
             var type = obj.type;
 
@@ -157,7 +160,9 @@ module.exports = {
 
             events.emit('verbose', 'Uninstalling Android library: ' + src);
             var parent = obj.parent;
-            var parentDir = parent ? path.resolve(project_dir, parent) : project_dir;
+            var parentDir = parent ?
+                    path.resolve(project_dir, getCustomSubprojectRelativeDir(plugin_id, project_dir,
parent)) :
+                    project_dir;
             var subDir;
             var type = obj.type;
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/bc3e973c/cordova-lib/src/plugman/util/android-project.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/util/android-project.js b/cordova-lib/src/plugman/util/android-project.js
index 77908fb..fd62c79 100644
--- a/cordova-lib/src/plugman/util/android-project.js
+++ b/cordova-lib/src/plugman/util/android-project.js
@@ -118,7 +118,11 @@ AndroidProject.prototype = {
         for (var filename in this._propertiesEditors) {
             var editor = this._propertiesEditors[filename];
             if (editor.dirty) {
-                fs.writeFileSync(filename, editor.toString());
+                // Check for parent directory existence before attempting write 
+                // (when uninstalling a plugin its subprojects' directories are deleted)
+                if (fs.existsSync(path.dirname(filename))) {
+                    fs.writeFileSync(filename, editor.toString());
+                }
                 editor.dirty = false;
             }
         }


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


Mime
View raw message