plugins {
  id 'java'
  id 'eclipse'

  // Generate coverage during tests.
  id 'jacoco'

  // Generate executable scripts
  id 'application'

  // enforces consistent formatting
  id 'com.github.sherter.google-java-format' version '0.8'

  // enforces java style
  id 'net.ltgt.errorprone' version '0.6'

  // improve the test output
  id "com.adarshr.test-logger" version "1.7.0"
}

eclipse {
    classpath {
       downloadSources=true
    }
}

def createScript(project, mainClass, name) {
  project.tasks.create(name: name, type: CreateStartScripts) {
    outputDir       = new File(project.buildDir, 'scripts')
    mainClassName   = mainClass
    applicationName = name
    classpath       = project.tasks[JavaPlugin.JAR_TASK_NAME].outputs.files + project.configurations.runtime
  }
  project.tasks[name].dependsOn(project.jar)

  project.applicationDistribution.with {
    into("bin") {
      from(project.tasks[name])
      fileMode = 0755
    }
  }
}

startScripts.enabled = false
run.enabled = false

sourceCompatibility = 1.8
version = '1.0'

createScript(project, 'com.google.javascript.clutz.DeclarationGenerator', 'clutz')
createScript(project, 'com.google.javascript.gents.TypeScriptGenerator', 'gents')

repositories {
  mavenCentral()
  maven {
    url "https://oss.sonatype.org/content/repositories/snapshots/"
  }
}

dependencies {

  // Verify all versions match closure-compiler's deps to avoid version conflicts.
  // Also make sure this matches internal Google usage, as closure-compiler is not always
  // dilligent about using the correct versions.
  // https://github.com/google/closure-compiler/blob/master/pom-main.xml
  compile('args4j:args4j:2.0.26') {
    // Forced, as Closure Compiler depends on the wrong version.
    force = true
  }
  // In the past we tested against nightly closure releases at  'com.google.javascript:closure-compiler:1.0-SNAPSHOT',
  // but sonatype started 404-ing CircleCI. Now, we test against the latest released Closure version on Circle, and
  // internally test against Closure head.
  compile 'com.google.javascript:closure-compiler:v20190929'

  compile 'com.google.code.gson:gson:2.7'
  compile 'com.google.code.findbugs:jsr305:3.0.1'
  compile 'com.google.guava:guava:28.0-jre'
  compile 'org.apache.commons:commons-text:1.4'

  // ErrorProne itself, plus its javac integration.
  errorprone("com.google.errorprone:error_prone_core:2.3.2")
  errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')

  testCompile 'junit:junit:4.11'
  testCompile 'com.google.truth:truth:1.0'
}

tasks.withType(Test) {
  systemProperty 'gents.clangFormat',
                 System.getProperty('gents.clangFormat', 'node_modules/.bin/clang-format')
}

test {
  testLogging {
    exceptionFormat = 'full'
  }
}

googleJavaFormat {
  toolVersion '1.3'
}

// configure the test output
testlogger {
  theme 'mocha'
}
