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

configure(childProjects.values()) {

  apply plugin: 'base'

  /*
   * Although these libs are local to Elasticsearch, they can conflict with other similarly
   * named libraries when downloaded into a single directory via maven. Here we set the
   * name of all libs to begin with the "elasticsearch-" prefix. Additionally, subprojects
   * of libs begin with their parents artifactId.
   */
  def baseProject = project
  def baseArtifactId = "elasticsearch-${it.name}"
  base {
    archivesName = baseArtifactId
  }
  subprojects {
    apply plugin: 'base'

    def subArtifactId = baseArtifactId
    def currentProject = project
    while (currentProject != baseProject) {
      subArtifactId += "-${currentProject.name}"
      currentProject = currentProject.parent
    }
    base {
      archivesName = subArtifactId
    }
  }

  // log4j is a hack, and not really a full elasticsearch built jar
  if (project.name != 'log4j') {

    /*
     * All subprojects are java projects using Elasticsearch's standard build
     * tools.
     */
    apply plugin: 'elasticsearch.build'
  }

  // This is for any code potentially included in the server at runtime.
  // Omit oddball libraries that aren't in server.
  def nonServerLibs = ['plugin-scanner']
  if (false == nonServerLibs.contains(project.name)) {
    project.getTasks().withType(Test.class).matching(test -> ['test', 'internalClusterTest'].contains(test.name)).configureEach(test -> {
      test.systemProperty('es.entitlement.enableForTests', 'true')
    })
  }

}
