/*
 * 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.apache.tools.ant.filters.ReplaceTokens

apply plugin: 'elasticsearch.internal-yaml-rest-test'

def pluginPaths = []
def pluginNames = []
project(':plugins').getChildProjects().each { pluginName, pluginProject ->
  pluginPaths << pluginProject.path
  pluginNames << pluginName
}

dependencies {
  yamlRestTestImplementation project(':x-pack:qa')
  pluginPaths.each { pluginPath ->
    clusterPlugins(project(pluginPath))
  }
}

ext.expansions = [
  'expected.plugins.count': pluginPaths.size()
]

tasks.named("processYamlRestTestResources").configure {
  inputs.properties(project.expansions)
  filter("tokens" : expansions.collectEntries {k, v -> [k, v.toString()]} /* must be a map of strings */, ReplaceTokens.class)
}

tasks.named("yamlRestTest") {
  usesDefaultDistribution("plugins require default distro with all modules")
  systemProperty('tests.plugin.names', pluginNames.join(','))
}
