From 8586d4a7ba4599db190616fcc5eb59e64623a499 Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Thu, 22 Nov 2018 08:59:33 -0500 Subject: [PATCH] Resolve issue with plugin target-dir="app*" subdirs (#572) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (subdirectories) such as "appco", with unit tests to verify Needed for @katzer plugins that use de/appplant subdirectory, for example: * cordova-plugin-local-notifications * cordova-plugin-badge * cordova-plugin-background-mode Also needed for cordova-plugin-inappbrowser Co-authored-by: Christopher J. Brody Co-authored-by: Julio César Co-authored-by: Jan Piotrowski --- bin/templates/cordova/lib/pluginHandlers.js | 2 +- .../fixtures/org.test.plugins.dummyplugin/plugin.xml | 2 ++ spec/unit/pluginHandlers/handlers.spec.js | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/templates/cordova/lib/pluginHandlers.js b/bin/templates/cordova/lib/pluginHandlers.js index aaee3b3ee7..f5be4b49dc 100644 --- a/bin/templates/cordova/lib/pluginHandlers.js +++ b/bin/templates/cordova/lib/pluginHandlers.js @@ -320,7 +320,7 @@ function generateAttributeError (attribute, element, id) { function getInstallDestination (obj) { var APP_MAIN_PREFIX = 'app/src/main'; - if (obj.targetDir.includes('app')) { + if (obj.targetDir.startsWith('app')) { // If any source file is using the new app directory structure, // don't penalize it return path.join(obj.targetDir, path.basename(obj.src)); diff --git a/spec/fixtures/org.test.plugins.dummyplugin/plugin.xml b/spec/fixtures/org.test.plugins.dummyplugin/plugin.xml index 4e2ebcc6c6..9bc99d21dd 100644 --- a/spec/fixtures/org.test.plugins.dummyplugin/plugin.xml +++ b/spec/fixtures/org.test.plugins.dummyplugin/plugin.xml @@ -82,6 +82,8 @@ + diff --git a/spec/unit/pluginHandlers/handlers.spec.js b/spec/unit/pluginHandlers/handlers.spec.js index 97e77dcefe..dc4043457f 100644 --- a/spec/unit/pluginHandlers/handlers.spec.js +++ b/spec/unit/pluginHandlers/handlers.spec.js @@ -169,6 +169,12 @@ describe('android project handler', function () { 'src/android/jniLibs/x86/libnative.so', temp, path.join('app/src/main/jniLibs/x86/libnative.so'), false); }); + + it('Test#006j : should allow installing sources with target-dir that includes "app"', function () { + android['source-file'].install(valid_source[10], dummyPluginInfo, dummyProject, {android_studio: true}); + expect(copyFileSpy) + .toHaveBeenCalledWith(dummyplugin, 'src/android/DummyPlugin2.java', temp, path.join('app/src/main/java/com/appco/DummyPlugin2.java'), false); + }); }); describe('of elements', function () { @@ -378,6 +384,12 @@ describe('android project handler', function () { android['source-file'].uninstall(valid_source[9], dummyPluginInfo, dummyProject, {android_studio: true}); expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/jniLibs/x86/libnative.so')); }); + + it('Test#019j : should remove stuff by calling common.deleteJava for Android Studio projects, with target-dir that includes "app"', function () { + android['source-file'].install(valid_source[10], dummyPluginInfo, dummyProject, {android_studio: true}); + android['source-file'].uninstall(valid_source[10], dummyPluginInfo, dummyProject, {android_studio: true}); + expect(deleteJavaSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/java/com/appco/DummyPlugin2.java')); + }); }); describe('of elements', function () {