plugins {
    id "com.jfrog.bintray" version "1.1"
    id "com.github.jruby-gradle.base" version "1.5.0"
    id "java"
    id "eclipse"
}
import com.github.jrubygradle.JRubyExec
repositories {
    mavenCentral()
    jcenter()
}
configurations {
    provided
}

version = "0.1.11"

sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
    compile  "org.embulk:embulk-core:0.7.5"
    provided "org.embulk:embulk-core:0.7.5"
    compile  "org.embulk:embulk-standards:0.7.5"
    // compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
    compile group: 'org.apache.poi', name : 'poi', version: '3.17'
    compile(group: 'org.apache.poi', name : 'poi-ooxml', version: '3.17') {
        exclude group: 'stax', module: 'stax-api'
    }
    testCompile "junit:junit:4.+"
}

task classpath(type: Copy, dependsOn: ["jar"]) {
    doFirst { file("classpath").deleteDir() }
    from (configurations.runtime - configurations.provided + files(jar.archivePath))
    into "classpath"
}
clean { delete "classpath" }

task gem(type: JRubyExec, dependsOn: ["gemspec", "classpath"]) {
    jrubyArgs "-S"
    script "gem"
    scriptArgs "build", "${project.name}.gemspec"
    doLast { ant.move(file: "${project.name}-${project.version}.gem", todir: "pkg") }
}

task gemPush(type: JRubyExec, dependsOn: ["gem"]) {
    jrubyArgs "-S"
    script "gem"
    scriptArgs "push", "pkg/${project.name}-${project.version}.gem"
}

task "package"(dependsOn: ["gemspec", "classpath"]) {
    doLast {
        println "> Build succeeded."
        println "> You can run embulk with '-L ${file(".").absolutePath}' argument."
    }
}

task gemspec {
    ext.gemspecFile = file("${project.name}.gemspec")
    inputs.file "build.gradle"
    outputs.file gemspecFile
    doLast { gemspecFile.write($/
Gem::Specification.new do |spec|
  spec.name          = "${project.name}"
  spec.version       = "${project.version}"
  spec.authors       = ["hishidama"]
  spec.summary       = %[Apache POI Excel parser plugin for Embulk]
  spec.description   = %[Parses Excel files(xls, xlsx) read by other file input plugins.]
  spec.email         = ["hishi.dama@asahi.email.ne.jp"]
  spec.licenses      = ["MIT"]
  spec.homepage      = "https://github.com/hishidama/embulk-parser-poi_excel"

  spec.files         = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
  spec.test_files    = spec.files.grep(%r"^(test|spec)/")
  spec.require_paths = ["lib"]

  #spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
  spec.add_development_dependency 'bundler', ['~> 1.0']
  spec.add_development_dependency 'rake', ['>= 10.0']
end
/$)
    }
}
clean { delete "${project.name}.gemspec" }