Merge pull request #434 from infil00p/CB-13830

CB-13830: Add handlers for plugins that use non-Java source files
This commit is contained in:
Joe Bowser 2018-03-26 16:08:22 -07:00 committed by GitHub
commit 83686542b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 67 deletions

View File

@ -34,15 +34,7 @@ var handlers = {
// a later plugins release. This is for legacy plugins to work with Cordova.
if (options && options.android_studio === true) {
// If a Java file is using the new directory structure, don't penalize it
if (!obj.targetDir.includes('app/src/main')) {
if (obj.src.endsWith('.java')) {
dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
} else if (obj.src.endsWith('.xml')) {
// We are making a huge assumption here that XML files will be going to res/xml or values/xml
dest = path.join('app/src/main', obj.targetDir, path.basename(obj.src));
}
}
dest = studioPathRemap(obj);
}
if (options && options.force) {
@ -55,10 +47,16 @@ var handlers = {
var dest = path.join(obj.targetDir, path.basename(obj.src));
if (options && options.android_studio === true) {
dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
dest = studioPathRemap(obj);
}
// TODO: Add Koltin extension to uninstall, since they are handled like Java files
if (obj.src.endsWith('java')) {
deleteJava(project.projectDir, dest);
} else {
// Just remove the file, not the whole parent directory
removeFile(project.projectDir, dest);
}
}
},
'lib-file': {
@ -318,3 +316,16 @@ function removeFileAndParents (baseDir, destFile, stopper) {
function generateAttributeError (attribute, element, id) {
return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
}
function studioPathRemap (obj) {
// If a Java file is using the new directory structure, don't penalize it
if (!obj.targetDir.includes('app/src/main')) {
if (obj.src.endsWith('.java')) {
return path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
} else if (obj.src.endsWith('.xml')) {
// We are making a huge assumption here that XML files will be going to res/xml or values/xml
return path.join('app/src/main', obj.targetDir, path.basename(obj.src));
}
}
}