/*
 * 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 plugin: 'java'

configurations {
  compile {
    if (rootProject.hasProperty('excludeHadoopDeps')) {
      exclude group: "org.apache.hadoop"
    }
    if (rootProject.hasProperty('excludeHiveDeps')) {
      exclude group: "org.apache.hive"
      exclude group: "com.linkedin.hive"
    }
    exclude group: 'org.slf4j', module: 'log4j-over-slf4j'
  }
}

dependencies {
  compile project(':gobblin-api')
  compile project(':gobblin-core')
  compile project(':gobblin-compaction')
  compile project(':gobblin-runtime')
  compile project(':gobblin-utility')
  compile project(':gobblin-metastore')
  compile project(':gobblin-metrics-libs:gobblin-metrics')
  compile project(':gobblin-data-management')
  compile project(":gobblin-rest-service:gobblin-rest-api")
  compile project(":gobblin-rest-service:gobblin-rest-client")
  compile project(":gobblin-rest-service:gobblin-rest-server")
  compile project(":gobblin-config-management:gobblin-config-client")
  compile project(":gobblin-config-management:gobblin-config-core")
  compile project(':gobblin-cluster')
  compile project(':gobblin-yarn')
  compile project(':gobblin-aws')
  compile project(':gobblin-service')
  compile project(':gobblin-runtime-hadoop')
}

apply from: "${rootProject.rootDir}/gobblin-flavored-build.gradle"

task buildDistributionTar(type: Tar, overwrite: true) {
  extension = 'tar.gz'
  baseName "apache-gobblin-incubating-bin"
  compression = Compression.GZIP

  into("conf") { from "../conf/" }
  into("bin") {
    from "../bin/"
    from project(':gobblin-utility').projectDir.path + '/src/main/bash/gobblin_password_encryptor.sh'
    filter { String line -> line.replace("GOBBLIN_VERSION=@project.version@",
      "GOBBLIN_VERSION="+'"' + project.version + '"') }
  }
  into("lib") {
    from configurations.runtime
  }
  into("gobblin-dist")

  doLast {
    copy {
      from buildDir.path + '/distributions/' + baseName + '-' + project.version + '.tar.gz'
      into project.rootDir.path

      archiveName = "${baseName}-${project.version}.tar.gz"
      // Disable md5, since Apache release policy has changed
      // ant.checksum file:"$buildDir.path/distributions/$archiveName", algorithm: "MD5", fileext: ".md5"
      ant.checksum file:"$buildDir.path/distributions/$archiveName", algorithm: "SHA-512", fileext: ".sha512"
    }
  }
}

// Signing requires a user ~/.gradle/gradle.properties file with signing information.
// See: http://www.gradle.org/docs/current/userguide/signing_plugin.html
signing {
  // Sign the source archive if the proper configuration is in place to do so.  Otherwise
  // skip the signing process (it isn't required).  This archive can be manually signed if
  // needed.
  required false
  sign buildDistributionTar
}

assemble.dependsOn buildDistributionTar
