buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath "com.novoda:bintray-release:$project.bintrayPluginVersion"
  }
}

allprojects {
  buildscript {
    repositories {
      jcenter()
      mavenCentral()
    }
  }
  repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
  }
}

def buildSrcDir = 'buildsystem'
apply from: "${buildSrcDir}/inject.gradle"

task wrapper(type: Wrapper) {
  gradleVersion = project.gradleVersion
}

task cleanFrodo(type: Exec) {
  description = 'Cleans all Frodo projects.'
  commandLine './gradlew', 'clean'
}

task installFrodoApi(type: Exec) {
  description = 'Assembles and installs Frodo Api in the local maven repository.'
  commandLine './gradlew', '-p', 'frodo-api/', 'assemble', 'install'
}

task installFrodoRuntime(type: Exec) {
  description = 'Assembles and installs Frodo Core Runtime Library in the local maven repository.'
  commandLine "./gradlew", "-p", "frodo-runtime/", "assembleDebug", "install", "-x", "lint"
}

task installFrodoPlugin(type: Exec) {
  description = 'Assembles and installs Frodo Gradle Plugin in the local maven repository.'
  commandLine "./gradlew", "-p", "frodo-plugin/", "build", "install"
}

task installFrodoAndroidSample(type: Exec,
    dependsOn: ['installFrodoApi', 'installFrodoRuntime', 'installFrodoPlugin']) {
  description = 'Assembles and installs Frodo Example Android application.'
  commandLine "./gradlew", "clean", "-p", "frodo-android-sample/", "assembleDebug", "installDebug"
}
installFrodoAndroidSample.mustRunAfter('installFrodoApi', 'installFrodoRuntime',
    'installFrodoPlugin')

task runUnitTests(
    dependsOn: [':frodo-runtime:cleanTestDebugUnitTest', ':frodo-runtime:testDebugUnitTest']) {
  description = 'Run unit tests for frodo runtime.'
}

task publishFrodoPlugin(type: Exec, dependsOn: ['frodo-plugin:javadocJar']) {
  description = 'Publishes Frodo Gradle Plugin.'
  commandLine "./gradlew", "-p", "frodo-plugin/", "build", "bintrayUpload",
      "-PbintrayUser=$System.env.BINTRAY_USERNAME",
      "-PbintrayKey=$System.env.BINTRAY_KEY",
      "-PdryRun=false"
}

task publishFrodoApi(type: Exec, dependsOn: ['frodo-api:javadocJar']) {
  description = 'Publishes Frodo Library Api.'
  commandLine "./gradlew", "-p", "frodo-api/", "build", "bintrayUpload",
      "-PbintrayUser=$System.env.BINTRAY_USERNAME",
      "-PbintrayKey=$System.env.BINTRAY_KEY",
      "-PdryRun=false"
}

task publishFrodoRuntime(type: Exec,
    dependsOn: ['frodo-runtime:androidSourcesJar', 'frodo-runtime:androidJavadocsJar']) {
  description = 'Publishes Frodo Core Runtime Library.'
  commandLine "./gradlew", "-p", "frodo-runtime/", "build", "bintrayUpload",
      "-PbintrayUser=$System.env.BINTRAY_USERNAME",
      "-PbintrayKey=$System.env.BINTRAY_KEY",
      "-PdryRun=false"
}

task publishFrodo(
    dependsOn: ['cleanFrodo', 'publishFrodoPlugin', 'publishFrodoApi', 'publishFrodoRuntime']) {
  description = 'Publishes a new Frodo Library version to Bintray.'
}
publishFrodo.mustRunAfter('cleanFrodo', 'publishFrodoPlugin', 'publishFrodoApi',
    'publishFrodoRuntime')