From b9f7e6fdf5e839dba8d581a7e196b946b619fb4b Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Wed, 14 Nov 2018 11:42:21 -0500 Subject: [PATCH] GH-547 Fix for old plugins with non-Java sources (source-file entries) including aidl, aar, jar, and so files --- bin/templates/cordova/lib/pluginHandlers.js | 12 +++++++ spec/unit/pluginHandlers/handlers.spec.js | 40 +++++++++------------ 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/bin/templates/cordova/lib/pluginHandlers.js b/bin/templates/cordova/lib/pluginHandlers.js index 2ef18c289c..f4f411c31b 100644 --- a/bin/templates/cordova/lib/pluginHandlers.js +++ b/bin/templates/cordova/lib/pluginHandlers.js @@ -301,6 +301,18 @@ function getInstallDestination (obj) { return path.join(obj.targetDir, path.basename(obj.src)); } else if (obj.src.endsWith('.java')) { return path.join(APP_MAIN_PREFIX, 'java', obj.targetDir.substring(4), path.basename(obj.src)); + } else if (obj.src.endsWith('.aidl')) { + return path.join(APP_MAIN_PREFIX, 'aidl', obj.targetDir.substring(4), path.basename(obj.src)); + } else if (obj.targetDir.includes('libs')) { + if (obj.src.endsWith('.so')) { + // THANKS FOR GUIDANCE: + // https://github.com/dpa99c/cordova-plugin-hello-c/blob/master/plugin.xml#L39-L42 + return path.join(APP_MAIN_PREFIX, 'jniLibs', obj.targetDir.substring(5), path.basename(obj.src)); + } else { + return path.join('app', obj.targetDir, path.basename(obj.src)); + } + } else if (obj.targetDir.includes('src/main')) { + return path.join('app', obj.targetDir, path.basename(obj.src)); } else { // For all other source files not using the new app directory structure, // add 'app/src/main' to the targetDir diff --git a/spec/unit/pluginHandlers/handlers.spec.js b/spec/unit/pluginHandlers/handlers.spec.js index 0f19d9a329..20f5e6e93b 100644 --- a/spec/unit/pluginHandlers/handlers.spec.js +++ b/spec/unit/pluginHandlers/handlers.spec.js @@ -136,36 +136,32 @@ describe('android project handler', function () { path.join('app/src/main/res/values/other.extension'), false); }); - it('Test#006f : should allow installing aidl file from sources with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#006f : should allow installing aidl file from sources with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[6], dummyPluginInfo, dummyProject, {android_studio: true}); expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/myapi.aidl', temp, - path.join('app/src/main/src/com/mytest/myapi.aidl'), false); + path.join('app/src/main/aidl/com/mytest/myapi.aidl'), false); }); - it('Test#006g : should allow installing aar lib file from sources with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#006g : should allow installing aar lib file from sources with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[7], dummyPluginInfo, dummyProject, {android_studio: true}); expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/testaar2.aar', temp, - path.join('app/src/main/libs/testaar2.aar'), false); + path.join('app/libs/testaar2.aar'), false); }); - it('Test#006h : should allow installing jar lib file from sources with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#006h : should allow installing jar lib file from sources with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[8], dummyPluginInfo, dummyProject, {android_studio: true}); expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/testjar2.jar', temp, - path.join('app/src/main/libs/testjar2.jar'), false); + path.join('app/libs/testjar2.jar'), false); }); - it('Test#006i : should allow installing .so lib file from sources with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#006i : should allow installing .so lib file from sources with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[9], dummyPluginInfo, dummyProject, {android_studio: true}); expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/jniLibs/x86/libnative.so', temp, - path.join('app/src/main/libs/x86/libnative.so'), false); + path.join('app/src/main/jniLibs/x86/libnative.so'), false); }); }); @@ -353,32 +349,28 @@ describe('android project handler', function () { expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/res/values/other.extension')); }); - it('Test#019f : should remove stuff by calling common.removeFile for Android Studio projects, of aidl with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#019f : should remove stuff by calling common.removeFile for Android Studio projects, of aidl with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[6], dummyPluginInfo, dummyProject, {android_studio: true}); android['source-file'].uninstall(valid_source[6], dummyPluginInfo, dummyProject, {android_studio: true}); - expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/src/com/mytest/myapi.aidl')); + expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/aidl/com/mytest/myapi.aidl')); }); - it('Test#019g : should remove stuff by calling common.removeFile for Android Studio projects, of aar with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#019g : should remove stuff by calling common.removeFile for Android Studio projects, of aar with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[7], dummyPluginInfo, dummyProject, {android_studio: true}); android['source-file'].uninstall(valid_source[7], dummyPluginInfo, dummyProject, {android_studio: true}); - expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/libs/testaar2.aar')); + expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/testaar2.aar')); }); - it('Test#019h : should remove stuff by calling common.removeFile for Android Studio projects, of jar with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#019h : should remove stuff by calling common.removeFile for Android Studio projects, of jar with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[8], dummyPluginInfo, dummyProject, {android_studio: true}); android['source-file'].uninstall(valid_source[8], dummyPluginInfo, dummyProject, {android_studio: true}); - expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/libs/testjar2.jar')); + expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/testjar2.jar')); }); - it('Test#019i : should remove stuff by calling common.removeFile for Android Studio projects, of .so lib file with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#019i : should remove stuff by calling common.removeFile for Android Studio projects, of .so lib file with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[9], dummyPluginInfo, dummyProject, {android_studio: true}); android['source-file'].uninstall(valid_source[9], dummyPluginInfo, dummyProject, {android_studio: true}); - expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/libs/x86/libnative.so')); + expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/jniLibs/x86/libnative.so')); }); });