/*==========================================================================
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/>.
===========================================================================*/

ext.componentDescription = "Wilma Test Server"

apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'

buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0'
    }
}

mainClassName = 'com.epam.wilma.test.server.WilmaTestServerApplication'

shadowJar {
    excludes = [
		'META-INF/*.SF',
		'META-INF/*.DSA',
		'META-INF/*.RSA'
		]
}

jar {
    manifest.attributes( 'provider': 'gradle')
    manifest.attributes( 'Main-Class': mainClassName)
    manifest.attributes( 'Implementation-Title': "$componentDescription - V" + archiveVersion.get())

    finalizedBy shadowJar
}

dependencies {
    implementation group: 'org.slf4j', name: 'slf4j-api', version: "${orgSfl4jVersion}"
    implementation group: 'ch.qos.logback', name: 'logback-classic', version: "${logbackVersion}"
    implementation group: 'org.eclipse.jetty', name: 'jetty-server', version:"${jettyVersion}"
    implementation group: 'org.eclipse.jetty', name: 'jetty-servlet', version:"${jettyVersion}"
    implementation group: 'org.eclipse.jetty', name: 'jetty-webapp', version:"${jettyVersion}"
    implementation group: 'org.eclipse.jetty', name: 'jetty-servlets', version:"${jettyVersion}"
    implementation group: 'commons-io', name: 'commons-io', version:'2.11.0'
    implementation group: 'com.sun.xml.fastinfoset', name: 'FastInfoset', version:"${FastInfoSetVersion}"
    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}"
    testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: "${jUnitVersion}"
    testImplementation group: 'cglib', name: 'cglib', version:'3.3.0'
}

test.useJUnit()

def myCopySpec = project.copySpec {
    from(rootProject.rootDir.absolutePath + '/wilma-test/wilma-test-server/') {
        include 'wilma.testserver.properties'
        include 'certificate/WilmaTestServer.cer'
        include 'certificate/wilmaTestServer.jks'
    }
    from(rootProject.rootDir.absolutePath + '/wilma-test/wilma-test-server/build/libs/') {
        include "wilma-test-server-$version" + '-all.jar'
    }
}

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

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

run {
    args 'wilma.testserver.properties'
}