if (!project.rootProject.file('local.properties').exists()) {
  println "Not applying install.gradle"
  return
}
apply plugin: 'com.novoda.bintray-release'

def getBintrayUserAndKey() {
  Properties properties = new Properties()
  properties.load(project.rootProject.file('local.properties').newDataInputStream())
  return [
      properties.getProperty("bintray.user"),
      properties.getProperty("bintray.apikey")
  ]
}

if (versions == null || versions.publishVersion == null) {
  throw new IllegalStateException("Unable to reference publishVersion")
}

task checkBintrayConfig {
  doLast {
    def (user, key) = getBintrayUserAndKey()
    if (user == null || user.isEmpty() ||
        key == null || key.isEmpty()) {
      throw new IllegalStateException("Must specify Bintray user/API key in your local.properties.")
    }
  }
}

afterEvaluate {
  bintrayUpload.dependsOn checkBintrayConfig
}

def (user, key) = getBintrayUserAndKey()
publish {
  bintrayUser = user
  bintrayKey = key
  userOrg = 'drummer-aidan'
  groupId = 'com.afollestad'
  artifactId = 'icon-request'
  publishVersion = versions.publishVersion
  desc = 'An easy to use Icon Request API, with traditional email capabilities plus the Arctic Manager API.'
  website = 'https://github.com/afollestad/arctic-icon-request'
  dryRun = false
}