/*
 * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
 * Public License v 1"; you may not use this file except in compliance with, at
 * your election, the "Elastic License 2.0", the "GNU Affero General Public
 * License v3.0 only", or the "Server Side Public License, v 1".
 */

import org.elasticsearch.gradle.OS

apply plugin: 'elasticsearch.build'

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

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

dependencies {
  compileOnly project(":server")
  compileOnly project(":libs:cli")
  implementation project(":libs:plugin-api")
  implementation project(":libs:plugin-scanner")
  implementation project(":libs:entitlement")
  implementation project(path: "bc", configuration: 'shadow')
  // TODO: asm is picked up from the plugin scanner and entitlements, we should consolidate so it is not defined twice
  implementation 'org.ow2.asm:asm:9.9'
  implementation 'org.ow2.asm:asm-tree:9.9'

  testImplementation project(":test:framework")
  testImplementation "com.google.jimfs:jimfs:${versions.jimfs}"
  testRuntimeOnly "com.google.guava:guava:${versions.jimfs_guava}"

  testImplementation "org.bouncycastle:bcpg-jdk18on:1.83"
  testImplementation "org.bouncycastle:bcprov-jdk18on:1.83"
  testImplementation "org.bouncycastle:bcutil-jdk18on:1.83"
}

tasks.named("test").configure {
  // TODO: find a way to add permissions for the tests in this module
  systemProperty 'tests.security.manager', 'false'
  // These tests are "heavy" on the secure number generator. On Linux, the NativePRNG defaults to /dev/random for the seeds, and
  // its entropy is quite limited, to the point that it's known to hang: https://bugs.openjdk.org/browse/JDK-6521844
  // We force the seed to be initialized from /dev/urandom, which is less secure, but in case of unit tests is not important.
  if (OS.current() == OS.LINUX) {
    systemProperty 'java.security.egd', 'file:/dev/urandom'
  }
}

if (buildParams.inFipsJvm) {
  // Disable tests in FIPS mode due to JAR hell between plugin-cli's
  // BC dependencies and the BC FIPS dependencies added by the FIPS gradle config
  // We support running plugin-cli with BC FIPS JARs in ES lib via shadowing.
  // Running these tests with the JVM in FIPS mode isn't related.
  tasks.named("test").configure { enabled = false }
}
