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

group = 'org.apache.freemarker.onlinetester'
version = "0.1-SNAPSHOT"

ext.jarName = "${project.name}-${project.version}"

apply from: "intellij.gradle"
apply from: "${rootDir}/dependencies.gradle"
apply plugin: 'maven'
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'project-report'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: "com.github.kt3k.coveralls"

project.sourceCompatibility = "1.8"
project.targetCompatibility = "1.8"

repositories {
    mavenCentral()
    maven {
        url "https://repository.apache.org/content/repositories/snapshots/"
    }
    maven {
        url "https://repository.apache.org/content/repositories/staging/"
    }
}

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.1"
        classpath "com.github.jengelman.gradle.plugins:shadow:1.2.4"
    }
}

configurations {
    rat
}

dependencies {
    compile libraries.dropwizard
    compile libraries.dropwizard_views
    compile libraries.dropwizard_views_freemarker
    compile libraries.dropwizard_configurable_assets
    compile libraries.dropwizard_bundles_redirect
    compile libraries.freemarker
    compile libraries.commonLangs
    compile libraries.findBugs

    testCompile libraries.dropwizard_testing
    testCompile libraries.junit
    testCompile libraries.mockito
    testCompile libraries.hamcrest
    testCompile libraries.jersey_grrizle
    
    rat libraries.rat
}

compileJava {
    options.compilerArgs << "-Werror"
}
compileTestJava {
    options.compilerArgs << "-Werror"
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.5'
}

jar {
    manifest {
        attributes 'Main-Class': 'org.apache.freemarker.onlinetester.dropwizard.FreeMarkerOnlineTester'
        attributes 'Implementation-Version': "$version"
    }
}

shadowJar {
    dependsOn jar
    baseName = "${jarName}"
    classifier = null
    version = null
    mergeServiceFiles()
}

// Log full exception information on failed tests, so we see it in the Travis log:
test.testLogging {
    showStackTraces true
    exceptionFormat "full"
}

jacocoTestReport {
    reports {
        xml.enabled  true
    }
}

task rat {
    doLast {
        ant.taskdef(
                name: 'ratReport', classname: 'org.apache.rat.anttasks.Report',
                classpath: configurations.rat.asPath)
        ant.ratReport(reportFile: "build/rat-report.txt") {
            fileset(dir: "", excludesfile: "rat-excludes")
        }
        project.logger.lifecycle('Rat reports were written into build/rat-report.txt')
    }
}

check.dependsOn jacocoTestReport
build.dependsOn shadowJar
