import org.elasticsearch.gradle.VersionProperties

if (project.projectDir.name != 'x-plugins') {
  throw new GradleException('You must checkout x-plugins in a directory named x-plugins next to elasticsearch')
}

subprojects {
  // we must not publish to sonatype until we have set up x-plugins to only publish the parts we want to publish!
  project.afterEvaluate {
    if (project.plugins.hasPlugin('com.bmuschko.nexus') && project.nexus.repositoryUrl.startsWith('file://') == false) {
      uploadArchives.enabled = false
    }
  }
}

task bundlePack(type: Zip) {
  onlyIf { project('kibana').bundlePlugin.enabled }
  dependsOn 'elasticsearch:x-pack:bundlePlugin'
  dependsOn 'kibana:bundlePlugin'
  from { zipTree(project('elasticsearch:x-pack').bundlePlugin.outputs.files.singleFile) }
  from { zipTree(project('kibana').bundlePlugin.outputs.files.singleFile) }
  destinationDir file('build/distributions')
  baseName = 'x-pack'
  version = VersionProperties.elasticsearch
}

task assemble(dependsOn: bundlePack) {
  group = 'Build'
  description = 'Assembles the outputs of this project.'
}

task build(dependsOn: assemble) {
  group = 'Build'
  description = 'Assembles and tests this project.'
}

task clean(type: Delete) {
  group = 'Build'
  description = 'Deletes the build directory'
  delete 'build'
}