/*==========================================================================
Copyright since 2013, EPAM Systems

This file is part of Wilma.

Wilma 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.

Wilma 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 Wilma.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================*/
description = 'wilma application'

task docs(type: Javadoc) {
    destinationDir = file("$buildDir/docs/all")
    options.memberLevel = JavadocMemberLevel.PRIVATE
    for (subproject in project.subprojects) {
        if (subproject.plugins.hasPlugin(JavaPlugin)){
            source += files(subproject.sourceSets.main.java)
            classpath += files(subproject.sourceSets.main.compileClasspath)
        }
    }
}

task checkstyle(type: Checkstyle) {
    dependsOn subprojects.checkstyleMain
}

task deleteRelease(type: Delete) {
    dependsOn ":wilma-application:wilma-engine:shadowJar"
    delete rootProject.rootDir.absolutePath + '/wilma-application/release'
}

def myCopySpec = project.copySpec {
    from(rootProject.rootDir.absolutePath + '/wilma-application/modules/wilma-engine/') {
        include 'wilma.conf.properties'
        include 'readme.txt'
        include 'stubConfig.json'
    }
    from(rootProject.rootDir.absolutePath + '/wilma-application/modules/wilma-engine/build/libs/') {
        include "wilma-engine-$version" + '-all.jar'
    }
    from(rootProject.rootDir.absolutePath + '/wilma-application/resources/'){
        include 'certificate/wilma.cer'
        include 'certificate/wilma.jks'
    }
    from(rootProject.rootDir.absolutePath + '/') {
        include 'COPYRIGHT.txt'
        include 'COPYRIGHTS/'
    }
}

task copyToReleaseRoot (type: Copy) {
	dependsOn deleteRelease
	into(rootProject.rootDir.absolutePath + '/wilma-application/release')
    rename "wilma-engine-$version" + '-all.jar', "wilma-" + "$version" + ".jar"
	with myCopySpec
}

task createDir {
	dependsOn copyToReleaseRoot
	doLast{
	    file(rootProject.rootDir.absolutePath + '/wilma-application/release/config/templates').mkdirs()
        file(rootProject.rootDir.absolutePath + '/wilma-application/release/config/formatters').mkdirs()
        file(rootProject.rootDir.absolutePath + '/wilma-application/release/config/interceptors').mkdirs()
        file(rootProject.rootDir.absolutePath + '/wilma-application/release/config/cache/stub_descriptors').mkdirs()
        file(rootProject.rootDir.absolutePath + '/wilma-application/release/config/condition-checkers').mkdirs()
        file(rootProject.rootDir.absolutePath + '/wilma-application/release/config/jar').mkdirs()
        file(rootProject.rootDir.absolutePath + '/wilma-application/release/config/sequencehandlers').mkdirs()
	}
}

task release(type: Zip) {
	dependsOn createDir
    from rootProject.rootDir.absolutePath + '/wilma-application/release'
}

subprojects {

    repositories {
        maven { url "https://repository.jboss.org/nexus/content/groups/public" }
        maven { url 'https://jitpack.io' }
    }
    
    
    dependencies {
        implementation(group: 'org.springframework', name: 'spring-context', version:"${orgSpringframework}")
        implementation group: 'ch.qos.logback', name: 'logback-classic', version:"${logbackVersion}"
        implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: "${orgSfl4jVersion}"
        implementation group: 'org.slf4j', name: 'jul-to-slf4j', version: "${orgSfl4jVersion}"
        implementation group: 'commons-io', name: 'commons-io', version:'2.11.0'
        implementation group: 'org.codehaus.janino', name: 'janino', version: '3.1.9'
        implementation group: 'net.sf.saxon', name: 'Saxon-HE', version:'12.0'
        testImplementation group: 'org.mockito', name: 'mockito-core', version: "${mockitoCoreVersion}"
        testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: "${mockitoCoreVersion}"
        testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: "${jUnitVersion}"
        testImplementation(group: 'org.springframework', name: 'spring-test', version:"${orgSpringframework}")
        testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${jUnitVersion}"
    }

    test.useJUnitPlatform()
}
