/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

plugins {
    id 'java'
}

// Configure source sets with proper output directories
sourceSets {
    test {
        java {
            destinationDirectory = layout.buildDirectory.dir('classes/java/test').get().asFile
        }
        resources {
            destinationDirectory = layout.buildDirectory.dir('resources/test').get().asFile
        }
    }
}

repositories {
    mavenCentral()
}

// Configure test compilation
tasks.named('compileTestJava') {
    description = 'Compiles test Java source files'

    // Enable caching
    outputs.cacheIf { true }

    // Configure compiler options
    options.compilerArgs.add("-parameters")

    // Ensure proper output tracking
    outputs.dir(sourceSets.test.java.destinationDirectory)
        .withPropertyName("testClassesDir")

    // Track annotation processor outputs
    options.annotationProcessorGeneratedSourcesDirectory = 
        layout.buildDirectory.dir('generated/sources/annotationProcessor/java/test').get().asFile
}

dependencies {
    testImplementation(project(':fineract-avro-schemas'))
    testImplementation(project(':fineract-client'))

    testImplementation 'org.springframework:spring-context'
    implementation 'org.springframework:spring-test'
    testImplementation 'org.springframework:spring-jms'

    testImplementation 'com.github.spotbugs:spotbugs-annotations'

    testImplementation 'com.squareup.retrofit2:retrofit:2.11.0'
    testImplementation 'org.apache.httpcomponents:httpclient:4.5.14'
    testImplementation 'org.apache.commons:commons-lang3:3.18.0'
    testImplementation ('com.googlecode.json-simple:json-simple:1.1.1') {
        exclude group: 'junit', module: 'junit'
    }
    testImplementation 'com.google.code.gson:gson:2.11.0'

    testImplementation 'io.cucumber:cucumber-java:7.20.1'
    testImplementation 'io.cucumber:cucumber-junit:7.20.1'
    testImplementation 'io.cucumber:cucumber-spring:7.20.1'
    testImplementation 'io.cucumber:cucumber-junit-platform-engine:7.20.1'

    testImplementation 'io.qameta.allure:allure-cucumber7-jvm:2.29.1'

    testImplementation 'org.assertj:assertj-core:3.26.3'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.11.3'

    testCompileOnly 'org.projectlombok:lombok:1.18.36'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.36'

    testImplementation "ch.qos.logback:logback-core:1.5.17"
    testImplementation "ch.qos.logback:logback-classic:1.5.17"

    testImplementation 'org.apache.activemq:activemq-client:6.1.6'
    testImplementation "org.apache.avro:avro:1.12.0"
    testImplementation "org.awaitility:awaitility:4.2.2"
    testImplementation 'io.github.classgraph:classgraph:4.8.179'

    testImplementation 'org.apache.commons:commons-collections4:4.4'
}

tasks.withType(JavaCompile).configureEach {
    options.compilerArgs.add("-parameters")
}

// Configure the jar task to include test classes and resources
tasks.named('jar') {
    from sourceSets.test.output
    
    // Include the test resources
    from(sourceSets.test.resources) {
        // Handle duplicate files by using the first one found
        duplicatesStrategy = DuplicatesStrategy.INCLUDE
    }
    
    // Include the manifest with the classpath
    manifest {
        attributes(
            'Implementation-Title': project.name,
            'Implementation-Version': project.version,
            'Built-By': System.getProperty('user.name'),
            'Built-Date': new Date(),
            'Created-By': 'Gradle ' + gradle.gradleVersion,
            'Build-Jdk': System.getProperty('java.version')
        )
    }
}
