import groovy.json.JsonSlurper
import org.gradle.internal.os.OperatingSystem

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        maven { url "http://repo.spring.io/plugins-release" }
        maven { url "http://repo.spring.io/milestone" }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.1"
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.9"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${spring_boot_version}"
        classpath "org.springframework.build.gradle:propdeps-plugin:0.0.7"
        classpath "com.moowork.gradle:gradle-node-plugin:1.1.1"
        classpath "io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE"
        //jhipster-needle-gradle-buildscript-dependency - JHipster will add additional gradle build script plugins here
    }
}

apply plugin: 'java'
sourceCompatibility=1.8
targetCompatibility=1.8
apply plugin: 'maven'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'propdeps'
apply plugin: 'com.moowork.node'
apply plugin: 'io.spring.dependency-management'
defaultTasks 'bootRun'

bootRepackage {
   mainClass = 'com.apress.jhblog.JhipsterblogApp'
}

war {

}

springBoot {
    mainClass = 'com.apress.jhblog.JhipsterblogApp'
    executable = true
    buildInfo()
}

if (OperatingSystem.current().isWindows()) {
    task pathingJar(type: Jar) {
        dependsOn configurations.runtime
        appendix = 'pathing'

        doFirst {
            manifest {
                attributes 'Class-Path': configurations.runtime.files.collect {
                    it.toURL().toString().replaceFirst(/file:\/+/, '/').replaceAll(' ', '%20')
                }.join(' ')
            }
        }
    }

    bootRun {
        addResources = false
        dependsOn pathingJar
        doFirst {
            classpath = files("$buildDir/classes/main", "$buildDir/resources/main", pathingJar.archivePath)
        }
    }
} else {
    bootRun {
        addResources = false
    }
}

test {
    include '**/*UnitTest*'
    include '**/*IntTest*'

    // uncomment if the tests reports are not generated
    // see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484
    // ignoreFailures true
    reports.html.enabled = false
}

task testReport(type: TestReport) {
    destinationDir = file("$buildDir/reports/tests")
    reportOn test
}

apply from: 'gradle/sonar.gradle'
apply from: 'gradle/liquibase.gradle'
apply from: 'gradle/mapstruct.gradle'
apply from: 'gradle/docker.gradle'
//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here

if (project.hasProperty('prod')) {
    apply from: 'gradle/profile_prod.gradle'
} else {
    apply from: 'gradle/profile_dev.gradle'
}

if (project.hasProperty('graphite')) {
    apply from: 'gradle/graphite.gradle'
}

if (project.hasProperty('prometheus')) {
    apply from: 'gradle/prometheus.gradle'
}

//group = 'com.apress.jhblog'
//artifact = 'jhipsterblog'
version = '0.0.1-SNAPSHOT'

//description = ''

configurations {
    providedRuntime
    compile.exclude module: "spring-boot-starter-tomcat"
}

repositories {
    mavenLocal()
    mavenCentral()
    jcenter()
    maven { url 'http://repo.spring.io/milestone' }
    maven { url 'http://repo.spring.io/snapshot' }
    maven { url 'https://repository.jboss.org/nexus/content/repositories/releases' }
    maven { url 'https://oss.sonatype.org/content/repositories/releases' }
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    maven { url 'http://repo.maven.apache.org/maven2' }
}

dependencies {
    compile "io.github.jhipster:jhipster:${jhipster_server_version}"
    compile "io.dropwizard.metrics:metrics-core:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-jcache:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-jvm:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-servlet:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-json:${dropwizard_metrics_version}"
    compile "io.dropwizard.metrics:metrics-servlets:${dropwizard_metrics_version}"
    compile ("net.logstash.logback:logstash-logback-encoder:${logstash_logback_encoder_version}") {
        exclude(group: 'ch.qos.logback')
    }
    compile "com.fasterxml.jackson.datatype:jackson-datatype-json-org"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-hppc"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5"
    compile "com.fasterxml.jackson.core:jackson-annotations"
    compile "com.fasterxml.jackson.core:jackson-databind"
    compile ("com.ryantenney.metrics:metrics-spring:${metrics_spring_version}")
    compile "javax.cache:cache-api"
    compile "org.hibernate:hibernate-core:${hibernate_version}"
    compile ("com.zaxxer:HikariCP:${hikaricp_version}")
    compile "org.apache.commons:commons-lang3:${commons_lang_version}"
    compile "commons-io:commons-io:${commons_io_version}"
    compile "javax.transaction:javax.transaction-api"
    compile "org.ehcache:ehcache"
    compile "org.hibernate:hibernate-jcache:${hibernate_version}"
    compile "org.hibernate:hibernate-envers"
    compile "org.hibernate:hibernate-validator"
    compile ("org.liquibase:liquibase-core")
    compile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}"
    compile "org.springframework.boot:spring-boot-actuator"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.springframework.boot:spring-boot-loader-tools"
    compile "org.springframework.boot:spring-boot-starter-mail"
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-starter-aop"
    compile "org.springframework.boot:spring-boot-starter-data-jpa"
    compile "org.springframework.boot:spring-boot-starter-security"
    compile ("org.springframework.boot:spring-boot-starter-web") {
        exclude module: 'spring-boot-starter-tomcat'
    }
    compile "org.springframework.boot:spring-boot-starter-undertow"
    compile "org.springframework.boot:spring-boot-starter-thymeleaf"
    compile "org.springframework.boot:spring-boot-starter-cloud-connectors"
    compile ("org.springframework:spring-context-support")
    compile "org.springframework.security:spring-security-config"
    compile "org.springframework.security:spring-security-data"
    compile "org.springframework.security:spring-security-web"
    compile "io.jsonwebtoken:jjwt:${jjwt_version}"
    compile ("io.springfox:springfox-swagger2:${springfox_version}") {
        exclude module: 'mapstruct'
    }
    compile "io.springfox:springfox-bean-validators:${springfox_version}"
    compile "mysql:mysql-connector-java"
    compile "com.h2database:h2"
    compile "org.mapstruct:mapstruct-jdk8:${mapstruct_version}"
    testCompile "org.awaitility:awaitility:${awaitility_version}"
    testCompile "com.jayway.jsonpath:json-path"
    testCompile "org.springframework.boot:spring-boot-starter-test"
    testCompile "org.springframework.security:spring-security-test"
    testCompile "org.springframework.boot:spring-boot-test"
    testCompile "org.assertj:assertj-core:${assertj_version}"
    testCompile "junit:junit"
    testCompile "org.mockito:mockito-core"
    testCompile "com.mattbertolini:liquibase-slf4j:${liquibase_slf4j_version}"
    testCompile "org.hamcrest:hamcrest-library"
    optional "org.springframework.boot:spring-boot-configuration-processor:${spring_boot_version}"
    //jhipster-needle-gradle-dependency - JHipster will add additional dependencies here
}

clean {
    delete "target"
}

task cleanResources(type: Delete) {
    delete 'build/resources'
}

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

task stage(dependsOn: 'bootRepackage') {
}

if (project.hasProperty('nodeInstall')) {
    node {
        version = "${node_version}"
        npmVersion = "${npm_version}"
        yarnVersion = "${yarn_version}"
        download = true
    }
}

compileJava.dependsOn processResources
processResources.dependsOn cleanResources,bootBuildInfo
bootBuildInfo.mustRunAfter cleanResources
