import org.gradle.internal.os.OperatingSystem
plugins {
    id 'java'
}

description = 'Provides database access and connectivity'
group 'edu.msudenver.tsp'
version '1.0'

sourceCompatibility = 1.8

sonarqube {
    properties {
        property "sonar.projectName", 'Pandamonium Persistence Tier'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.0.5.RELEASE'
    compile group: 'org.apache.tomcat', name: 'tomcat-jdbc', version: '9.0.16'
    compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.0.5.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.5.RELEASE'
    compile group: 'org.springframework', name: 'spring-aspects', version: '5.1.5.RELEASE'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.1.Final'
    compile group: 'com.vladmihalcea', name: 'hibernate-types-52', version: '2.4.1'

    compile fileTree(dir: 'lib', include: '**/*.jar')

    compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15'
    compile('com.googlecode.log4jdbc:log4jdbc:1.2') {
        exclude(group: 'org.slf4j')
    }

    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.2.RELEASE'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile 'javax.el:javax.el-api:3.0.0'

}

task loadDb(type: Exec, group: 'Verification', description: 'Reloads the local database.') {
    if (OperatingSystem.current().isLinux() || OperatingSystem.current().isMacOsX()) {
        workingDir "./scripts/mysql"
        commandLine './loaddb.sh'
    } else {
        workingDir "./scripts/mysql"
        commandLine=['cmd','/c','loaddb.bat']
    }
}

task startPersistenceApi(type: JavaExec, description: 'Starts the Persistence API') {
    dependsOn 'loadDb'
    dependsOn 'build'
    classpath = files('build/libs/persistence-1.0.jar')
    classpath += sourceSets.main.runtimeClasspath
    main = 'edu.msudenver.tsp.persistence.PersistenceApi'
}
