/*
 * 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 'standard-subproject-configuration'
  id 'war'
  id 'geode-publish-war'
  id 'warnings'
  id 'nebula.facet'
}

jar.enabled = false

facets {
  commonTest {
    testTaskName = 'commonTest'
    includeInCheckLifecycle = false
  }
}

commonTest {
  useJUnitPlatform()
}

sourceSets {
  integrationTest {
    resources {
      srcDir "${projectDir}/src/main/webapp"
    }
  }

  distributedTest {
    resources {
      srcDir "${projectDir}/src/main/webapp"
    }
  }
}

configurations {
  war {}
}
dependencies {
  api(platform(project(':boms:geode-all-bom'))) {
    exclude module: "jackson-annotations"
  }
  compileOnly(project(':geode-logging'))
  compileOnly(project(':geode-serialization'))
  compileOnly(project(':geode-core'))

  compileOnly('javax.servlet:javax.servlet-api')
  // jackson-annotations must be accessed from the geode classloader and not the webapp
  compileOnly('com.fasterxml.jackson.core:jackson-annotations')

  implementation('org.apache.commons:commons-lang3')
  implementation('commons-fileupload:commons-fileupload') {
    exclude module: 'commons-io'
  }
  implementation('com.fasterxml.jackson.core:jackson-core')
  implementation('com.fasterxml.jackson.core:jackson-databind') {
    exclude module: 'jackson-annotations'
  }

  implementation('org.springdoc:springdoc-openapi-ui') {
    exclude module: 'slf4j-api'
    exclude module: 'jackson-annotations'
  }

  implementation('org.springframework:spring-beans')
  implementation('org.springframework.security:spring-security-core')
  implementation('org.springframework.security:spring-security-web')
  implementation('org.springframework.security:spring-security-config')
  implementation('org.springframework:spring-web')
  implementation('org.springframework:spring-webmvc')
  implementation('org.springframework.hateoas:spring-hateoas') {
    exclude module: 'aopalliance'
    exclude module: 'commons-logging'
    exclude module: 'objenesis'
    exclude module: 'slf4j-api'
    exclude module: 'spring-core'
    exclude module: 'spring-plugin-core'
  }
  implementation('org.springframework:spring-aspects') {
    exclude module: 'aopalliance'
    exclude module: 'aspectjweaver'
  }
  implementation('org.springframework:spring-oxm') {
    exclude module: 'commons-logging'
    exclude module: 'spring-core'
    exclude module: 'spring-beans'
  }
  compileOnly('org.apache.logging.log4j:log4j-api')

  commonTestImplementation(project(':geode-core'))
  commonTestImplementation(project(':geode-junit')) {
    exclude module: 'geode-core'
  }
  commonTestImplementation(project(':geode-dunit')) {
    exclude module: 'geode-core'
  }
  commonTestImplementation('org.springframework:spring-test')
  commonTestImplementation('org.springframework:spring-webmvc')
  commonTestImplementation('org.springframework.security:spring-security-test')
  commonTestImplementation(project(':geode-web-management'))

  testImplementation(project(':geode-junit')) {
    exclude module: 'geode-core'
  }
  testImplementation(project(':geode-core'))
  testImplementation('javax.servlet:javax.servlet-api')

  integrationTestImplementation(sourceSets.commonTest.output)

  integrationTestImplementation(project(':geode-core'))
  integrationTestImplementation('org.springframework:spring-test')
  integrationTestImplementation('org.springframework:spring-webmvc')
  integrationTestImplementation('org.springframework.security:spring-security-test')

  integrationTestImplementation(project(':geode-junit')) {
    exclude module: 'geode-core'
  }
  integrationTestImplementation(project(':geode-dunit')) {
    exclude module: 'geode-core'
  }
  integrationTestRuntimeOnly('org.apache.logging.log4j:log4j-slf4j-impl') {
    exclude module: 'slf4j-api'
  }

  distributedTestImplementation(sourceSets.commonTest.output)

  distributedTestImplementation('org.springframework:spring-test')
  distributedTestImplementation('org.springframework:spring-webmvc')
  distributedTestImplementation('org.springframework.security:spring-security-test')

  distributedTestImplementation(project(':geode-core'))
  distributedTestImplementation(project(':geode-junit')) {
    exclude module: 'geode-core'
  }
  distributedTestImplementation(project(':geode-dunit')) {
    exclude module: 'geode-core'
  }

  distributedTestRuntimeOnly('org.apache.logging.log4j:log4j-slf4j-impl') {
    exclude module: 'slf4j-api'
  }
}

war {
  enabled = true
  rootSpec.exclude("**/*commons-logging-*.jar")
  duplicatesStrategy = DuplicatesStrategy.EXCLUDE
  // this shouldn't be necessary but if it's not specified we're missing some of the jars
  // from the runtime classpath
  classpath configurations.runtimeClasspath
}

artifacts {
  war tasks.war
}
