/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * The OpenSearch Contributors require contributions made to
 * this file be licensed under the Apache-2.0 license or a
 * compatible open source license.
 *
 * Modifications Copyright OpenSearch Contributors. See
 * GitHub history for details.
 */

import org.opensearch.gradle.test.RestIntegTestTask
import org.opensearch.gradle.testclusters.TestClustersPlugin

subprojects { Project subproj ->
  subproj.tasks.withType(RestIntegTestTask) {
    if (subproj.extensions.findByName("${it.name}Cluster")) {
      subproj.extensions.configure("${it.name}Cluster") { cluster ->
        cluster.distribution = System.getProperty('tests.distribution', 'archive')
      }
    }
  }
  plugins.withType(TestClustersPlugin).whenPluginAdded {
    testClusters.all {
      String configuredTestDistribution = System.getProperty('tests.distribution', 'archive').toUpperCase()
      testDistribution = configuredTestDistribution
    }
  }
}