plugins {
	id 'java-library'
	id 'distribution'
	id 'maven-publish'
}

java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(25)
	}

	withSourcesJar()
}

dependencies {
	// 1. Core Framework
	api project(':core')

	// 2. Web APIs
	compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
	compileOnly 'javax.websocket:javax.websocket-api:1.1'

	testImplementation 'javax.servlet:javax.servlet-api:4.0.1'
	testImplementation 'javax.websocket:javax.websocket-api:1.1'

	// 3. OpenSearch (replaces Elasticsearch 2.4.6 + Lucene 5; Lucene 10 comes transitively)
	// Engine swap only — Elastic* class/package/bean names kept for now.
	api 'org.opensearch:opensearch:3.8.0'
	api 'org.opensearch.plugin:transport-netty4-client:3.8.0'
	// Built-in analyzers (mapping char_filter, snowball/stemmer/elision/asciifolding, etc.)
	// live in analysis-common; the embedded node must load it as a plugin.
	api 'org.opensearch.plugin:analysis-common:3.8.0'
	// geo_point aggregations (geohash_grid, geotile_grid, geo_bounds) live in the geo
	// module; the embedded node must load it as a plugin.
	api 'org.opensearch.plugin:geo:3.8.0'

	// Direct Lucene searcher (org.entermediadb.lucene) — same Lucene line as OpenSearch 3.8.
	api 'org.apache.lucene:lucene-core:10.5.0'
	api 'org.apache.lucene:lucene-analysis-common:10.5.0'
	api 'org.apache.lucene:lucene-facet:10.5.0'

	// 5. Jackson
	api 'com.fasterxml.jackson.core:jackson-core:2.8.1'
	api 'com.fasterxml.jackson.core:jackson-databind:2.8.1'
	api 'com.fasterxml.jackson.core:jackson-annotations:2.8.1'
	api 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.8.1'
	api 'com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.8.1'
	api 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.1'

	// 6. Media — modular pdfbox (not fat pdfbox-app)
	api 'org.apache.pdfbox:pdfbox:2.0.24'
	api 'org.apache.poi:poi:5.3.0'
	api 'com.googlecode.mp4parser:isoparser:1.1.22'
	api 'org.jsoup:jsoup:1.18.1'

	// 7. Utilities
	api 'javax.mail:mail:1.4.7'
	api 'javax.activation:activation:1.1'
	api 'com.warrenstrange:googleauth:1.5.0'
	api 'com.google.code.gson:gson:2.10.1'
	api 'joda-time:joda-time:2.9.5'
	api 'com.jcraft:jsch:0.1.55'
	api 'org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.1'
	api 'org.apache.httpcomponents:httpmime:4.5.2'

	// 8. Scripting
	api 'bsf:bsf:2.4.0'
	api 'org.mozilla:rhino:1.7R4'
	api 'org.antlr:antlr-runtime:3.5'
	api 'org.apache.velocity.tools:velocity-tools-generic:3.1'
	api 'org.apache-extras.beanshell:bsh:2.0b6'

	// 9. Logging
	api 'log4j:log4j:1.2.17'
	api 'log4j:apache-log4j-extras:1.2.17'

	// 10. Misc
	api 'commons-fileupload:commons-fileupload:1.4'
	api 'commons-net:commons-net:3.9.0'

	implementation fileTree(dir: 'lib', include: [
		'java-version-checker-5.6.3.jar',
		'plugin-cli-5.6.3.jar',
		'compiler-0.8.13.jar'
	])

	testImplementation platform('org.junit:junit-bom:5.13.4')
	testImplementation 'org.junit.jupiter:junit-jupiter'
	testImplementation 'org.apache.ant:ant:1.10.12'
}

test {
	useJUnitPlatform()
	enabled = false
}

tasks.withType(JavaCompile).configureEach {
	options.encoding = 'UTF-8'
	options.compilerArgs += [
		'-Xlint:none',
		'-Xlint:-dep-ann',
		'-Xmaxerrs',
		'2000'
	]
}

// plugin.xml / depends.xml live next to Java (ThoughtFrame layout); put them on the classpath.
// Keep include broad enough that src/main/resources (*.properties) is still packaged.
sourceSets {
	main {
		resources {
			srcDir 'src/main/java'
			include '**/*.xml'
			include '**/*.properties'
		}
	}
}

tasks.register('runtimeZip', Zip) {
	archiveClassifier = 'runtime'

	from('webapp') {
		exclude 'WEB-INF/base/archive/**'
		exclude 'WEB-INF/base/search/**'
	}
}

publishing {
	publications {
		mavenJava(MavenPublication) {
			from components.java
			artifact(tasks.runtimeZip)
		}
	}
}
