/*
 * 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.
 */


apply from: 'gradle/scripts/environment.gradle'

buildscript {
  apply from: 'gradle/scripts/repositories.gradle'
  apply from: 'gradle/scripts/defaultBuildProperties.gradle'
  apply from: 'gradle/scripts/computeVersions.gradle'
  apply from: 'gradle/scripts/ci-support.gradle'

  apply from: file('gradle/scripts/buildscript.gradle'), to: buildscript

  buildscript.repositories.addAll(project.repositories)

  dependencies {
    classpath 'org.apache.ant:ant:1.9.4'
    classpath 'gradle.plugin.org.inferred:gradle-processors:1.1.2'
    classpath 'io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE'
    classpath 'me.champeau.gradle:jmh-gradle-plugin:0.4.8'
    classpath "gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.14.0"
    classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.33.20'
  }

  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }

}

apply plugin: "com.github.hierynomus.license"

downloadLicenses {
  includeProjectDependencies = true

  ext.apacheTwo = license('Apache License, Version 2.0', 'http://opensource.org/licenses/Apache-2.0')
  ext.bsd = license('BSD License', 'http://www.opensource.org/licenses/bsd-license.php')
  ext.bsd3 = license('BSD 3-clause', 'https://opensource.org/licenses/BSD-3-Clause')
  ext.cddlGplv2 = license('CDDL + GPLv2 with classpath exception', 'https://glassfish.dev.java.net/nonav/public/CDDL+GPL.html')
  ext.spl = license('SPL', 'http://opensource.org/licenses/SPL-1.0');
  ext.epl = license('Eclipse Public License - Version 1.0', 'https://opensource.org/licenses/EPL-1.0')

  licenses = [
      (group('com.linkedin.gobblin')) : apacheTwo,
      // https://zookeeper.apache.org/
      (group('org.apache.zookeeper')) : apacheTwo,
      // http://testng.org/doc/
      (group('org.testng:testng')) : apacheTwo,
      // https://db.apache.org/jdo/index.html
      (group('javax.jdo')) : apacheTwo,
      // Based on other javax licenses
      (group('javax.servlet.jsp')) : cddlGplv2,
      (group('javax.servlet')) : cddlGplv2,
      (group('javax.transaction')) : cddlGplv2,
      // http://commons.apache.org/proper/commons-beanutils/
      (group('commons-beanutils')) : apacheTwo,
      // http://jakarta.apache.org/regexp/
      (group('regexp')) : apacheTwo,
      // http://forge.ow2.org/projects/asm/
      (group('asm')) : bsd,
      // https://github.com/codehaus/jettison/blob/master/pom.xml
      (group('org.codehaus.jettison')) : apacheTwo,
      // https://github.com/stephenc/jcip-annotations/blob/master/LICENSE.txt
      (group('net.jcip')) : apacheTwo,
      // https://github.com/google/re2j/blob/master/LICENSE
      (group('com.google.re2j')) : bsd3,
      // https://github.com/findbugsproject/findbugs/issues/128
      (group('com.google.code.findbugs')) : bsd3,
      // http://www.beanshell.org/license.html
      (group('org.beanshell')) : spl,
      // http://www.mchange.com/projects/c3p0/
      (group('c3p0')) : epl,
      'antlr-runtime-3.4.jar' : apacheTwo
      ]
  aliases = [
      (apacheTwo) : ['The Apache Software License, Version 2.0', 'Apache 2', 'Apache License Version 2.0',
                     'Apache License, Version 2.0', 'Apache License 2.0', 'Apache Version 2.0, January 2004',
                     license('Apache License', 'http://www.apache.org/licenses/LICENSE-2.0')],
      (bsd) : ['BSD', license('New BSD License', 'http://www.opensource.org/licenses/bsd-license.php')]
  ]
  dependencyConfiguration = 'compile'
  excludeDependencies = [
      'gobblin-throttling-service-client-data-template-*.jar',
      'gobblin-throttling-service-api-data-template-*.jar',
      'gobblin-flow-config-service-client-data-template-*.jar',
      'gobblin-rest-api-data-template-*.jar',
      'gobblin-throttling-service-server-data-template-*.jar',
      'gobblin-flow-config-service-server-data-template-*.jar',
      'gobblin-rest-server-data-template-*.jar',
      'gobblin-flow-config-service-api-data-template-*.jar'
  ]
}

apply from: 'gradle/scripts/repositories.gradle'

apply plugin: 'org.inferred.processors'
apply plugin: 'io.spring.dependency-management'

apply from: 'gradle/scripts/configureSubprojects.gradle'
apply from: 'gradle/scripts/idesSetup.gradle'
apply from: 'gradle/scripts/jacoco-coveralls-support.gradle'

apply from: 'gradle/scripts/dependencyDefinitions.gradle'
apply from: 'gradle/scripts/restli.gradle'

apply from: 'gradle/scripts/testSetup.gradle'
apply from: 'gradle/scripts/globalDependencies.gradle'
apply from: 'gradle/scripts/javaPlugin.gradle'

apply from: 'gradle/scripts/utilities.gradle'

apply from: 'gradle/scripts/javadoc.gradle'
apply from: 'gradle/scripts/sourcesJar.gradle'

apply from: 'gradle/scripts/mavenPublishing.gradle'
apply from: 'gradle/scripts/nexusPublishing.gradle'
apply from: 'gradle/scripts/artifactoryPublishing.gradle'
apply from: 'gradle/scripts/javaVersionCheck.gradle'

apply from: 'gradle/scripts/rat.gradle'
apply from: 'gradle/scripts/release.gradle'

/*
 * Hack for upgrading pegasus to version 11.0.0. For some reason, the gradle-plugins in
 * that version fails to bring in "tools.jar" into the classpath. The rest.li team is actively
 * seeking for a clean fix. This part will be removed later when the fix is ready
 */
allprojects {
  tasks.matching { it.name == 'generateRestModel' }.all {
    doFirst {
      it.codegenClasspath += files("${System.getProperty('java.home')}/../lib/tools.jar")
    }
  }
}

task printVersionName {
  doLast {
    println project.version
  }
}

rat {
  excludes = [
    '**/.git/**',
    '**/.github/**',
    '**/.gradle/**',
    '**/.project',
    '**/.factorypath',
    '**/.settings/**',
    '**/.classpath',
    '**/*.iml',
    '**/*.iws',
    '**/*.ipr',
    '**/.rubyversion',
    'gradle/wrapper/**',
    'gradlew',
    '**/changes.md',
    '**/README.md',
    '**/.ruby-version',
    '**/.DS_Store/**',
    '**/.gitignore',
    '**/.codecov_bash',
    '**/build/**',
    '**/target/**',
    '**/bin/**',
    '**/test-output/**',
    '**/Gemfile.lock',
    '**/*.tsv',
    '**/*.csv',
    '**/*.svg',
    '**/*.groovy',
    '**/*.yml',
    '**/*.yaml',
    '**/*.properties',
    '**/*.conf',
    '**/*.xml',
    '**/*.md',
    '**/*.json',
    '**/*.avsc',
    '**/*.schema',
    '**/*.ddl',
    '**/*.dml',
    '**/*.txt',
    '**/*.pull',
    '**/*.job',
    '**/*.log',
    '**/*.log.*',
    '**/*.sql',
    '**/*.zip',
    '**/*.gz',
    '**/*.tgz',
    '**/*.tar',
    '**/*.lck',
    '**/*.ctrl',
    '**/*.dat',
    '**/*.pem',
    '**/*.crc',
    '**/*.gpg',
    '**/*.jst',
    '**/*.orc',
    '**/*.rc',
    '**/*.avro',
    '**/*.avro.*',
    '**/*.proto',
    '**/*.png',
    '**/*.jpg',
    '**/*.jpeg',
    '**/*.eot',
    '**/*.ttf',
    '**/*.woff',
    '**/*.woff2',
    '**/Dockerfile',
    '**/.dockerignore',
    '**/file*',
    '**/*.epf',
    '**/*.pdsc',
    '**/*.pdl',
    '**/*.yml',
    '**/*.inc',
    '**/*.py',
    '**/*.gradle',
    '**/*.css',
    '**/*.sh',
    '**/*.avro',
    '**/*.txt.*',
    '**/*.key',
    '**/*.token',
    '**/*.btm',
    '**/*.json.*',
    '**/*.template',
    '**/migrationConfig',
    '**/testTable',
    '**/encryption_provider_test_keystore',
    '**/default_dataset_urn',
    '**/metastore_db',
    '**/grok/**',
    '**/mock-couchbase/**',
    '**/mainGeneratedRest/**',
    '**/mainGeneratedDataTemplate/**',
    '**/gen-java/**',
    '**/gen-avro/**',
    '**/gen-proto/**',
    '**/META-INF/**',
    '**/package-list',
    '**/WebmasterPerformanceTuningMetrics',
    '.reviewboardrc',
    'CONTRIBUTORS',
    'RELEASE.md',
    'DISCLAIMER',
    'NOTICE',
    'LICENSE'
  ]
}
