mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
Rewrite install dir resolution for legacy plugins (#589)
* Improve target-dir restriction for detecting new android project structure used in plugin.xml. (#575) * Clarify old source-file declaration way from the new one and improve ambiguous code. * Better check `src/main` forms. * Replace path search with RegExp vars. * Fix RegExp in order to match `/` or `EOL`. * Remove template strings for NodeJS 4 support (wanted in case we port these changes to `7.1.x` at some point). * Add pointer to deprecation plan in GH-580.
This commit is contained in:
parent
ef2434188e
commit
8a4ae311ce
32
bin/templates/cordova/lib/pluginHandlers.js
vendored
32
bin/templates/cordova/lib/pluginHandlers.js
vendored
@ -294,27 +294,41 @@ function generateAttributeError (attribute, element, id) {
|
||||
|
||||
function getInstallDestination (obj) {
|
||||
var APP_MAIN_PREFIX = 'app/src/main';
|
||||
var PATH_SEPARATOR = '/';
|
||||
|
||||
if (obj.targetDir.startsWith('app')) {
|
||||
var PATH_SEP_MATCH = '\\' + PATH_SEPARATOR;
|
||||
var PATH_SEP_OR_EOL_MATCH = '(\\' + PATH_SEPARATOR + '|$)';
|
||||
|
||||
var appReg = new RegExp('^app' + PATH_SEP_OR_EOL_MATCH);
|
||||
var libsReg = new RegExp('^libs' + PATH_SEP_OR_EOL_MATCH);
|
||||
var srcReg = new RegExp('^src' + PATH_SEP_OR_EOL_MATCH);
|
||||
var srcMainReg = new RegExp('^src' + PATH_SEP_MATCH + 'main' + PATH_SEP_OR_EOL_MATCH);
|
||||
|
||||
if (appReg.test(obj.targetDir)) {
|
||||
// If any source file is using the new app directory structure,
|
||||
// don't penalize it
|
||||
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 {
|
||||
// Plugin using deprecated target directory structure (GH-580)
|
||||
if (obj.src.endsWith('.java')) {
|
||||
return path.join(APP_MAIN_PREFIX, 'java', obj.targetDir.replace(srcReg, ''),
|
||||
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')) {
|
||||
return path.join(APP_MAIN_PREFIX, 'aidl', obj.targetDir.replace(srcReg, ''),
|
||||
path.basename(obj.src));
|
||||
} else if (libsReg.test(obj.targetDir)) {
|
||||
if (obj.src.endsWith('.so')) {
|
||||
return path.join(APP_MAIN_PREFIX, 'jniLibs', obj.targetDir.substring(5), path.basename(obj.src));
|
||||
return path.join(APP_MAIN_PREFIX, 'jniLibs', obj.targetDir.replace(libsReg, ''),
|
||||
path.basename(obj.src));
|
||||
} else {
|
||||
return path.join('app', obj.targetDir, path.basename(obj.src));
|
||||
}
|
||||
} else if (obj.targetDir.includes('src/main')) {
|
||||
} else if (srcMainReg.test(obj.targetDir)) {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,6 +84,8 @@
|
||||
<source-file src="src/android/jniLibs/x86/libnative.so" target-dir="libs/x86" />
|
||||
<source-file src="src/android/DummyPlugin2.java"
|
||||
target-dir="src/com/appco" />
|
||||
<source-file src="src/android/DummyPlugin2.java"
|
||||
target-dir="appco/src" />
|
||||
<lib-file src="src/android/TestLib.jar" />
|
||||
</platform>
|
||||
</plugin>
|
||||
|
@ -169,6 +169,12 @@ describe('android project handler', function () {
|
||||
expect(copyFileSpy)
|
||||
.toHaveBeenCalledWith(dummyplugin, 'src/android/DummyPlugin2.java', temp, path.join('app/src/main/java/com/appco/DummyPlugin2.java'), false);
|
||||
});
|
||||
|
||||
it('Test#006k : should allow installing sources with target-dir that includes "app" in its first directory', function () {
|
||||
android['source-file'].install(valid_source[11], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||
expect(copyFileSpy)
|
||||
.toHaveBeenCalledWith(dummyplugin, 'src/android/DummyPlugin2.java', temp, path.join('app/src/main/java/appco/src/DummyPlugin2.java'), false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('of <framework> elements', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user