import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
	id 'application'
	id 'java'
	id 'idea'
	id "com.github.johnrengelman.shadow" version "5.1.0"
	id "org.javamodularity.moduleplugin" version "1.6.0"
	id 'org.jetbrains.kotlin.jvm' version '1.3.50'
	id "org.beryx.jlink" version "2.16.2"
}

mainClassName = 'holocore/com.projectswg.holocore.ProjectSWG'

sourceSets {
	main
	display
	utility
	integration
}

test {
	afterSuite { TestDescriptor td, TestResult tr ->
		if (td.parent == null) {
			println 'Tests run: (' + tr.getTestCount() + '), Failures: (' + tr.getFailedTestCount() + ')' // IMPORTANT - this is required for Lightspeed
		}
	}
}

idea {
    module {
        inheritOutputDirs = true
    }
}

jlink {
//	addOptions '--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'
	imageDir.set(file("$buildDir/holocore"))
	imageZip.set(file("$buildDir/holocore.zip"))
	launcher {
		name = 'holocore'
		jvmArgs = []
		unixScriptTemplate = file('src/main/resources/jlink-unix-launch-template.txt')
	}
}

shadowJar {
	archivesBaseName = 'Holocore'
	archiveClassifier.set(null)
	archiveVersion.set(null)
}

repositories {
	jcenter()
}

dependencies {
	compile project(':pswgcommon')
	
	compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.3.50'
	compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.3.0'
	compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
	compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.5.2'
	compile group: 'org.mongodb', name: 'mongodb-driver-sync', version: '3.11.0'
	compile group: 'me.joshlarson', name: "fast-json", version: '3.0.0'
	compile group: 'me.joshlarson', name: 'jlcommon-network', version: '1.0.0'
	compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
	
	testCompile 'junit:junit:4.12'
	
	displayCompile project(':pswgcommon')
	displayCompile sourceSets.main.output
	
	utilityCompile project(':pswgcommon')
	utilityCompile sourceSets.main.output
	utilityCompile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.3.50'
	utilityCompile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.23.1'
	utilityCompile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.6.3'
	utilityCompile group: 'me.joshlarson', name: "fast-json", version: '3.0.0'
	
	integrationCompile project(':pswgcommon')
	integrationCompile project(':client-holocore')
	integrationCompile sourceSets.main.output
	integrationCompile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.23.1'
	integrationCompile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.6.3'
	integrationCompile 'junit:junit:4.12'
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
		jvmTarget = "12"
	}
}

task CreateConvertLoginJar(type: ShadowJar) {
	archivesBaseName = "ConvertLogin"
	archiveClassifier.set(null)
	archiveVersion.set(null)
	manifest.attributes 'Main-Class': 'com.projectswg.utility.ConvertLogin'
	from sourceSets.utility.output
	configurations = [project.configurations.utilityRuntime]
	exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
}

task CreatePacketCaptureProcessor(type: ShadowJar) {
	archivesBaseName = "PacketCaptureProcessor"
	archiveClassifier.set(null)
	archiveVersion.set(null)
	manifest.attributes 'Main-Class': 'com.projectswg.utility.packets.ProcessPacketCapture'
	from sourceSets.utility.output
	configurations = [project.configurations.utilityRuntime]
	exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA')
}
