buildscript { repositories { jcenter() } dependencies { classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1' classpath "com.github.jruby-gradle:jruby-gradle-jar-plugin:1.0.1" classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3' classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2' } } apply plugin: "com.github.jruby-gradle.jar" apply plugin: 'com.jfrog.bintray' apply plugin: 'com.github.johnrengelman.shadow' def java_projects = [project(":embulk-core"), project(":embulk-standards"), project(":embulk-cli")] def release_projects = [project(":embulk-core"), project(":embulk-standards")] allprojects { group = 'org.embulk' version = '0.7.0' ext { jrubyVersion = '9.0.0.0' } apply plugin: 'java' apply plugin: 'maven-publish' apply plugin: 'com.jfrog.bintray' test { maxHeapSize = "1536m" } // // bintrayUpload task // bintray { // write at your bintray user name and api key to ~/.gradle/gradle.properties file: // bintray_user=frsyuki // bintray_api_key=xxxxxxxxxxx user = project.hasProperty('bintray_user') ? bintray_user : '' key = project.hasProperty('bintray_api_key') ? bintray_api_key : '' publications = ['bintrayMavenRelease'] filesSpec { // include embulk-.jar built by 'cli' task from "pkg/embulk-${project.version}.jar" into "." } dryRun = false publish = true pkg { userOrg = 'embulk' repo = 'maven' name = 'embulk' desc = 'Embulk, a plugin-based parallel bulk data loader' websiteUrl = 'https://github.com/embulk/embulk' issueTrackerUrl = 'https://github.com/embulk/embulk/issues' vcsUrl = 'https://github.com/embulk/embulk.git' licenses = ['Apache-2.0'] labels = ['embulk', 'ruby', 'java'] publicDownloadNumbers = true version { name = project.version // TODO //mavenCentralSync { // sync = true // user = 'userToken' // password = 'paasword' // close = '1' //} } } } } subprojects { if (java_projects.contains(project)) { apply plugin: 'maven' apply plugin: 'findbugs' apply plugin: 'jacoco' repositories { mavenCentral() jcenter() } compileJava.options.encoding = 'UTF-8' // source encoding sourceCompatibility = 1.7 targetCompatibility = 1.7 dependencies { testCompile 'junit:junit:4.12' } tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:unchecked" //<< "-Xlint:deprecation" } tasks.withType(FindBugs) { reports { xml.enabled = false html.enabled = true } } findbugs { ignoreFailures = true } javadoc { options { locale = 'en_US' encoding = 'UTF-8' } } // add tests/javadoc/source jar tasks as artifacts to be released task testsJar(type: Jar, dependsOn: classes) { classifier = 'tests' from sourceSets.test.output } task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource } task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from javadoc.destinationDir } artifacts { archives testsJar, sourcesJar, javadocJar } } publishing { publications { if (release_projects.contains(project)) { bintrayMavenRelease(MavenPublication) { from components.java artifact testsJar artifact sourcesJar artifact javadocJar } } } } } task wrapper(type: Wrapper) { gradleVersion = '2.6' } import com.github.jrubygradle.JRubyExec jruby { execVersion = project.jrubyVersion } dependencies { jrubyExec 'rubygems:simplecov:0.10.+' jrubyExec 'rubygems:test-unit:3.0.+' } import java.util.zip.ZipFile import java.util.zip.ZipEntry task updateResources(dependsOn: 'classpath') { doFirst { List packages = [] List dirs = [] file("classpath").listFiles().each { jarFile -> List names = new ZipFile(jarFile.toString()).entries().iterator().collect { it.getName() } packages.addAll(names.findAll { it.endsWith(".class") }.collect { it.replaceFirst(/(?:^|\/)[^\/]*\.class$/, '').replaceAll(/\//, '.') }.unique()) dirs.addAll(names.findAll { !it.endsWith("/") && !it.endsWith(".class") }.collect { it.replaceFirst(/(?:^|\/)[^\/]*$/, '') }.unique()) } packages = packages.unique() dirs = dirs.unique() List uniquePackages = packages.clone() List uniqueDirs = dirs.clone() packages.each { pk -> uniquePackages.removeAll { it.startsWith(pk + '.') } } dirs.each { dir -> uniqueDirs.removeAll { it.startsWith(dir + '/') } } uniquePackages.removeAll { it.isEmpty() } uniqueDirs.removeAll { it.isEmpty() || it == "META-INF" } String date = new Date().format('yyyy-MM-dd HH:mm:ss z', TimeZone.getTimeZone("UTC")) file("embulk-core/src/main/resources/embulk/parent_first_packages.properties").withWriter { out -> out.println("# generated by './gradlew updateResources' at $date") uniquePackages.sort().each { out.println it } } file("embulk-core/src/main/resources/embulk/parent_first_resources.properties").withWriter { out -> out.println("# generated by './gradlew updateResources' at $date") uniqueDirs.sort().each { out.println it } } } doLast { classpath.execute() } } // // classpath task // task classpath(dependsOn: ['build', ':embulk-cli:classpath']) << { } clean { delete 'classpath' } // // cli task // task cli(dependsOn: ':embulk-cli:shadowJar') << { file('pkg').mkdirs() File f = file("pkg/embulk-${project.version}.jar") f.write("") f.append(file("embulk-cli/src/main/sh/selfrun.sh").readBytes()) f.append(file("embulk-cli/build/libs/embulk-cli-${project.version}-all.jar").readBytes()) f.setExecutable(true) } bintrayUpload.dependsOn(['cli']) project(':embulk-cli') { apply plugin: 'com.github.johnrengelman.shadow' shadowJar { manifest { attributes 'Implementation-Title': project.name, 'Implementation-Version': project.version, 'Implementation-Vendor-Id': project.group, 'Specification-Title': project.name, 'Specification-Version': project.version, 'Main-Class': 'org.embulk.cli.Main' } append("${rootProject.projectDir}/COPYING") } task classpath(type: Copy) { File dest = file("${rootProject.projectDir}/classpath") doFirst { dest.deleteDir() } from configurations.runtime into dest } } task rubyTest(type: JRubyExec) { jrubyArgs '-Ilib', '-Itest', '-rtest/unit', '--debug', './test/run-test.rb' } rubyTest.dependsOn('classpath') // // gem task // task gemJRuby(type: JRubyExec, dependsOn: ["classpath"]) { jrubyArgs '-rrubygems/gem_runner', '-eGem::GemRunner.new.run(ARGV)' script './lib/embulk/version.rb' // dummy scriptArgs 'build', 'embulk.gemspec' doLast { file("${project.name}-${project.version}-java.gem").renameTo("pkg/${project.name}-${project.version}-java.gem") } } task gem(type: Exec, dependsOn: ["classpath", "gemJRuby"]) { executable "gem" args "build", "embulk.gemspec" doFirst { def rubyVersion = file(".ruby-version").getText().trim() if (!"ruby --version".execute().text.contains(rubyVersion)) { throw new GradleException("Version of 'ruby' command in PATH must be ${rubyVersion}. Use rbenv and install ${rubyVersion}") } } doLast { file("${project.name}-${project.version}.gem").renameTo("pkg/${project.name}-${project.version}.gem") } } // // rubyGemsUpload task // task rubyGemsUploadJRuby(type: Exec, dependsOn: ["gem"]) { executable "gem" args "push", "pkg/embulk-${project.version}-java.gem" } task rubyGemsUpload(type: Exec, dependsOn: ["gem", "rubyGemsUploadJRuby"]) { executable "gem" args "push", "pkg/embulk-${project.version}.gem" } // // releaseCheck and release tasks // task releaseCheck << { if (!file("lib/embulk/version.rb").getText().contains("${project.version}")) { throw new GradleException("lib/embulk/version.rb doesn't include ${project.version}") } if (!file("embulk-docs/src/release/release-${project.version}.rst").getText().contains("${project.version}")) { throw new GradleException("Release note for ${project.version} doesn't exist") } if (!file("embulk-docs/src/release.rst").getText().contains("release-${project.version}")) { throw new GradleException("embulk-docs/src/release.rst doesn't include release-${project.version}") } String date = new Date().format("yyyy-MM-dd") if (!file("embulk-docs/src/release/release-${project.version}.rst").getText().contains(date)) { throw new GradleException("embulk-docs/src/release/release-${project.version}.rst doesn't include today's release date") } // TODO check git-ls-files includes release-.rst file println "Ready. Run 'release' task." } task release(dependsOn: ["releaseCheck", "bintrayUpload", "rubyGemsUpload"]) << { println """ Manual operations: git commit -am v${project.version} git tag v${project.version} """ } bintrayUpload.mustRunAfter('releaseCheck') rubyGemsUpload.mustRunAfter('releaseCheck') rubyGemsUploadJRuby.mustRunAfter('releaseCheck') task setVersion << { if (!project.hasProperty("to")) { throw new GradleException("Usage: ./gradlew setVersion -Pto=VERSION") } File gradle_ver = file('build.gradle') gradle_ver.write(gradle_ver.getText().replaceFirst("version = '(\\d+)(\\.\\d+){2}'", "version = '${to}'")) File ruby_ver = file('lib/embulk/version.rb') ruby_ver.write(ruby_ver.getText().replaceFirst("VERSION = '(\\d+)(\\.\\d+){2}'", "VERSION = '${to}'")) List docs = [ 'README.md', ] docs.each() { path -> File doc = file(path) doc.write(doc.getText().replaceAll('embulk-(\\d+)(\\.\\d+){2}', "embulk-${to}")) } file("embulk-docs/src/release/release-${to}.rst").append("") "git add embulk-docs/src/release/release-${to}.rst".execute().waitFor() println "add 'release/release-${to}' line to embulk-docs/src/release.rst" }