description = 'BX-bot Exchange Adapters'

dependencies {

  implementation project(':bxbot-trading-api')
  implementation project(':bxbot-exchange-api')

  implementation libraries.spring_boot_starter
  implementation libraries.spring_boot_starter_log4j2
  implementation libraries.google_gson
  implementation libraries.google_guava

  implementation libraries.jakarta_xml_api

  compileOnly libraries.lombok
  annotationProcessor libraries.lombok

  testImplementation libraries.powermock_junit
  testImplementation libraries.powermock_api_easymock
  testImplementation libraries.easymock
  testImplementation libraries.junit_vintage_engine
  testImplementation libraries.spring_boot_starter_test
}

sourceSets {
  integrationTests {
    compileClasspath += sourceSets.main.output
    runtimeClasspath += sourceSets.main.output

    java.srcDir 'src/integration-test/java'
    resources.srcDir 'src/integration-test/resources'
  }
}

task integrationTests(type: Test) {
  description = "Run integration tests"
  group = "verification"
  testClassesDirs = sourceSets.integrationTests.output.classesDirs
  classpath = sourceSets.integrationTests.runtimeClasspath
}

integrationTests {
  testLogging {
    events "passed", "skipped", "failed"
  }

  // See: https://stackoverflow.com/questions/69896191/powermock-compatibility-with-jdk-17
  jvmArgs "--add-opens", "java.base/java.util=ALL-UNNAMED"
}

configurations {
  integrationTestsImplementation.extendsFrom(testImplementation)
  integrationTestsRuntimeOnly.extendsFrom(testRuntimeOnly)
}

// For Powermock tests messing with JDK 17+ bytecode.
// See: https://stackoverflow.com/questions/69896191/powermock-compatibility-with-jdk-17
test.jvmArgs "--add-opens", "java.base/java.lang=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.util=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.util.stream=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.text=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.io=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.nio.file=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.math=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.time=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.security=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/java.net=ALL-UNNAMED"
test.jvmArgs "--add-opens", "java.base/sun.net.www.protocol.https=ALL-UNNAMED"

jacocoTestCoverageVerification {
  violationRules {
    rule {
      element = 'CLASS'
      // Ignore classes tested using Powermock. JaCoCo won't/can't instrument them:
      // "... right now there is NO WAY TO USE PowerMock with JaCoCo On-the-fly instrumentation."
      // See: https://github.com/powermock/powermock/wiki/Code-coverage-with-JaCoCo
      excludes = [
          'com.gazbert.bxbot.exchanges.*' // * needed for the inner classes
      ]
      limit {
        counter = 'LINE'
        value = 'COVEREDRATIO'
        minimum = 0.8
      }
    }
  }
}