plugins {
    id 'rhino.java-conventions'
    id 'jacoco'
    id 'jacoco-report-aggregation'
}

dependencies {
    implementation project(':rhino-engine')
    implementation project(':examples')
    implementation project(':rhino')
    implementation project(':rhino-tools')
    implementation project(':rhino-xml')

    testImplementation project(':testutils')
    testImplementation("com.tngtech.archunit:archunit-junit4:1.3.0") {
        exclude group: 'junit'
    }
    testImplementation("org.slf4j:slf4j-simple:2.0.16")
}

tasks.withType(JavaCompile) {
    // We have deprecated things, like "optimization level", and have
    // not yet removed them from all tests, so turn this warning off.
    options.compilerArgs = [
            '-Xlint:-deprecation'
    ]
}

test {
    testLogging.showStandardStreams = true
    maxHeapSize = "1g"
    // Many tests do not clean up contexts properly. This makes the tests much
    // more resilient at the expense of performance.
    forkEvery = 1
    maxParallelForks = 64

    // Properties required for the legacy Mozilla tests. Tests will fail unless
    // the time zone and other properties are set as shown below
    systemProperty 'java.awt.headless', 'true'
    systemProperty 'mozilla.js.tests', 'testsrc/tests'
    systemProperty 'mozilla.js.tests.timeout', 60000
    systemProperty 'user.language', 'en'
    systemProperty 'user.country', 'US'
    systemProperty 'user.timezone', 'America/Los_Angeles'
    systemProperty 'file.encoding', 'UTF-8'

    // Required for JWT GUI tests
    jvmArgs += ['--add-opens', 'java.desktop/javax.swing.table=ALL-UNNAMED']
    // Required for some reflection tests
    jvmArgs += ['--add-opens', 'java.base/java.util=ALL-UNNAMED']
    jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED']

    systemProperty 'test262properties', System.getProperty('test262properties')
    if (System.getProperty('updateTest262properties') != null) {
        if (System.getenv("RHINO_TEST_JAVA_VERSION") != "11") {
            System.out.println("Test262 properties update is only accurate on Java 11 and you have " + JavaVersion.current())
            System.out.println("Set RHINO_TEST_JAVA_VERSION in the environment to use this feature")
            throw new Exception("Incorrect Java version for Test 262 properties update")
        }
        systemProperty 'updateTest262properties', System.getProperty('updateTest262properties')
    }

    jacoco {
        // These particular tests produce Jacoco exceptions because of their size
        excludes = ['**perlstress**', '**start_unicode**']
    }
}

jacocoTestReport {
    reports {
        xml.required = false
        csv.required = false
        html.outputLocation = layout.buildDirectory.dir('reports/jacoco')
    }
}
