import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.plugin.PluginBuildPlugin
import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.precommit.LicenseHeadersTask

Project xpackRootProject = project

subprojects {
  group = 'org.elasticsearch.plugin'
  ext.xpackRootProject = xpackRootProject
  ext.xpackProject = { String projectName -> xpackRootProject.project(projectName) }
  // helper method to find the path to a module
  ext.xpackModule = { String moduleName -> xpackProject("plugin:${moduleName}").path }

  plugins.withType(PluginBuildPlugin).whenPluginAdded {
    project.esplugin.licenseFile = rootProject.file('licenses/ELASTIC-LICENSE.txt')
    project.esplugin.noticeFile = xpackRootProject.file('NOTICE.txt')
  }

  if (project.name != 'protocol') {
    tasks.withType(LicenseHeadersTask.class) {
        approvedLicenses = ['Elastic License', 'Generated']
        additionalLicense 'ELAST', 'Elastic License', 'Licensed under the Elastic License'
    }

    ext.licenseName = 'Elastic License'
    ext.licenseUrl = ext.elasticLicenseUrl

    project.ext.licenseFile = rootProject.file('licenses/ELASTIC-LICENSE.txt')
    project.ext.noticeFile = xpackRootProject.file('NOTICE.txt')
  }
}

subprojects {
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-ccr:${version}": xpackModule('ccr')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-core:${version}": xpackModule('core')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-deprecation:${version}": xpackModule('deprecation')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-graph:${version}": xpackModule('graph')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-logstash:${version}": xpackModule('logstash')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-ml:${version}": xpackModule('ml')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-monitoring:${version}": xpackModule('monitoring')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-security:${version}": xpackModule('security')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-sql:${version}": xpackModule('sql')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-upgrade:${version}": xpackModule('upgrade')]
  ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-watcher:${version}": xpackModule('watcher')]
}