/*
 * Copyright 2016-2020 Andres Almiray
 *
 * This file is part of Java Trove Examples
 *
 * Java Trove Examples is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Java Trove Examples is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Java Trove Examples. If not, see <http://www.gnu.org/licenses/>.
 */

plugins {
    id 'war'
    id 'idea'
    id 'jetty'
    id 'jacoco'
    id 'net.ltgt.apt'                  version '0.15'
    id 'com.github.ben-manes.versions' version '0.27.0'
    id 'com.github.hierynomus.license' version '0.15.0'
    id 'org.kordamp.gradle.stats'      version '0.2.2'
}

repositories {
    jcenter()
    maven { url 'http://clojars.org/repo/' }
}

dependencyUpdates.resolutionStrategy = {
    componentSelection { rules ->
        rules.all { selection ->
            boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'pr', 'atlassian'].any { qualifier ->
                selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
            }
            if (rejected) {
                selection.reject('Release candidate')
            }
        }
    }
}

dependencies {
    compileOnly         "org.projectlombok:lombok:$lombokVersion"
    annotationProcessor "org.projectlombok:lombok:$lombokVersion"

    compileOnly "javax:javaee-api:$javaeeapiVersion"
    api "com.github.spullara.mustache.java:compiler:$mustacheVersion"
    api "com.fasterxml.jackson.core:jackson-core:$jacksonVersion"
    api "com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion"
    api "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
    api "org.slf4j:slf4j-api:$slf4jVersion"
    api "com.google.guava:guava:$guavaVersion"
    api("com.google.inject:guice:$guiceVersion") {
        exclude group: 'org.sonatype.sisu.inject', module: 'cglib'
    }
    api "com.google.inject.extensions:guice-servlet:$guiceVersion"
    api 'ru.vyarus:guice-ext-annotations:1.3.0'
    api "org.sql2o:sql2o:$sql2oVersion"
    api "com.zaxxer:HikariCP:$hikaricpVersion"

    runtimeOnly "com.h2database:h2:$h2Version"
    runtimeOnly "org.slf4j:slf4j-simple:$slf4jVersion"

    testImplementation "junit:junit:$junitVersion"
    testImplementation "org.mockito:mockito-core:$mockitoVersion"
    testImplementation "org.jukito:jukito:$jukitoVersion"
    testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
    testImplementation "io.rest-assured:rest-assured:$restassuredVersion"

    testImplementation "javax:javaee-api:$javaeeapiVersion"
    testImplementation "org.jboss.arquillian.junit:arquillian-junit-container:$arquillianVersion"
    testImplementation "org.jboss.arquillian.container:arquillian-tomcat-embedded-8:$arquillianTomcatVersion"
    testImplementation "org.apache.tomcat:tomcat-catalina:$tomcatVersion"

    testImplementation "org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-gradle-depchain:$shrinkwrapVersion"
    testImplementation "org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api-maven:$shrinkwrapVersion"
    testImplementation "org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven:$shrinkwrapVersion"
}

license {
    header = rootProject.file('gradle/HEADER')
    strictCheck = true
    ignoreFailures = true
    mapping {
        java = 'SLASHSTAR_STYLE'
        fxml = 'XML_STYLE'
    }
    ext.year    = '2016-2020'
    ext.author  = 'Andres Almiray'
    ext.project = 'Java Trove Examples'
}

jettyRun {
    contextPath = ''
}

jacoco {
    toolVersion = '0.7.9'
}

idea {
    project {
        jdkName '13'
        languageLevel '13'
        ipr {
            withXml { provider ->
                def node = provider.asNode()
                node.component.find { it.'@name' == 'VcsDirectoryMappings' }?.mapping[0].'@vcs' = 'Git'

                def compilerConfiguration = node.component.find { it.'@name' == 'CompilerConfiguration' }
                compilerConfiguration.remove(compilerConfiguration.annotationProcessing)
                compilerConfiguration.append(new XmlParser().parseText("""
    <annotationProcessing>
      <profile default="true" name="Default" enabled="true">
        <processorPath useClasspath="true" />
      </profile>
    </annotationProcessing>"""))
            }
        }
    }
}
