2016-02-29 23:49:17 +08:00
/ * *
Licensed to the Apache Software Foundation ( ASF ) under one
or more contributor license agreements . See the NOTICE file
distributed with this work for additional information
regarding copyright ownership . The ASF licenses this file
to you under the Apache License , Version 2.0 ( the
"License" ) ; you may not use this file except in compliance
with the License . You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing ,
software distributed under the License is distributed on an
"AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND , either express or implied . See the License for the
specific language governing permissions and limitations
under the License .
* /
2022-04-18 09:39:54 +08:00
const rewire = require ( 'rewire' ) ;
const common = rewire ( '../../../lib/pluginHandlers' ) ;
const android = common . _ _get _ _ ( 'handlers' ) ;
const path = require ( 'path' ) ;
const fs = require ( 'fs-extra' ) ;
const os = require ( 'os' ) ;
const temp = path . join ( os . tmpdir ( ) , 'plugman' ) ;
const plugins _dir = path . join ( temp , 'cordova/plugins' ) ;
const dummyplugin = path . join ( _ _dirname , '../../fixtures/org.test.plugins.dummyplugin' ) ;
const faultyplugin = path . join ( _ _dirname , '../../fixtures/org.test.plugins.faultyplugin' ) ;
const android _studio _project = path . join ( _ _dirname , '../../fixtures/android_studio_project' ) ;
const PluginInfo = require ( 'cordova-common' ) . PluginInfo ;
const AndroidProject = require ( '../../../lib/AndroidProject' ) ;
const dummyPluginInfo = new PluginInfo ( dummyplugin ) ;
const valid _source = dummyPluginInfo . getSourceFiles ( 'android' ) ;
const valid _resources = dummyPluginInfo . getResourceFiles ( 'android' ) ;
const valid _libs = dummyPluginInfo . getLibFiles ( 'android' ) ;
const faultyPluginInfo = new PluginInfo ( faultyplugin ) ;
const invalid _source = faultyPluginInfo . getSourceFiles ( 'android' ) ;
2016-02-29 23:49:17 +08:00
2017-06-14 02:42:20 +08:00
describe ( 'android project handler' , function ( ) {
describe ( 'installation' , function ( ) {
2022-04-18 09:39:54 +08:00
const copyFileOrig = common . _ _get _ _ ( 'copyFile' ) ;
const copyFileSpy = jasmine . createSpy ( 'copyFile' ) ;
let dummyProject ;
2016-02-29 23:49:17 +08:00
2017-06-14 02:42:20 +08:00
beforeEach ( function ( ) {
2020-01-29 09:12:55 +08:00
fs . ensureDirSync ( temp ) ;
2016-02-29 23:49:17 +08:00
dummyProject = AndroidProject . getProjectFile ( temp ) ;
2017-01-04 03:02:48 +08:00
copyFileSpy . calls . reset ( ) ;
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'copyFile' , copyFileSpy ) ;
} ) ;
2017-06-14 02:42:20 +08:00
afterEach ( function ( ) {
2020-01-29 09:12:55 +08:00
fs . removeSync ( temp ) ;
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'copyFile' , copyFileOrig ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <lib-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#001 : should copy files for Android Studio projects' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'lib-file' ] . install ( valid _libs [ 0 ] , dummyPluginInfo , dummyProject ) ;
2016-09-17 06:41:20 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin , 'src/android/TestLib.jar' , temp , path . join ( 'app' , 'libs' , 'TestLib.jar' ) , false ) ;
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <resource-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#002 : should copy files to the correct location on an Android Studio project' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'resource-file' ] . install ( valid _resources [ 0 ] , dummyPluginInfo , dummyProject ) ;
2018-04-18 19:16:54 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin , 'android-resource.xml' , temp , path . join ( 'app' , 'src' , 'main' , 'res' , 'xml' , 'dummy.xml' ) , false ) ;
2016-02-29 23:49:17 +08:00
} ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <source-file> elements' , function ( ) {
beforeEach ( function ( ) {
2020-01-29 09:12:55 +08:00
fs . copySync ( android _studio _project , temp ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#003 : should copy stuff from one location to another by calling common.copyFile' , function ( ) {
2016-02-29 23:49:17 +08:00
android [ 'source-file' ] . install ( valid _source [ 0 ] , dummyPluginInfo , dummyProject ) ;
expect ( copyFileSpy )
2018-09-06 10:06:18 +08:00
. toHaveBeenCalledWith ( dummyplugin , 'src/android/DummyPlugin.java' , temp , path . join ( 'app' , 'src' , 'main' , 'java' , 'com' , 'phonegap' , 'plugins' , 'dummyplugin' , 'DummyPlugin.java' ) , false ) ;
2016-09-17 06:41:20 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#005 : should throw if source file cannot be found' , function ( ) {
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'copyFile' , copyFileOrig ) ;
2017-06-14 02:42:20 +08:00
expect ( function ( ) {
2016-02-29 23:49:17 +08:00
android [ 'source-file' ] . install ( invalid _source [ 0 ] , faultyPluginInfo , dummyProject ) ;
2017-01-04 03:02:48 +08:00
} ) . toThrow ( new Error ( '"' + path . resolve ( faultyplugin , 'src/android/NotHere.java' ) + '" not found!' ) ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#006 : should throw if target file already exists' , function ( ) {
2016-02-29 23:49:17 +08:00
// write out a file
2018-09-06 10:06:18 +08:00
let target = path . resolve ( temp , 'app' , 'src' , 'main' , 'java' , 'com' , 'phonegap' , 'plugins' , 'dummyplugin' ) ;
2020-01-29 09:12:55 +08:00
fs . ensureDirSync ( target ) ;
2016-02-29 23:49:17 +08:00
target = path . join ( target , 'DummyPlugin.java' ) ;
fs . writeFileSync ( target , 'some bs' , 'utf-8' ) ;
2017-06-14 02:42:20 +08:00
expect ( function ( ) {
2016-02-29 23:49:17 +08:00
android [ 'source-file' ] . install ( valid _source [ 0 ] , dummyPluginInfo , dummyProject ) ;
2017-06-14 02:42:20 +08:00
} ) . toThrow ( new Error ( '"' + target + '" already exists!' ) ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-11-09 02:23:29 +08:00
2018-11-13 10:42:31 +08:00
// TODO: renumber these tests and other tests below
it ( 'Test#00a6 : should allow installing sources with new app target-dir scheme' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 1 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-09 02:23:29 +08:00
expect ( copyFileSpy )
. toHaveBeenCalledWith ( dummyplugin , 'src/android/DummyPlugin2.java' , temp , path . join ( 'app/src/main/src/com/phonegap/plugins/dummyplugin/DummyPlugin2.java' ) , false ) ;
} ) ;
2018-11-10 03:43:47 +08:00
2018-11-13 10:42:31 +08:00
it ( 'Test#006b : should allow installing jar lib file from sources with new app target-dir scheme' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 2 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-10 03:43:47 +08:00
expect ( copyFileSpy )
. toHaveBeenCalledWith ( dummyplugin , 'src/android/TestLib.jar' , temp , path . join ( 'app/libs/TestLib.jar' ) , false ) ;
} ) ;
2018-11-13 10:42:31 +08:00
it ( 'Test#006c : should allow installing aar lib file from sources with new app target-dir scheme' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 3 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-10 03:43:47 +08:00
expect ( copyFileSpy )
. toHaveBeenCalledWith ( dummyplugin , 'src/android/TestAar.aar' , temp , path . join ( 'app/libs/TestAar.aar' ) , false ) ;
} ) ;
2018-11-13 10:50:20 +08:00
it ( 'Test#006d : should allow installing xml file from sources with old target-dir scheme' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 4 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-13 10:50:20 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/mysettings.xml' , temp ,
path . join ( 'app/src/main/res/xml/mysettings.xml' ) , false ) ;
} ) ;
2018-11-13 11:01:13 +08:00
it ( 'Test#006e : should allow installing file with other extension from sources with old target-dir scheme' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 5 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-13 11:01:13 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/other.extension' , temp ,
path . join ( 'app/src/main/res/values/other.extension' ) , false ) ;
} ) ;
2018-11-14 02:06:48 +08:00
2018-11-15 02:19:58 +08:00
it ( 'Test#006f : should allow installing aidl file from sources with old target-dir scheme (GH-547)' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 6 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-14 02:06:48 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/myapi.aidl' , temp ,
2018-11-15 02:19:58 +08:00
path . join ( 'app/src/main/aidl/com/mytest/myapi.aidl' ) , false ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#006g : should allow installing aar lib file from sources with old target-dir scheme (GH-547)' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 7 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-14 02:06:48 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/testaar2.aar' , temp ,
2018-11-15 02:19:58 +08:00
path . join ( 'app/libs/testaar2.aar' ) , false ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#006h : should allow installing jar lib file from sources with old target-dir scheme (GH-547)' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 8 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-14 02:06:48 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/testjar2.jar' , temp ,
2018-11-15 02:19:58 +08:00
path . join ( 'app/libs/testjar2.jar' ) , false ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#006i : should allow installing .so lib file from sources with old target-dir scheme (GH-547)' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 9 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-14 02:06:48 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyplugin ,
'src/android/jniLibs/x86/libnative.so' , temp ,
2018-11-15 02:19:58 +08:00
path . join ( 'app/src/main/jniLibs/x86/libnative.so' ) , false ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-22 21:59:33 +08:00
it ( 'Test#006j : should allow installing sources with target-dir that includes "app"' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 10 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-22 21:59:33 +08:00
expect ( copyFileSpy )
. toHaveBeenCalledWith ( dummyplugin , 'src/android/DummyPlugin2.java' , temp , path . join ( 'app/src/main/java/com/appco/DummyPlugin2.java' ) , false ) ;
} ) ;
2018-11-28 19:46:45 +08:00
it ( 'Test#006k : should allow installing sources with target-dir that includes "app" in its first directory' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 11 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-28 19:46:45 +08:00
expect ( copyFileSpy )
. toHaveBeenCalledWith ( dummyplugin , 'src/android/DummyPlugin2.java' , temp , path . join ( 'app/src/main/java/appco/src/DummyPlugin2.java' ) , false ) ;
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <framework> elements' , function ( ) {
2022-04-18 09:39:54 +08:00
const someString = jasmine . any ( String ) ;
2016-02-29 23:49:17 +08:00
2022-04-18 09:39:54 +08:00
const copyNewFileOrig = common . _ _get _ _ ( 'copyNewFile' ) ;
const copyNewFileSpy = jasmine . createSpy ( 'copyNewFile' ) ;
2016-02-29 23:49:17 +08:00
2017-06-14 02:42:20 +08:00
beforeEach ( function ( ) {
2020-01-29 09:12:55 +08:00
fs . copySync ( android _studio _project , temp ) ;
2016-02-29 23:49:17 +08:00
spyOn ( dummyProject , 'addSystemLibrary' ) ;
spyOn ( dummyProject , 'addSubProject' ) ;
spyOn ( dummyProject , 'addGradleReference' ) ;
common . _ _set _ _ ( 'copyNewFile' , copyNewFileSpy ) ;
} ) ;
2017-06-14 02:42:20 +08:00
afterEach ( function ( ) {
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'copyNewFile' , copyNewFileOrig ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#007 : should throw if framework doesn\'t have "src" attribute' , function ( ) {
2017-06-14 02:42:20 +08:00
expect ( function ( ) { android . framework . install ( { } , dummyPluginInfo , dummyProject ) ; } ) . toThrow ( ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#008 : should install framework without "parent" attribute into project root' , function ( ) {
2022-04-18 09:39:54 +08:00
const framework = { src : 'plugin-lib' } ;
2016-02-29 23:49:17 +08:00
android . framework . install ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . addSystemLibrary ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#009 : should install framework with "parent" attribute into parent framework dir' , function ( ) {
2022-04-18 09:39:54 +08:00
const childFramework = { src : 'plugin-lib2' , parent : 'plugin-lib' } ;
2016-02-29 23:49:17 +08:00
android . framework . install ( childFramework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . addSystemLibrary ) . toHaveBeenCalledWith ( path . resolve ( dummyProject . projectDir , childFramework . parent ) , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#010 : should not copy anything if "custom" attribute is not set' , function ( ) {
2022-04-18 09:39:54 +08:00
const framework = { src : 'plugin-lib' } ;
const cpSpy = spyOn ( fs , 'copySync' ) ;
2016-02-29 23:49:17 +08:00
android . framework . install ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . addSystemLibrary ) . toHaveBeenCalledWith ( someString , framework . src ) ;
expect ( cpSpy ) . not . toHaveBeenCalled ( ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#011 : should copy framework sources if "custom" attribute is set' , function ( ) {
2022-04-18 09:39:54 +08:00
const framework = { src : 'plugin-lib' , custom : true } ;
2016-02-29 23:49:17 +08:00
android . framework . install ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . addSubProject ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
expect ( copyNewFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , framework . src , dummyProject . projectDir , someString , false ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#012 : should install gradleReference using project.addGradleReference' , function ( ) {
2022-04-18 09:39:54 +08:00
const framework = { src : 'plugin-lib' , custom : true , type : 'gradleReference' } ;
2016-02-29 23:49:17 +08:00
android . framework . install ( framework , dummyPluginInfo , dummyProject ) ;
expect ( copyNewFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , framework . src , dummyProject . projectDir , someString , false ) ;
expect ( dummyProject . addGradleReference ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
} ) ;
2016-04-07 18:24:41 +08:00
2017-06-14 02:42:20 +08:00
describe ( 'of <js-module> elements' , function ( ) {
2022-04-18 09:39:54 +08:00
const jsModule = { src : 'www/dummyplugin.js' } ;
let wwwDest , platformWwwDest ;
2016-04-07 18:24:41 +08:00
beforeEach ( function ( ) {
spyOn ( fs , 'writeFileSync' ) ;
wwwDest = path . resolve ( dummyProject . www , 'plugins' , dummyPluginInfo . id , jsModule . src ) ;
platformWwwDest = path . resolve ( dummyProject . platformWww , 'plugins' , dummyPluginInfo . id , jsModule . src ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#013 : should put module to both www and platform_www when options.usePlatformWww flag is specified' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'js-module' ] . install ( jsModule , dummyPluginInfo , dummyProject , { usePlatformWww : true } ) ;
2016-04-07 18:24:41 +08:00
expect ( fs . writeFileSync ) . toHaveBeenCalledWith ( wwwDest , jasmine . any ( String ) , 'utf-8' ) ;
expect ( fs . writeFileSync ) . toHaveBeenCalledWith ( platformWwwDest , jasmine . any ( String ) , 'utf-8' ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#014 : should put module to www only when options.usePlatformWww flag is not specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android [ 'js-module' ] . install ( jsModule , dummyPluginInfo , dummyProject ) ;
expect ( fs . writeFileSync ) . toHaveBeenCalledWith ( wwwDest , jasmine . any ( String ) , 'utf-8' ) ;
expect ( fs . writeFileSync ) . not . toHaveBeenCalledWith ( platformWwwDest , jasmine . any ( String ) , 'utf-8' ) ;
} ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <asset> elements' , function ( ) {
2022-04-18 09:39:54 +08:00
let asset ;
2016-04-07 18:24:41 +08:00
beforeEach ( function ( ) {
2019-10-22 00:26:17 +08:00
asset = { src : 'www/dummyPlugin.js' , target : 'foo/dummy.js' } ;
2016-04-07 18:24:41 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#015 : should put asset to both www and platform_www when options.usePlatformWww flag is specified' , function ( ) {
2019-01-08 13:31:14 +08:00
android . asset . install ( asset , dummyPluginInfo , dummyProject , { usePlatformWww : true } ) ;
2016-04-07 18:24:41 +08:00
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , asset . src , dummyProject . www , asset . target ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , asset . src , dummyProject . platformWww , asset . target ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#016 : should put asset to www only when options.usePlatformWww flag is not specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android . asset . install ( asset , dummyPluginInfo , dummyProject ) ;
expect ( copyFileSpy ) . toHaveBeenCalledWith ( dummyPluginInfo . dir , asset . src , dummyProject . www , asset . target ) ;
expect ( copyFileSpy ) . not . toHaveBeenCalledWith ( dummyPluginInfo . dir , asset . src , dummyProject . platformWww , asset . target ) ;
} ) ;
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'uninstallation' , function ( ) {
2022-04-18 09:39:54 +08:00
const deleteJavaOrig = common . _ _get _ _ ( 'deleteJava' ) ;
2020-01-31 21:02:48 +08:00
const originalRemoveSync = fs . removeSync ;
2022-04-18 09:39:54 +08:00
const deleteJavaSpy = jasmine . createSpy ( 'deleteJava' ) ;
let dummyProject ;
2020-01-29 09:12:55 +08:00
let removeSyncSpy ;
2016-02-29 23:49:17 +08:00
2017-06-14 02:42:20 +08:00
beforeEach ( function ( ) {
2020-01-29 09:12:55 +08:00
fs . ensureDirSync ( temp ) ;
fs . ensureDirSync ( plugins _dir ) ;
fs . copySync ( android _studio _project , temp ) ;
2016-02-29 23:49:17 +08:00
AndroidProject . purgeCache ( ) ;
dummyProject = AndroidProject . getProjectFile ( temp ) ;
2020-01-29 09:12:55 +08:00
removeSyncSpy = spyOn ( fs , 'removeSync' ) ;
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'deleteJava' , deleteJavaSpy ) ;
} ) ;
2017-06-14 02:42:20 +08:00
afterEach ( function ( ) {
2020-01-29 09:12:55 +08:00
originalRemoveSync . call ( fs , temp ) ;
2016-02-29 23:49:17 +08:00
common . _ _set _ _ ( 'deleteJava' , deleteJavaOrig ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <lib-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#017 : should remove jar files for Android Studio projects' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'lib-file' ] . install ( valid _libs [ 0 ] , dummyPluginInfo , dummyProject ) ;
android [ 'lib-file' ] . uninstall ( valid _libs [ 0 ] , dummyPluginInfo , dummyProject ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/libs/TestLib.jar' ) ) ;
2016-09-17 06:41:20 +08:00
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <resource-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#018 : should remove files for Android Studio projects' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'resource-file' ] . install ( valid _resources [ 0 ] , dummyPluginInfo , dummyProject ) ;
android [ 'resource-file' ] . uninstall ( valid _resources [ 0 ] , dummyPluginInfo , dummyProject ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app' , 'src' , 'main' , 'res' , 'xml' , 'dummy.xml' ) ) ;
2017-10-04 05:16:27 +08:00
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <source-file> elements' , function ( ) {
2018-04-18 19:16:54 +08:00
it ( 'Test#019 : should remove stuff by calling common.deleteJava for Android Studio projects' , function ( ) {
2018-09-06 10:06:18 +08:00
android [ 'source-file' ] . install ( valid _source [ 0 ] , dummyPluginInfo , dummyProject ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 0 ] , dummyPluginInfo , dummyProject ) ;
2016-09-17 06:41:20 +08:00
expect ( deleteJavaSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/src/main/java/com/phonegap/plugins/dummyplugin/DummyPlugin.java' ) ) ;
} ) ;
2016-02-29 23:49:17 +08:00
2018-11-12 02:36:31 +08:00
it ( 'Test#019a : should remove stuff by calling common.deleteJava for Android Studio projects, with specific app target-dir' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 1 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 1 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2018-11-12 02:36:31 +08:00
expect ( deleteJavaSpy ) . toHaveBeenCalledWith ( temp , path . join ( 'app/src/main/src/com/phonegap/plugins/dummyplugin/DummyPlugin2.java' ) ) ;
} ) ;
2018-11-13 10:42:31 +08:00
it ( 'Test#019b : should remove stuff by calling common.removeFile for Android Studio projects, of jar with new app target-dir scheme' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 2 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 2 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/libs/TestLib.jar' ) ) ;
2018-11-12 02:36:31 +08:00
} ) ;
2018-11-13 10:42:31 +08:00
it ( 'Test#019c : should remove stuff by calling common.removeFile for Android Studio projects, of aar with new app target-dir scheme' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 3 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 3 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/libs/TestAar.aar' ) ) ;
2018-11-12 02:36:31 +08:00
} ) ;
2018-11-13 10:50:20 +08:00
it ( 'Test#019d : should remove stuff by calling common.removeFile for Android Studio projects, of xml with old target-dir scheme' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 4 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 4 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/src/main/res/xml/mysettings.xml' ) ) ;
2018-11-13 10:50:20 +08:00
} ) ;
2018-11-13 11:01:13 +08:00
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 ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 5 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 5 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/src/main/res/values/other.extension' ) ) ;
2018-11-13 11:01:13 +08:00
} ) ;
2018-11-14 02:06:48 +08:00
2018-11-15 02:19:58 +08:00
it ( 'Test#019f : should remove stuff by calling common.removeFile for Android Studio projects, of aidl with old target-dir scheme (GH-547)' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 6 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 6 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/src/main/aidl/com/mytest/myapi.aidl' ) ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#019g : should remove stuff by calling common.removeFile for Android Studio projects, of aar with old target-dir scheme (GH-547)' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 7 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 7 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/libs/testaar2.aar' ) ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
it ( 'Test#019h : should remove stuff by calling common.removeFile for Android Studio projects, of jar with old target-dir scheme (GH-547)' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 8 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 8 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/libs/testjar2.jar' ) ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-15 02:19:58 +08:00
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 ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 9 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 9 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( path . join ( dummyProject . projectDir , 'app/src/main/jniLibs/x86/libnative.so' ) ) ;
2018-11-14 02:06:48 +08:00
} ) ;
2018-11-22 21:59:33 +08:00
it ( 'Test#019j : should remove stuff by calling common.deleteJava for Android Studio projects, with target-dir that includes "app"' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'source-file' ] . install ( valid _source [ 10 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
android [ 'source-file' ] . uninstall ( valid _source [ 10 ] , dummyPluginInfo , dummyProject , { android _studio : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( deleteJavaSpy ) . toHaveBeenCalledWith ( dummyProject . projectDir , path . join ( 'app/src/main/java/com/appco/DummyPlugin2.java' ) ) ;
2018-11-22 21:59:33 +08:00
} ) ;
2018-11-12 02:36:31 +08:00
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <framework> elements' , function ( ) {
2022-04-18 09:39:54 +08:00
const someString = jasmine . any ( String ) ;
2016-02-29 23:49:17 +08:00
2017-06-14 02:42:20 +08:00
beforeEach ( function ( ) {
2020-01-29 09:12:55 +08:00
fs . ensureDirSync ( path . join ( dummyProject . projectDir , dummyPluginInfo . id ) ) ;
2016-02-29 23:49:17 +08:00
spyOn ( dummyProject , 'removeSystemLibrary' ) ;
spyOn ( dummyProject , 'removeSubProject' ) ;
spyOn ( dummyProject , 'removeGradleReference' ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#020 : should throw if framework doesn\'t have "src" attribute' , function ( ) {
2017-06-14 02:42:20 +08:00
expect ( function ( ) { android . framework . uninstall ( { } , dummyPluginInfo , dummyProject ) ; } ) . toThrow ( ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#021 : should uninstall framework without "parent" attribute into project root' , function ( ) {
2022-04-18 09:39:54 +08:00
const framework = { src : 'plugin-lib' } ;
2016-02-29 23:49:17 +08:00
android . framework . uninstall ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . removeSystemLibrary ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#022 : should uninstall framework with "parent" attribute into parent framework dir' , function ( ) {
2022-04-18 09:39:54 +08:00
const childFramework = { src : 'plugin-lib2' , parent : 'plugin-lib' } ;
2016-02-29 23:49:17 +08:00
android . framework . uninstall ( childFramework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . removeSystemLibrary ) . toHaveBeenCalledWith ( path . resolve ( dummyProject . projectDir , childFramework . parent ) , someString ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#023 : should remove framework sources if "custom" attribute is set' , function ( ) {
2022-04-18 09:39:54 +08:00
const framework = { src : 'plugin-lib' , custom : true } ;
2016-02-29 23:49:17 +08:00
android . framework . uninstall ( framework , dummyPluginInfo , dummyProject ) ;
expect ( dummyProject . removeSubProject ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( someString ) ;
2016-02-29 23:49:17 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#24 : should install gradleReference using project.removeGradleReference' , function ( ) {
2022-04-18 09:39:54 +08:00
const framework = { src : 'plugin-lib' , custom : true , type : 'gradleReference' } ;
2016-02-29 23:49:17 +08:00
android . framework . uninstall ( framework , dummyPluginInfo , dummyProject ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( someString ) ;
2016-02-29 23:49:17 +08:00
expect ( dummyProject . removeGradleReference ) . toHaveBeenCalledWith ( dummyProject . projectDir , someString ) ;
} ) ;
} ) ;
2016-04-07 18:24:41 +08:00
2017-06-14 02:42:20 +08:00
describe ( 'of <js-module> elements' , function ( ) {
2022-04-18 09:39:54 +08:00
const jsModule = { src : 'www/dummyPlugin.js' } ;
let wwwDest ;
let platformWwwDest ;
2016-04-07 18:24:41 +08:00
beforeEach ( function ( ) {
wwwDest = path . resolve ( dummyProject . www , 'plugins' , dummyPluginInfo . id , jsModule . src ) ;
platformWwwDest = path . resolve ( dummyProject . platformWww , 'plugins' , dummyPluginInfo . id , jsModule . src ) ;
2022-04-18 09:39:54 +08:00
const existsSyncOrig = fs . existsSync ;
2017-01-04 03:02:48 +08:00
spyOn ( fs , 'existsSync' ) . and . callFake ( function ( file ) {
2017-06-14 02:42:20 +08:00
if ( [ wwwDest , platformWwwDest ] . indexOf ( file ) >= 0 ) return true ;
2016-04-07 18:24:41 +08:00
return existsSyncOrig . call ( fs , file ) ;
} ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#025 : should put module to both www and platform_www when options.usePlatformWww flag is specified' , function ( ) {
2019-01-08 13:31:14 +08:00
android [ 'js-module' ] . uninstall ( jsModule , dummyPluginInfo , dummyProject , { usePlatformWww : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( wwwDest ) ;
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( platformWwwDest ) ;
2016-04-07 18:24:41 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#026 : should put module to www only when options.usePlatformWww flag is not specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android [ 'js-module' ] . uninstall ( jsModule , dummyPluginInfo , dummyProject ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( wwwDest ) ;
expect ( removeSyncSpy ) . not . toHaveBeenCalledWith ( platformWwwDest ) ;
2016-04-07 18:24:41 +08:00
} ) ;
} ) ;
2017-06-14 02:42:20 +08:00
describe ( 'of <asset> elements' , function ( ) {
2022-04-18 09:39:54 +08:00
const asset = { src : 'www/dummyPlugin.js' , target : 'foo/dummy.js' } ;
let wwwDest , platformWwwDest ;
2016-04-07 18:24:41 +08:00
beforeEach ( function ( ) {
wwwDest = path . resolve ( dummyProject . www , asset . target ) ;
platformWwwDest = path . resolve ( dummyProject . platformWww , asset . target ) ;
2022-04-18 09:39:54 +08:00
const existsSyncOrig = fs . existsSync ;
2017-01-04 03:02:48 +08:00
spyOn ( fs , 'existsSync' ) . and . callFake ( function ( file ) {
2017-06-14 02:42:20 +08:00
if ( [ wwwDest , platformWwwDest ] . indexOf ( file ) >= 0 ) return true ;
2016-04-07 18:24:41 +08:00
return existsSyncOrig . call ( fs , file ) ;
} ) ;
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#027 : should put module to both www and platform_www when options.usePlatformWww flag is specified' , function ( ) {
2019-01-08 13:31:14 +08:00
android . asset . uninstall ( asset , dummyPluginInfo , dummyProject , { usePlatformWww : true } ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( wwwDest ) ;
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( platformWwwDest ) ;
2016-04-07 18:24:41 +08:00
} ) ;
2018-04-18 19:16:54 +08:00
it ( 'Test#028 : should put module to www only when options.usePlatformWww flag is not specified' , function ( ) {
2016-04-07 18:24:41 +08:00
android . asset . uninstall ( asset , dummyPluginInfo , dummyProject ) ;
2020-01-29 09:12:55 +08:00
expect ( removeSyncSpy ) . toHaveBeenCalledWith ( wwwDest ) ;
expect ( removeSyncSpy ) . not . toHaveBeenCalledWith ( platformWwwDest ) ;
2016-04-07 18:24:41 +08:00
} ) ;
} ) ;
2016-02-29 23:49:17 +08:00
} ) ;
} ) ;