/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

import org.elasticsearch.gradle.internal.precommit.CheckForbiddenApisTask

apply plugin: 'elasticsearch.build'

base {
  archivesName = 'elasticsearch-security-cli'
}

dependencies {
  compileOnly project(":server")
  compileOnly project(path: xpackModule('core'))
  api "org.bouncycastle:bcpkix-jdk18on:${versions.bouncycastle}"
  api "org.bouncycastle:bcprov-jdk18on:${versions.bouncycastle}"
  api "org.bouncycastle:bcutil-jdk18on:${versions.bouncycastle}"
  testImplementation("com.google.jimfs:jimfs:${versions.jimfs}") {
    // this is provided by the runtime classpath, from the security project
    exclude group: "com.google.guava", module: "guava"
  }
  testRuntimeOnly "com.google.guava:guava:${versions.jimfs_guava}"
  testImplementation project(":test:framework")
  testImplementation(testArtifact(project(xpackModule('core'))))
}

tasks.named("dependencyLicenses").configure {
  mapping from: /bc.*/, to: 'bouncycastle'
}

tasks.named("forbiddenPatterns").configure {
  exclude '**/*.p12'
  exclude '**/*.jks'
}

tasks.named("test").configure {
  environment 'HOSTNAME', 'dummy.test.hostname' // some tests rely on this being set, which it always is for the code running in main
  systemProperty 'tests.security.manager', 'false' // the main code under test runs without the SecurityManager
}

if (buildParams.inFipsJvm) {
  tasks.named("test").configure {
    enabled = false
  }
  tasks.named("jarHell").configure {
    enabled = false
  }
  // Forbiden APIs non-portable checks fail because bouncy castle classes being used from the FIPS JDK since those are
  // not part of the Java specification - all of this is as designed, so we have to relax this check for FIPS.
  tasks.withType(CheckForbiddenApisTask).configureEach {
    modifyBundledSignatures { bundledSignatures ->
      bundledSignatures -= "jdk-non-portable"
      bundledSignatures
    }
  }
}
