mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 03:53:09 +08:00
Merge pull request #542 from brodybits/gh-540-hotfix
Resolve GH-539 & GH-540 on master
This commit is contained in:
commit
576ad183e7
14
bin/templates/cordova/lib/pluginHandlers.js
vendored
14
bin/templates/cordova/lib/pluginHandlers.js
vendored
@ -26,7 +26,7 @@ var handlers = {
|
|||||||
if (!obj.src) throw new CordovaError(generateAttributeError('src', 'source-file', plugin.id));
|
if (!obj.src) throw new CordovaError(generateAttributeError('src', 'source-file', plugin.id));
|
||||||
if (!obj.targetDir) throw new CordovaError(generateAttributeError('target-dir', 'source-file', plugin.id));
|
if (!obj.targetDir) throw new CordovaError(generateAttributeError('target-dir', 'source-file', plugin.id));
|
||||||
|
|
||||||
var dest = studioPathRemap(obj);
|
var dest = getInstallDestination(obj);
|
||||||
|
|
||||||
if (options && options.force) {
|
if (options && options.force) {
|
||||||
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
copyFile(plugin.dir, obj.src, project.projectDir, dest, !!(options && options.link));
|
||||||
@ -35,7 +35,7 @@ var handlers = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
uninstall: function (obj, plugin, project, options) {
|
uninstall: function (obj, plugin, project, options) {
|
||||||
var dest = studioPathRemap(obj);
|
var dest = getInstallDestination(obj);
|
||||||
|
|
||||||
// TODO: Add Koltin extension to uninstall, since they are handled like Java files
|
// TODO: Add Koltin extension to uninstall, since they are handled like Java files
|
||||||
if (obj.src.endsWith('java')) {
|
if (obj.src.endsWith('java')) {
|
||||||
@ -292,9 +292,15 @@ function generateAttributeError (attribute, element, id) {
|
|||||||
return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
|
return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getInstallDestination (obj) {
|
||||||
|
return studioPathRemap(obj) ||
|
||||||
|
path.join(obj.targetDir, path.basename(obj.src));
|
||||||
|
}
|
||||||
|
|
||||||
function studioPathRemap (obj) {
|
function studioPathRemap (obj) {
|
||||||
// If a Java file is using the new directory structure, don't penalize it
|
// If any source file is using the app new directory structure,
|
||||||
if (!obj.targetDir.includes('app/src/main')) {
|
// don't penalize it
|
||||||
|
if (!obj.targetDir.includes('app')) {
|
||||||
if (obj.src.endsWith('.java')) {
|
if (obj.src.endsWith('.java')) {
|
||||||
return path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
return path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
||||||
} else {
|
} else {
|
||||||
|
@ -70,6 +70,12 @@
|
|||||||
|
|
||||||
<source-file src="src/android/DummyPlugin.java"
|
<source-file src="src/android/DummyPlugin.java"
|
||||||
target-dir="src/com/phonegap/plugins/dummyplugin" />
|
target-dir="src/com/phonegap/plugins/dummyplugin" />
|
||||||
|
<source-file src="src/android/DummyPlugin2.java"
|
||||||
|
target-dir="app/src/main/src/com/phonegap/plugins/dummyplugin" />
|
||||||
|
<source-file src="src/android/TestLib.jar"
|
||||||
|
target-dir="app/libs" />
|
||||||
|
<source-file src="src/android/TestAar.aar"
|
||||||
|
target-dir="app/libs" />
|
||||||
<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/DummyPlugin2.java
vendored
Normal file
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/DummyPlugin2.java
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
./org.test.plugins.dummyplugin/src/android/DummyPlugin2.java
|
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/TestAar.aar
vendored
Normal file
1
spec/fixtures/org.test.plugins.dummyplugin/src/android/TestAar.aar
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
./org.test.plugins.dummyplugin/src/android/TestAar.aar
|
@ -102,6 +102,25 @@ describe('android project handler', function () {
|
|||||||
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject);
|
android['source-file'].install(valid_source[0], dummyPluginInfo, dummyProject);
|
||||||
}).toThrow(new Error('"' + target + '" already exists!'));
|
}).toThrow(new Error('"' + target + '" already exists!'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Test#007 : should allow installing sources using proper path', function () {
|
||||||
|
android['source-file'].install(valid_source[1], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
expect(copyFileSpy)
|
||||||
|
.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#007a : should allow installing lib file from sources using proper path', function () {
|
||||||
|
android['source-file'].install(valid_source[2], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
expect(copyFileSpy)
|
||||||
|
.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 () {
|
||||||
|
android['source-file'].install(valid_source[3], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
expect(copyFileSpy)
|
||||||
|
.toHaveBeenCalledWith(dummyplugin, 'src/android/TestAar.aar', temp, path.join('app/libs/TestAar.aar'), false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('of <framework> elements', function () {
|
describe('of <framework> elements', function () {
|
||||||
@ -251,6 +270,10 @@ 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);
|
||||||
@ -259,6 +282,30 @@ describe('android project handler', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 () {
|
||||||
|
android['source-file'].install(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'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('of <source-file> element, with JAR in specific app target-dir', 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'].uninstall(valid_source[2], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
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.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'].uninstall(valid_source[3], dummyPluginInfo, dummyProject, {android_studio: true});
|
||||||
|
expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/TestAar.aar'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('of <framework> elements', function () {
|
describe('of <framework> elements', function () {
|
||||||
|
|
||||||
var someString = jasmine.any(String);
|
var someString = jasmine.any(String);
|
||||||
|
Loading…
Reference in New Issue
Block a user