plugins {
	id 'java-library'
	id 'java-test-fixtures'
	id 'maven-publish'
}

group = 'org.sensortech'
version = '0.1.0'

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

	withSourcesJar()
	withJavadocJar()
}

repositories {
	mavenLocal()
	mavenCentral()
}

test {
	useJUnitPlatform {
		excludeTags 'fixture'
	}
}

// Fixture/integration tests are opt-in until the standalone core test webapp is
// fully configured (the modern JUnit 5 suite is the default).
tasks.register('fixtureTest', Test) {
	group = 'verification'
	description = 'Runs the JUnit 5 fixture/integration tests (requires a configured test webapp).'
	testClassesDirs = sourceSets.test.output.classesDirs
	classpath = sourceSets.test.runtimeClasspath
	useJUnitPlatform {
		includeTags 'fixture'
	}
	shouldRunAfter tasks.named('test')
	testLogging { events 'failed' }
}

dependencies {
	// Platform
	compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
	testImplementation 'javax.servlet:javax.servlet-api:4.0.1'

	// Foundation
	api 'org.apache.commons:commons-lang3:3.7'
	api 'commons-io:commons-io:2.6'
	api 'commons-codec:commons-codec:1.9'
	api 'commons-collections:commons-collections:3.2.2'
	api 'commons-logging:commons-logging:1.2'

	// HTTP
	api 'org.apache.httpcomponents:httpclient:4.5.2'
	api 'org.apache.httpcomponents:httpcore:4.4.4'
	api 'org.apache.httpcomponents:httpmime:4.5.2'

	// Templates & Runtime Scripting
	api 'org.apache.velocity:velocity-engine-core:2.4.1'
	api 'org.apache.groovy:groovy-all:6.0.0'

	// Native
	api 'net.java.dev.jna:jna:4.1.0'
	api 'net.java.dev.jna:jna-platform:4.1.0'

	// XML / JSON
	api('org.dom4j:dom4j:2.1.3') {
		// Registers org.gjt.xpp as JAXP SAXParserFactory; breaks Jetty web.xml DOCTYPE parse
		// when that jar sorts ahead of Xerces on the Eclipse launch classpath.
		exclude group: 'pull-parser', module: 'pull-parser'
		exclude group: 'xpp3', module: 'xpp3'
	}
	api 'com.google.guava:guava:18.0'
	api 'com.googlecode.json-simple:json-simple:1.1.1'
	api 'aopalliance:aopalliance:1.0'

	// Testing
	testImplementation platform("org.junit:junit-bom:${junitVersion}")
	testImplementation 'org.junit.jupiter:junit-jupiter'

	// Shared JUnit 5 fixture base (BaseJUnit5Test) used by :core and :dam tests
	testFixturesImplementation platform("org.junit:junit-bom:${junitVersion}")
	testFixturesImplementation 'org.junit.jupiter:junit-jupiter-api'

	testImplementation 'org.springframework:spring-core:3.2.1.RELEASE'
	testImplementation 'org.springframework:spring-beans:3.2.1.RELEASE'
	testImplementation 'org.springframework:spring-context:3.2.1.RELEASE'
	testImplementation 'org.springframework:spring-expression:3.2.1.RELEASE'
}

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

tasks.withType(Javadoc).configureEach {
	enabled = false
}

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

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

// The Eclipse bin/ output tree is not a build input, but a stale resource copy inside it can
// collide with the real one under src/ - Gradle 9 fails on duplicate archive entries where older
// versions silently included them. Same strategy thoughtframe's createWar already sets.
tasks.withType(Jar).configureEach {
	duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
