mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 03:53:09 +08:00
Merge pull request #550 from brodybits/gh-547-bugfix
Fix for old plugins with non-Java sources (GH-547)
This commit is contained in:
commit
21ae48eada
30
bin/templates/cordova/lib/pluginHandlers.js
vendored
30
bin/templates/cordova/lib/pluginHandlers.js
vendored
@ -293,20 +293,28 @@ function generateAttributeError (attribute, element, id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getInstallDestination (obj) {
|
function getInstallDestination (obj) {
|
||||||
return studioPathRemap(obj) ||
|
var APP_MAIN_PREFIX = 'app/src/main';
|
||||||
path.join(obj.targetDir, path.basename(obj.src));
|
|
||||||
}
|
|
||||||
|
|
||||||
function studioPathRemap (obj) {
|
if (obj.targetDir.includes('app')) {
|
||||||
// If any source file is using the app new directory structure,
|
// If any source file is using the new app directory structure,
|
||||||
// don't penalize it
|
// don't penalize it
|
||||||
if (!obj.targetDir.includes('app')) {
|
return path.join(obj.targetDir, path.basename(obj.src));
|
||||||
if (obj.src.endsWith('.java')) {
|
} else if (obj.src.endsWith('.java')) {
|
||||||
return path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
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')) {
|
||||||
|
return path.join(APP_MAIN_PREFIX, 'jniLibs', obj.targetDir.substring(5), path.basename(obj.src));
|
||||||
} else {
|
} else {
|
||||||
// For all other files, add 'app/src/main' to the targetDir if it didn't have it already
|
return path.join('app', obj.targetDir, path.basename(obj.src));
|
||||||
return path.join('app/src/main', 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
|
||||||
|
return path.join(APP_MAIN_PREFIX, obj.targetDir, path.basename(obj.src));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,12 @@
|
|||||||
target-dir="app/libs" />
|
target-dir="app/libs" />
|
||||||
<source-file src="src/android/TestAar.aar"
|
<source-file src="src/android/TestAar.aar"
|
||||||
target-dir="app/libs" />
|
target-dir="app/libs" />
|
||||||
|
<source-file src="src/android/mysettings.xml" target-dir="res/xml" />
|
||||||
|
<source-file src="src/android/other.extension" target-dir="res/values" />
|
||||||
|
<source-file src="src/android/myapi.aidl" target-dir="src/com/mytest" />
|
||||||
|
<source-file src="src/android/testaar2.aar" target-dir="libs" />
|
||||||
|
<source-file src="src/android/testjar2.jar" target-dir="libs" />
|
||||||
|
<source-file src="src/android/jniLibs/x86/libnative.so" target-dir="libs/x86" />
|
||||||
<lib-file src="src/android/TestLib.jar" />
|
<lib-file src="src/android/TestLib.jar" />
|
||||||
</platform>
|
</platform>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/jniLibs/x86/libnative.so
vendored
Normal file
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/jniLibs/x86/libnative.so
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
dummy
|
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/myapi.aidl
vendored
Normal file
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/myapi.aidl
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
dummy
|
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/mysettings.xml
vendored
Normal file
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/mysettings.xml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
dummy
|
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/other.extension
vendored
Normal file
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/other.extension
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
dummy
|
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/testaar2.aar
vendored
Normal file
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/testaar2.aar
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
dummy
|
BIN
spec/fixtures/org.test.plugins.dummyplugin/src/android/testjar2.jar
vendored
Normal file
BIN
spec/fixtures/org.test.plugins.dummyplugin/src/android/testjar2.jar
vendored
Normal file
Binary file not shown.
@ -103,24 +103,66 @@ describe('android project handler', function () {
|
|||||||
}).toThrow(new Error('"' + target + '" already exists!'));
|
}).toThrow(new Error('"' + target + '" already exists!'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test#007 : should allow installing sources using proper path', function () {
|
// TODO: renumber these tests and other tests below
|
||||||
|
it('Test#00a6 : should allow installing sources with new app target-dir scheme', function () {
|
||||||
android['source-file'].install(valid_source[1], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].install(valid_source[1], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
expect(copyFileSpy)
|
expect(copyFileSpy)
|
||||||
.toHaveBeenCalledWith(dummyplugin, 'src/android/DummyPlugin2.java', temp, path.join('app/src/main/src/com/phonegap/plugins/dummyplugin/DummyPlugin2.java'), false);
|
.toHaveBeenCalledWith(dummyplugin, 'src/android/DummyPlugin2.java', temp, path.join('app/src/main/src/com/phonegap/plugins/dummyplugin/DummyPlugin2.java'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: renumber these tests and other tests below
|
it('Test#006b : should allow installing jar lib file from sources with new app target-dir scheme', function () {
|
||||||
it('Test#007a : should allow installing lib file from sources using proper path', function () {
|
|
||||||
android['source-file'].install(valid_source[2], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].install(valid_source[2], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
expect(copyFileSpy)
|
expect(copyFileSpy)
|
||||||
.toHaveBeenCalledWith(dummyplugin, 'src/android/TestLib.jar', temp, path.join('app/libs/TestLib.jar'), false);
|
.toHaveBeenCalledWith(dummyplugin, 'src/android/TestLib.jar', temp, path.join('app/libs/TestLib.jar'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test#007b : should allow installing aar file from sources using proper path', function () {
|
it('Test#006c : should allow installing aar lib file from sources with new app target-dir scheme', function () {
|
||||||
android['source-file'].install(valid_source[3], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].install(valid_source[3], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
expect(copyFileSpy)
|
expect(copyFileSpy)
|
||||||
.toHaveBeenCalledWith(dummyplugin, 'src/android/TestAar.aar', temp, path.join('app/libs/TestAar.aar'), false);
|
.toHaveBeenCalledWith(dummyplugin, 'src/android/TestAar.aar', temp, path.join('app/libs/TestAar.aar'), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Test#006d : should allow installing xml file from sources with old target-dir scheme', function () {
|
||||||
|
android['source-file'].install(valid_source[4], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin,
|
||||||
|
'src/android/mysettings.xml', temp,
|
||||||
|
path.join('app/src/main/res/xml/mysettings.xml'), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test#006e : should allow installing file with other extension from sources with old target-dir scheme', function () {
|
||||||
|
android['source-file'].install(valid_source[5], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin,
|
||||||
|
'src/android/other.extension', temp,
|
||||||
|
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 (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/aidl/com/mytest/myapi.aidl'), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
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/libs/testaar2.aar'), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
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/libs/testjar2.jar'), false);
|
||||||
|
});
|
||||||
|
|
||||||
|
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/jniLibs/x86/libnative.so'), false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('of <framework> elements', function () {
|
describe('of <framework> elements', function () {
|
||||||
@ -270,40 +312,66 @@ describe('android project handler', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// - merge tests of <source-file> elements into single describe block
|
|
||||||
// (with proper beforeEach/afterEach)
|
|
||||||
// - renumber the tests after Test#019
|
|
||||||
describe('of <source-file> elements', function () {
|
describe('of <source-file> elements', function () {
|
||||||
it('Test#019 : should remove stuff by calling common.deleteJava for Android Studio projects', function () {
|
it('Test#019 : should remove stuff by calling common.deleteJava for Android Studio projects', function () {
|
||||||
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject);
|
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject);
|
||||||
android['source-file'].uninstall(valid_source[0], dummyPluginInfo, dummyProject);
|
android['source-file'].uninstall(valid_source[0], dummyPluginInfo, dummyProject);
|
||||||
expect(deleteJavaSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/java/com/phonegap/plugins/dummyplugin/DummyPlugin.java'));
|
expect(deleteJavaSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/java/com/phonegap/plugins/dummyplugin/DummyPlugin.java'));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('of <source-file> element, with specific app target-dir', function () {
|
|
||||||
it('Test#019a : should remove stuff by calling common.deleteJava for Android Studio projects, with specific app target-dir', function () {
|
it('Test#019a : should remove stuff by calling common.deleteJava for Android Studio projects, with specific app target-dir', function () {
|
||||||
android['source-file'].install(valid_source[1], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].install(valid_source[1], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
android['source-file'].uninstall(valid_source[1], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].uninstall(valid_source[1], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
expect(deleteJavaSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/src/com/phonegap/plugins/dummyplugin/DummyPlugin2.java'));
|
expect(deleteJavaSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/src/com/phonegap/plugins/dummyplugin/DummyPlugin2.java'));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('of <source-file> element, with JAR in specific app target-dir', function () {
|
it('Test#019b : should remove stuff by calling common.removeFile for Android Studio projects, of jar with new app target-dir scheme', function () {
|
||||||
it('Test#019b : should remove stuff by calling common.deleteJava for Android Studio projects, with JAR into specific app target-dir', function () {
|
|
||||||
android['source-file'].install(valid_source[2], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].install(valid_source[2], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
android['source-file'].uninstall(valid_source[2], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].uninstall(valid_source[2], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/TestLib.jar'));
|
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/TestLib.jar'));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('of <source-file> element, with AAR in specific app target-dir', function () {
|
it('Test#019c : should remove stuff by calling common.removeFile for Android Studio projects, of aar with new app target-dir scheme', function () {
|
||||||
it('Test#019c : should remove stuff by calling common.deleteJava for Android Studio projects, with JAR into specific app target-dir', function () {
|
|
||||||
android['source-file'].install(valid_source[3], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].install(valid_source[3], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
android['source-file'].uninstall(valid_source[3], dummyPluginInfo, dummyProject, {android_studio: true});
|
android['source-file'].uninstall(valid_source[3], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/TestAar.aar'));
|
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/TestAar.aar'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Test#019d : should remove stuff by calling common.removeFile for Android Studio projects, of xml with old target-dir scheme', function () {
|
||||||
|
android['source-file'].install(valid_source[4], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
android['source-file'].uninstall(valid_source[4], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/res/xml/mysettings.xml'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test#019e : should remove stuff by calling common.removeFile for Android Studio projects, of file with other extension with old target-dir scheme', function () {
|
||||||
|
android['source-file'].install(valid_source[5], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
android['source-file'].uninstall(valid_source[5], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
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 (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/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 (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/libs/testaar2.aar'));
|
||||||
|
});
|
||||||
|
|
||||||
|
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/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 (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/jniLibs/x86/libnative.so'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('of <framework> elements', function () {
|
describe('of <framework> elements', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user