import org.apache.tools.ant.taskdefs.condition.Os

plugins {
    id "com.github.hierynomus.license" version"0.14.0"
}

license {
    header file("${rootDir}/FILE_HEADER")
    mapping {
        cs='JAVADOC_STYLE'
        proto='DOUBLESLASH_STYLE'
        interop='DOUBLESLASH_STYLE'
    }
    strictCheck true
}

task licenseFormatProto(type: com.hierynomus.gradle.license.tasks.LicenseFormat) {
    source = fileTree(dir: '.')
            .exclude("**/google/protobuf/*.proto")
            .include("**/*.proto").include("**/*.interop")
}

tasks["license"].dependsOn licenseFormatProto
licenseFormat.dependsOn licenseFormatProto

task copySamplesMetadata(type: Copy) {
  def outputDir = "${rootDir}/bin/win-x86/samples/greeting/metadata"
  if (Os.isFamily(Os.FAMILY_MAC)) {
      outputDir="${rootDir}/bin/osx-x64/samples/greeting/metadata"
  }
  outputs.dir outputDir
  inputs.dir 'samples/metadata'
  from 'samples/metadata'
  into outputDir
}

task copyQuickStartMetadata(type: Copy) {
  def outputDir = "${rootDir}/bin/win-x86/samples/quick-start/metadata"
  if (Os.isFamily(Os.FAMILY_MAC)) {
      outputDir="${rootDir}/bin/osx-x64/samples/quick-start/metadata"
  }
  outputs.dir outputDir
  inputs.dir 'quick-start/metadata'
  from 'quick-start/metadata'
  into outputDir
}

task build

build.dependsOn copySamplesMetadata 
build.dependsOn copyQuickStartMetadata
build.dependsOn('license')