/*
 * 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"
apply plugin: "eclipse"
// TODO add idea module config.
apply plugin: "idea"
apply plugin: "scala"
apply plugin: 'com.github.johnrengelman.shadow'

buildscript {
  repositories { gradlePluginPortal() }
  dependencies {
    classpath "com.github.johnrengelman.shadow:com.github.johnrengelman.shadow.gradle.plugin:5.2.0"
  }
}

// Read the groupId and version properties from the "parent" bigtop project.
// It would be better if there was some better way of doing this. Howvever,
// at this point, we have to do this (or some variation thereof) since gradle
// projects can't have maven projects as parents (AFAIK. If there is a way to do it,
// it doesn't seem to be well-documented).
def setProjectProperties() {
    Node xml = new XmlParser().parse("../../pom.xml")
    group = xml.groupId.first().value().first()
    version = xml.version.first().value().first()
}

setProjectProperties()
description = """"""

sourceCompatibility = 1.8
targetCompatibility = 1.8

// Specify any additional project properties.
ext {
    sparkVersion = "3.5.4"
    scalaVersion = "2.12"
}

shadowJar {
    zip64 true
}

repositories {
    mavenLocal()
    mavenCentral()
}

tasks.withType(AbstractCompile) {
    options.encoding = 'UTF-8'
    options.compilerArgs << "-Xlint:all"
}

tasks.withType(Test) {
    testLogging {
        // Uncomment this if you want to see the console output from the tests.
        // showStandardStreams = true
        events "passed", "skipped", "failed"
        // show standard out and standard error of the test JVM(s) on the console
        //showStandardStreams = true
    }
}

// Create a separate source-set for the src/integrationTest set of classes. The convention here
// is that gradle will look for a directory with the same name as that of the specified source-set
// under the 'src' directory.
sourceSets {
    main {
        java.srcDirs = [];
        scala.srcDirs = ["src/main/scala", "src/main/java"]
    }
}

dependencies {
    compile("org.apache.spark:spark-core_${scalaVersion}:${sparkVersion}")
    compile("org.apache.spark:spark-mllib_${scalaVersion}:${sparkVersion}")
    compile("org.apache.spark:spark-sql_${scalaVersion}:${sparkVersion}")
    compile "org.apache.bigtop:bigpetstore-data-generator:3.6.0-SNAPSHOT"
    compile "org.json4s:json4s-jackson_${scalaVersion}:3.6.12"

    testCompile "junit:junit:4.13.2"
    testCompile "org.scalatest:scalatest_${scalaVersion}:3.2.19"
    testCompile "org.scalatestplus:junit-4-13_${scalaVersion}:3.2.19.0"
}

eclipse {
    classpath {
        // Comment out the following two lines if you want to generate an eclipse project quickly.
        downloadSources = true
        downloadJavadoc = false
    }
}
