/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

buildscript {

  apply from: "${rootProject.projectDir}/gradle/scripts/repositories.gradle", to: buildscript

  dependencies {
    classpath (group: 'com.linkedin.pegasus', name: 'gradle-plugins', version: rootProject.pegasusVersion) {
      exclude group: 'org.apache.ant'
    }
  }

}

apply plugin: 'pegasus'
apply plugin: 'war'

def apiProject = project(project.getParent().getPath() + ":" + project.getParent().getName() + "-api")
ext.apiProject = apiProject

if (file('extraDependencies.gradle').exists()) {
  apply from: 'extraDependencies.gradle'
}

dependencies {
  compile project(path: apiProject.path, configuration: 'dataTemplate')
  compile(project(':gobblin-utility')) {
    // pegasus uses an old version of guice, so we must exclude it from gobblin-utility
    exclude module: "guice"
  }

  compile externalDependency.gson
  compile externalDependency.lombok
  compile externalDependency.pegasus.restliServer
  compile externalDependency.pegasus.restliCommon
  compile externalDependency.pegasus.restliNettyStandalone
  compile externalDependency.pegasus.restliGuiceBridge

  testCompile externalDependency.testng
}

// Below is only used for running jetty from within gradle for demo purposes.
configurations {
  jetty8
}

dependencies {
  jetty8 "org.mortbay.jetty:jetty-runner:8.1.15.v20140411"
}

task JettyRunWar(type: JavaExec) {
  dependsOn war
  main = "org.mortbay.jetty.runner.Runner"
  args = [war.archivePath]
  classpath configurations.jetty8
}

afterEvaluate {
  tasks["publishRestliIdl"].dependsOn(apiProject.path + ":mainGeneratedDataTemplateClasses")
}

artifacts {
  archives jar
}

war {
  classifier "war"
}
