plugins {
    id 'java'
}

group 'armardillo_server'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8
def mainClassName = "armadillo.Application"
jar {
    manifest {
        attributes "Main-Class": "$mainClassName"
    }
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}
repositories {
    mavenCentral()
}
configurations {
    mybatisGenerator
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile project(":base")
    compile fileTree(dir:'libs',includes:['*jar'])
    // https://mvnrepository.com/artifact/com.gitee.sunchenbin.mybatis.actable/mybatis-enhance-actable
    compile group: 'com.gitee.sunchenbin.mybatis.actable', name: 'mybatis-enhance-actable', version: '1.0.8.1.RELEASE'
    // https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
    testCompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
    // https://mvnrepository.com/artifact/org.slf4j/slf4j-api
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    testCompile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
    // https://mvnrepository.com/artifact/org.ow2.asm/asm-debug-all
    compile group: 'org.ow2.asm', name: 'asm-debug-all', version: '5.0.3'
    // https://mvnrepository.com/artifact/commons-cli/commons-cli
    compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
    // https://mvnrepository.com/artifact/io.netty/netty-all
    compile group: 'io.netty', name: 'netty-all', version: '4.1.56.Final'
    // https://mvnrepository.com/artifact/io.netty/netty-transport-native-epoll
    compile group: 'io.netty', name: 'netty-transport-native-epoll', version: '4.1.56.Final'


    mybatisGenerator 'org.mybatis.generator:mybatis-generator-core:1.3.5'
    mybatisGenerator 'mysql:mysql-connector-java:5.1.40'
    mybatisGenerator 'tk.mybatis:mapper:3.3.9'
}
def getDbProperties = {
    def properties = new Properties()
    file("src/main/resources/mybatis/config.properties").withInputStream { inputStream ->
        properties.load(inputStream)
    }
    properties
}
task mybatisGenerate << {
    def properties = getDbProperties()
    ant.properties['targetProject'] = projectDir.path
    ant.properties['driverClass'] = properties.getProperty("jdbc.driverClassName")
    ant.properties['connectionURL'] = properties.getProperty("jdbc.url")
    ant.properties['userId'] = properties.getProperty("jdbc.username")
    ant.properties['password'] = properties.getProperty("jdbc.password")
    ant.properties['src_main_java'] = sourceSets.main.java.srcDirs[0].path
    ant.properties['src_main_resources'] = sourceSets.main.resources.srcDirs[0].path
    ant.properties['modelPackage'] = properties.getProperty("package.model")
    ant.properties['mapperPackage'] = properties.getProperty("package.mapper")
    ant.properties['sqlMapperPackage'] = properties.getProperty("package.xml")
    ant.taskdef(
            name: 'mbgenerator',
            classname: 'org.mybatis.generator.ant.GeneratorAntTask',
            classpath: configurations.mybatisGenerator.asPath
    )
    ant.mbgenerator(overwrite: true,
            configfile: 'src/main/resources/mybatis/generatorConfig.xml', verbose: true) {
        propertyset {
            propertyref(name: 'targetProject')
            propertyref(name: 'userId')
            propertyref(name: 'driverClass')
            propertyref(name: 'connectionURL')
            propertyref(name: 'password')
            propertyref(name: 'src_main_java')
            propertyref(name: 'src_main_resources')
            propertyref(name: 'modelPackage')
            propertyref(name: 'mapperPackage')
            propertyref(name: 'sqlMapperPackage')
        }
    }
}
