apply plugin: 'war'
apply plugin: 'checkstyle'

evaluationDependsOn(':HIRS_Utils')

sourceCompatibility = 1.8

dependencies {
    compile project(':TPM_Utils')
    compile project(':HIRS_Structs')
    compile project(':HIRS_Utils')

    compile libs.bouncy_castle
    compile libs.commons_codec
    compile libs.commons_lang
    compile libs.spring_webmvc
    compile libs.log4j2
    compile libs.log4j2_web
    compile libs.protobuf_java

    providedCompile libs.servlet_api

    testCompile project(':HIRS_Utils').sourceSets.test.output
    testCompile project(':HIRS_Utils').sourceSets.test.resources

    testCompile libs.commons_lang
    testCompile libs.spring_test
    testCompile libs.mockito
    testCompile libs.testng
    testCompile libs.hsqldb
}

task generateProtoBuf(type:Exec) {
    workingDir 'config'

    commandLine './genJavaProtoBuf.sh'
}

compileJava.dependsOn generateProtoBuf
copyVersion.dependsOn compileJava
war.dependsOn copyVersion

ext.configDir = new File(projectDir, 'config')
ext.checkstyleConfigDir = "$configDir/checkstyle"
checkstyle {
    toolVersion = '5.7'
    configFile = checkstyleConfigFile
    configProperties.put('basedir', checkstyleConfigDir)
    ignoreFailures = false
    showViolations = true
}

war {
    from(buildDir) {
        include 'VERSION'
        into 'WEB-INF/classes'
    }
    archiveName = 'HIRS_AttestationCA.war'
}

publishing {
    publications {
        maven(MavenPublication) {
            artifactId 'hirs-attestationca'
            artifact jar
            pom.withXml {
                def dependenciesNode = asNode().appendNode('dependencies')

                configurations.runtime.allDependencies.each {
                    if (it.group != null && it.name != null) {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', it.group)
                        dependencyNode.appendNode('artifactId', it.name)
                        dependencyNode.appendNode('version', it.version)

                        if (it.excludeRules.size() > 0) {
                            def exclusionsNode = dependencyNode.appendNode('exclusions')
                            it.excludeRules.each { rule ->
                                def exclusionNode = exclusionsNode.appendNode('exclusion')
                                exclusionNode.appendNode('groupId', rule.group)
                                exclusionNode.appendNode('artifactId', rule.module)
                            }
                        }
                    }
                }
            }
	   }
    }
}
