plugins {
  id 'wrapper'
  id 'idea'
  id 'com.jfrog.bintray' version '1.1'
  id 'com.github.ben-manes.versions' version '0.8'
}

ext {
  gitVersion = new ByteArrayOutputStream().with { out ->
    exec {
      commandLine 'git', 'describe', '--tags', '--dirty'
      standardOutput = out
    }
    final full = out.toString().trim()

    // 'v1.0' -> '1.0', 'vendetta' -> 'vendetta'
    full ==~ /v\d.*/ ? full.substring(1) : full
  }
}

idea.project.ipr.withXml {
    def compilerConfig = it.asNode().component.find { it.'@name' == 'CompilerConfiguration' }
    compilerConfig.annotationProcessing[0].'@enabled' = 'true'
}

allprojects {
  apply plugin: 'project-report'
  apply plugin: 'groovy'
  apply plugin: 'maven'
  apply plugin: 'maven-publish'
  apply plugin: 'com.jfrog.bintray'

  version = rootProject.ext.gitVersion

  sourceCompatibility = 1.8
  targetCompatibility = 1.8

  group = 'com.airbnb.plog'

  ext {
    nettyVersion = '4.1.29.Final'
    slf4jVersion = '1.7.10'
    metricsVersion = '3.0.2'
  }

  configurations {
    provided
    compile.extendsFrom provided
  }

  dependencies {
    provided 'org.projectlombok:lombok:1.16.2'
    compile 'com.google.guava:guava:18.0'
    compile 'com.google.code.findbugs:jsr305:3.0.0' // used by guava concurrent APIs
    compile 'com.typesafe:config:1.2.1'
    compile 'com.eclipsesource.minimal-json:minimal-json:0.9.2'
    compile "io.netty:netty-codec:${nettyVersion}"
    compile "io.netty:netty-handler:${nettyVersion}"
    compile "org.slf4j:slf4j-api:${slf4jVersion}"

    testCompile 'org.codehaus.groovy:groovy-all:2.4.1'
    testCompile 'junit:junit:4.12'
  }

  sourceSets.main.compileClasspath += [configurations.provided]

  task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
  }

  publishing.publications {
    mavenJava(MavenPublication) {
      from components.java
      artifact sourcesJar { classifier 'sources' }
    }
  }

  bintray {
    user = System.env.BINTRAY_USER ? System.env.BINTRAY_USER : project.getProperty('bintrayUser')
    key  = System.env.BINTRAY_KEY ? System.env.BINTRAY_KEY : project.getProperty('bintrayKey')

    publications = ['mavenJava']

    pkg {
      userOrg = 'airbnb'
      repo = 'jars'
      name = 'plog'
      licenses = ['Apache-2.0']
    }
  }

  repositories {
    mavenLocal()
    jcenter {
      url "http://jcenter.bintray.com/"
    }
  }

  idea.module {
    downloadJavadoc = true
    downloadSources = true
  }
}
