/*
 * 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.
 */

apply plugin: 'java-library'

description = 'S3 Repository'

dependencies {
  implementation platform(project(':platform'))
  api(project(':solr:core'))
  implementation project(':solr:solrj')

  implementation libs.apache.lucene.core

  implementation platform(libs.amazon.awssdk.bom)
  implementation libs.amazon.awssdk.auth
  implementation libs.amazon.awssdk.apacheclient
  implementation libs.amazon.awssdk.awscore
  implementation libs.amazon.awssdk.regions
  implementation libs.amazon.awssdk.httpclient.spi
  implementation libs.amazon.awssdk.retries.spi
  implementation(libs.amazon.awssdk.s3) {
    exclude group: 'software.amazon.awssdk', module: 'netty-nio-client'
  }
  implementation libs.amazon.awssdk.sdkcore

  runtimeOnly(libs.amazon.awssdk.sts) {
    exclude group: 'software.amazon.awssdk', module: 'netty-nio-client'
  }

  implementation libs.google.guava
  implementation libs.slf4j.api

  runtimeOnly libs.fasterxml.woodstox.core
  runtimeOnly libs.codehaus.woodstox.stax2api

  testImplementation project(':solr:test-framework')
  testImplementation libs.apache.lucene.testframework
  testImplementation libs.carrotsearch.randomizedtesting.runner
  testImplementation libs.junit.junit
  testImplementation libs.amazon.awssdk.profiles

  testImplementation libs.hamcrest.hamcrest

  testImplementation(libs.adobe.testing.s3mock.junit4) {
    // Don't pull in separate versions of these libs, just use what Solr already has
    exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
    exclude group: 'ch.qos.logback', module: 'logback-classic'
    exclude group: 'org.eclipse.jetty', module: '*'
    exclude group: 'io.netty', module: '*'
    exclude group: 'commons-io', module: 'commons-io'
    exclude group: 'commons-codec', module: 'commons-codec'
    exclude group: 'org.apache.commons', module: 'commons-lang3'
    exclude group: 'software.amazon.awssdk', module: 'netty-nio-client'
    exclude group: 'org.codehaus.woodstox', module: 'stax2-api'
  }
  testImplementation(libs.adobe.testing.s3mock.testsupportcommon) {
    // Don't pull in separate versions of these libs, just use what Solr already has
    exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
    exclude group: 'ch.qos.logback', module: 'logback-classic'
    exclude group: 'org.eclipse.jetty', module: '*'
    exclude group: 'io.netty', module: '*'
    exclude group: 'commons-io', module: 'commons-io'
    exclude group: 'commons-codec', module: 'commons-codec'
    exclude group: 'org.apache.commons', module: 'commons-lang3'
    exclude group: 'software.amazon.awssdk', module: 'netty-nio-client'
    exclude group: 'org.codehaus.woodstox', module: 'stax2-api'
  }

  testImplementation libs.commonsio.commonsio

  testRuntimeOnly libs.eclipse.jetty.ee10.webapp

  testImplementation(libs.mockito.core, {
    exclude group: "net.bytebuddy", module: "byte-buddy-agent"
  })
  testRuntimeOnly(libs.mockito.subclass, {
    exclude group: "net.bytebuddy", module: "byte-buddy-agent"
  })
}

test {
  // S3Mock uses Spring Boot under the hood, which tries to do too much auto configuration that we don't want
  environment "spring.autoconfigure.exclude", "org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration"
  environment "spring.jmx.enabled", "false"

  // Without this, randomizedtesting will think our tests leak threads (b/c S3Mock's Jetty hasn't bothered to clean up yet)
  environment "server.jetty.threads.idle-timeout", "1s"

  // Reduce logging noise during the tests
  environment "aws.accessKeyId", "foo"
  environment "aws.secretAccessKey", "bar"
}
