buildscript {
  repositories {
    mavenCentral()
    maven {
      url 'https://plugins.gradle.org/m2/'
    }
  }
  dependencies {
    classpath 'com.linkedin:gradle-dustjs-plugin:1.0.0'
    classpath 'de.obqo.gradle:gradle-lesscss-plugin:1.0-1.3.3'
  }
}

plugins {
    id 'com.craigburke.bower-installer' version '2.5.1'
}

apply plugin: 'lesscss'
apply plugin: 'dustjs'
apply plugin: 'distribution'

ext.pegasusVersion = '1.15.7'

configurations {
  generateRestli
}

dependencies {
  compile(project(':azkaban-common'))
  compile('com.linkedin.pegasus:restli-server:' + pegasusVersion)
  compile('org.apache.velocity:velocity-tools:2.0')

  testCompile('commons-collections:commons-collections:3.2.2')
  testCompile('org.hamcrest:hamcrest-all:1.3')
  testCompile('org.mockito:mockito-all:1.10.19')

  generateRestli('com.linkedin.pegasus:generator:' + pegasusVersion)
  generateRestli('com.linkedin.pegasus:restli-tools:' + pegasusVersion)

  // Needed by Velocity at runtime
  testRuntime('commons-collections:commons-collections:3.2.2')
  testCompile('org.hamcrest:hamcrest-all:1.3')
}

sourceSets {
  main {
    java {
      srcDirs 'src/main/java', 'src/restli/generatedJava', 'src/restli/java'
    }
  }
}

bower {
  installBase = 'bower' // <1>

  'moment'('2.14.1'){
    source 'min/moment.min.js' >> '/'
  }

  'moment-timezone'('0.5.5') {
    source 'builds/moment-timezone-with-data-2010-2020.min.js'  >> '/'
  }

  'eonasdan-bootstrap-datetimepicker'('4.0.0') {
    source 'build/js/*.min.js'  >> '/'
    excludes 'jquery'
  }

  'later'('1.2.0'){
    source 'later.min.js' >> '/'
  }
}
clean.dependsOn 'bowerClean'

task restliTemplateGenerator(type: JavaExec) {
  mkdir 'src/restli/generatedJava'

  main = 'com.linkedin.pegasus.generator.PegasusDataTemplateGenerator'
  args = ['src/restli/generatedJava','src/restli/schemas']
  classpath = configurations.generateRestli
}

task restliRestSpecGenerator(dependsOn: [restliTemplateGenerator], type: JavaExec) << {
  mkdir 'src/restli/generatedRestSpec'

  main = 'com.linkedin.restli.tools.idlgen.RestLiResourceModelExporterCmdLineApp'
  args = ['-outdir', 'src/restli/generatedRestSpec', '-sourcepath', 'src/restli/java']
  classpath = configurations.generateRestli
}

task restli(dependsOn: restliTemplateGenerator) << {
}

compileJava.dependsOn.add('restli')

lesscss {
  source = fileTree('src/main/less') {
    include 'azkaban.less'
    include 'azkaban-graph.less'
  }
  dest = 'build/less'
}

dustjs {
  source = fileTree('src/main/tl')
  dest = 'build/dust'
}

installDist.dependsOn 'lesscss'

distributions {
  main {
    contents {
      from('src/main/bash') {
        into 'bin'
        fileMode = 0755
      }
      from ('src/main/resources/conf') {
        into 'conf'
      }
      from(configurations.runtime) {
        into 'lib'
      }
      from(jar) {
        into 'lib'
      }
      from ('src/web') {
        into 'web'
      }
      from (lesscss.dest) {
        into 'web/css'
      }
      from (dustjs) {
        into 'web/js'
      }
      from ('bower') {
        into 'web/js'
      }
      from (bowerInstall) {
        into 'web/js'
      }
    }
  }
}
