/*==========================================================================
 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/>.
===========================================================================*/
apply plugin: 'application'

repositories {
    maven { url 'https://jitpack.io' }
    maven { url 'https://maven.bestsolution.at/efxclipse-releases/' }
    maven {
        url 'https://repo.maven.apache.org/maven2'
        name 'Maven Central'
    }
}

dependencies {
    implementation project(':wilma-application:wilma-domain')
    implementation project(':wilma-application:wilma-stub-configuration-domain')
    implementation "junit:junit:4.13.2"
    implementation 'gsbase:gsbase:2.0.1'
    implementation 'jakarta-regexp:jakarta-regexp:1.4'
    implementation 'com.sun.mail:javax.mail:1.6.2'
    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'net.sf.opencsv:opencsv:2.3'
    implementation group: 'org.springframework', name: 'spring-core', version:"${orgSpringframework}"
    implementation group: 'org.springframework', name: 'spring-jms', version:"${orgSpringframework}"
    implementation group: 'org.mockito', name: 'mockito-core', version: "${mockitoCoreVersion}"
    implementation group: 'at.bestsolution.efxclipse.eclipse', name: 'org.apache.commons.httpclient', version: '3.1.0'
    implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
    implementation 'commons-io:commons-io:2.11.0'
    implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
    implementation 'com.sun.xml.fastinfoset:FastInfoset:2.1.0'
    implementation project(':wilma-service-api')
    implementation group: 'com.github.everit-org.json-schema', name: 'org.everit.json.schema', version: '1.14.1'
    implementation 'org.xmlunit:xmlunit-core:2.9.0'
    implementation 'org.xmlunit:xmlunit-matchers:2.9.0'
    implementation "$javaxServletApi"
    implementation(group: 'org.springframework', name: 'spring-context', version:"${orgSpringframework}")
    implementation(group: 'org.springframework', name: 'spring-test', version:"${orgSpringframework}")
}

sourceSets {
    main {
        java {
            srcDirs 'src'
            srcDirs 'resourceCompile/src'
        }
    }
}

task conditionCheckerJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "conditionchecker"
    archiveVersion = "";
    destinationDirectory = file("$buildDir/../resources/preCompiled")
    includeEmptyDirs = false
    from sourceSets.main.output.classesDirs
    include ("**/sandbox/**/AlwaysTrueCheckerJared.class", "**/sandbox/**/SuperLogic.class")
}

task interceptorJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "interceptor"
    archiveVersion = "";
    destinationDirectory = file("$buildDir/../resources/preCompiled")
    includeEmptyDirs = false
    from sourceSets.main.output.classesDirs
    include ("**/sandbox/**/*InterceptorJared.class", "**/sandbox/**/SuperLogic.class")
}

task responseFormatterJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "responseformatter"
    archiveVersion = "";
    destinationDirectory = file("$buildDir/../resources/preCompiled")
    includeEmptyDirs = false
    from sourceSets.main.output.classesDirs
    include ("**/sandbox/**/TestResponseFormatterJared.class", "**/sandbox/**/SuperLogic.class")
}

task messageSequenceJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "message-sequence"
    archiveVersion = "";
    destinationDirectory = file("$buildDir/../resources/preCompiled")
    includeEmptyDirs = false
    from sourceSets.main.output.classesDirs
    include ("**/message/sequence/test/**/*.class", "**/wilma/sequencesandbox/**/*.class")
}

task sequenceHandlerInJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "sequenceHandlerInJar"
    archiveVersion = "";
    destinationDirectory = file("$buildDir/../resources/preCompiled")
    includeEmptyDirs = false
    from sourceSets.main.output.classesDirs
    include ("**/wilma/sequencesandbox/**/*.class")
}

task twoClassesJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "twoclasses"
    archiveVersion = "";
    destinationDirectory = file("$buildDir/../resources/preCompiled")
    includeEmptyDirs = false
    from sourceSets.main.output.classesDirs
    include ("**/sandbox/two/**/*.class")
}

task templateGeneratorJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "templategenerator"
    archiveVersion = "";
    destinationDirectory = file("$buildDir/../resources/preCompiled")
    includeEmptyDirs = false
    from sourceSets.main.output.classesDirs
    include ("**/sandbox/common/**/*.class", "**/sandbox/templategenerator/**/*.class")
}

task allClassesJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "allclasses"
    archiveVersion = "";
    destinationDirectory = file("$buildDir/../resources/preCompiled")
    includeEmptyDirs = false
    from sourceSets.main.output.classesDirs
    include ("**/sandbox/**/*.class")
}

mainClassName = "com.epam.gepard.AllTestRunner"

def appArgs = ["$buildDir/resources/main/wilma-test.properties,$buildDir/resources/main/gepard.properties"]
applicationDefaultJvmArgs = ["-Xss256k", "-Xmx512M", "-Xms512M", "-Djavax.net.ssl.trustStore=trustStoreForClientsUsingWilma.jks", "-Djavax.net.ssl.trustStorePassword=vvilma", "-DTEID=DEV"]
if ( !hasProperty('buildTag') ) {
    project.ext.buildTag="UNSET"
}
if ( hasProperty('wilmahost') ) {
    applicationDefaultJvmArgs += ["-Dwilma.host=${project.ext.wilmahost}"]
} else {
    applicationDefaultJvmArgs += ["-Dwilma.host=localhost"]
}

task prepareResources (dependsOn:
        [build, conditionCheckerJar, interceptorJar, sequenceHandlerInJar, twoClassesJar, allClassesJar, responseFormatterJar, messageSequenceJar, templateGeneratorJar], type: Copy) {
    from "build/classes/java/main/com/epam/wilma/functionalTest"
    into "resources/preCompiled"
    include "*.class"
}

run {
    dependsOn prepareResources
    doFirst {
        logger.lifecycle('\n ====================================================================')
        logger.lifecycle('\n Running Wilma-Functional Tests with Gepard.')
        logger.lifecycle('\n if you would like to see Gepard output properly, use -q parameter.')
        logger.lifecycle('\n ====================================================================')
        logger.lifecycle('\n')
    }
    args = appArgs
    logging.captureStandardOutput LogLevel.QUIET
}

task runFunctionalTest {
    dependsOn ':wilma-functionaltest:run'
}
