#
# Build configuration for Circle CI
#

machine:
  node:
    version: 6
  java:
    version: 'oraclejdk8'
  environment:
    ANDROID_HOME: /usr/local/android-sdk-linux
    ANDROID_NDK_HOME: $ANDROID_NDK
    NODE_ENV: test
    NODE_PATH: $NODE_PATH:$HOME/$CIRCLE_PROJECT_REPONAME/node_modules:$HOME/$CIRCLE_PROJECT_REPONAME/node_modules/cordova/node_modules
    PATH: $PATH:$HOME/$CIRCLE_PROJECT_REPONAME/node_modules/.bin

dependencies:
  cache_directories:
    - ~/.android
    - ~/android
    - ~/.gradle
  override:
    - npm install
    - cordova create app-preferences-app
    - echo test plugin within cordova app
    - cordova platform add android:
        pwd: app-preferences-app
    - cordova plugin add https://github.com/apla/me.apla.cordova.app-preferences:
        pwd: app-preferences-app
    - cordova plugin add cordova-plugin-device:
        pwd: app-preferences-app
    - cordova -d prepare:
        pwd: app-preferences-app
    - (cordova -d build --debug --emulator --gradleArg=--debug android || exit 0):
        pwd: app-preferences-app
    - (cordova -d build --debug --emulator --gradleArg=-Dorg.gradle.daemon=false android || exit 0):
        pwd: app-preferences-app
  pre:
    - ( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk --no-ui --all --filter tools,platform-tools,build-tools-25.0.3,android-22,android-25,extra-google-m2repository,extra-google-google_play_services
#    - chmod +x gradlew
#    - ANDROID_HOME=/usr/local/android-sdk-linux ./gradlew dependencies

test:
  pre:
    - emulator -avd circleci-android22 -no-audio -no-window:
        background: true
        parallel: true
    - circle-android wait-for-boot
  override:
    - echo running jasmine test
    - jasmine:
        pwd: bin
    - (if [ ! -f app-settings.json ]; then exit 0; fi):
        pwd: app-preferences-app
    - cp plugins/cordova-plugin-app-preferences/src/test.js www/js/apppreferences-test.js:
        pwd: app-preferences-app
    - patch -p0 -i plugins/cordova-plugin-app-preferences/src/test.patch:
        pwd: app-preferences-app
    - cordova prepare:
        pwd: app-preferences-app
    - cordova -d build --debug --emulator android:
        pwd: app-preferences-app
    - node ../bin/test-server.js android circleci-android22:
        pwd: app-preferences-app
