/*
 * 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'
}

evaluationDependsOn(':geode-core')

jar.enabled = true

dependencies {
  api(platform(project(':boms:geode-all-bom')))
  compileOnly(platform(project(':boms:geode-all-bom')))
  providedCompile(platform(project(':boms:geode-all-bom')))

  implementation('org.springframework.security:spring-security-core')
  implementation('javax.servlet:javax.servlet-api')
  implementation('mx4j:mx4j') {
    ext.optional = true
  }
  implementation('mx4j:mx4j-remote') {
    ext.optional = true
  }

  uiTestImplementation('junit:junit')
  uiTestImplementation('org.apache.httpcomponents:httpcore')
  uiTestImplementation('org.seleniumhq.selenium:selenium-api')
  uiTestImplementation('org.assertj:assertj-core')
  uiTestImplementation('org.apache.httpcomponents:httpclient')
  uiTestImplementation('org.seleniumhq.selenium:selenium-support')
  implementation('org.springframework:spring-beans')

  // Needed to fully use log4j instead of commons-logging.
  implementation('org.apache.logging.log4j:log4j-jcl')
  implementation('org.apache.logging.log4j:log4j-api')

  implementation('commons-beanutils:commons-beanutils')
  implementation('commons-collections:commons-collections')
  implementation('commons-digester:commons-digester')
  implementation('org.apache.commons:commons-lang3')
  implementation('org.apache.commons:commons-text')
  implementation('org.springframework.ldap:spring-ldap-core')
  implementation('org.springframework.security:spring-security-oauth2-core')
  implementation('org.springframework.security:spring-security-oauth2-client')
  implementation('org.springframework.security:spring-security-oauth2-jose')

  implementation('org.springframework.security:spring-security-config') {
    exclude module: 'aopalliance'
    exclude module: 'spring-expression'
  }
  implementation('org.springframework.security:spring-security-ldap') {
    exclude module: 'aopalliance'
    exclude module: 'spring-asm'
    exclude module: 'spring-expression'
    exclude module: 'spring-jdbc'
  }
  implementation('org.springframework.security:spring-security-web') {
    exclude module: 'aopalliance'
    exclude module: 'spring-asm'
    exclude module: 'spring-expression'
    exclude module: 'spring-jdbc'
  }
  implementation('org.springframework:spring-context')
  implementation('org.springframework:spring-web')
  runtimeOnly('org.springframework:spring-webmvc') {
    exclude module: 'aopalliance'
    exclude module: 'aspectjweaver'
  }
  implementation('org.springframework:spring-tx')
  implementation('com.fasterxml.jackson.core:jackson-annotations')
  implementation('com.fasterxml.jackson.core:jackson-core')
  implementation('com.fasterxml.jackson.core:jackson-databind')

  compileOnly('org.mortbay.jetty:servlet-api')

  runtimeOnly('org.springframework:spring-expression')

  runtimeOnly('org.apache.logging.log4j:log4j-slf4j-impl')

  providedCompile('commons-logging:commons-logging')


  testImplementation(project(':geode-core'))
  testImplementation(project(':geode-junit')) {
    exclude module: 'geode-core'
  }
  testImplementation(project(':geode-log4j')) {
    exclude module: 'geode-core'
  }
  testImplementation('org.springframework:spring-test')


  integrationTestImplementation(project(':geode-core'))
  integrationTestImplementation(project(':geode-junit')) {
    exclude module: 'geode-core'
  }
  integrationTestImplementation(project(':geode-log4j')) {
    exclude module: 'geode-core'
  }

  integrationTestImplementation(project(':geode-pulse'))
  integrationTestImplementation(project(':geode-pulse:geode-pulse-test'))
  integrationTestImplementation(project(':geode-serialization'))

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

  integrationTestImplementation('junit:junit')
  integrationTestImplementation('org.hamcrest:hamcrest')

  uiTestRuntimeOnly(project(':geode-core'))
  uiTestImplementation(project(':geode-junit')) {
    exclude module: 'geode-core'
  }
  uiTestImplementation(project(':geode-log4j')) {
    exclude module: 'geode-core'
  }
  uiTestImplementation(project(':geode-pulse:geode-pulse-test'))
  uiTestImplementation('org.seleniumhq.selenium:selenium-remote-driver')
}

def generatedResources = "$buildDir/generated-resources/main"

sourceSets {
  main {
    output.dir(generatedResources, builtBy: 'copyGemFireVersionFile')
  }

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

task copyGemFireVersionFile(type: Copy) {
  from project(':geode-core').createVersionPropertiesFile
  into generatedResources
}

eclipse.classpath.file {
  whenMerged { classpath ->
    classpath.entries.removeAll { entry -> entry.path.contains('geode-core/build')}
  }
}
idea.module.iml {
  whenMerged {module ->
    module.dependencies.removeAll { entry -> entry.toString().contains('geode-core/build')}
  }
}

artifacts {
  archives war
}

war {
  enabled = true
  duplicatesStrategy = DuplicatesStrategy.EXCLUDE
  classpath configurations.runtimeClasspath
}
uiTest.dependsOn war
uiTest.finalizedBy rootProject.combineReports
rootProject.combineReports.mustRunAfter uiTest
