From 96d3219657b26d12b88b935483054fc658b88be4 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 13:09:32 +0900 Subject: [PATCH 01/11] Reading default checkstyle XMLs didn't work --- .../gradle/embulk/EmbulkExtension.kt | 4 +-- .../kamatama41/gradle/embulk/EmbulkPlugin.kt | 29 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt index b8e27ec..ab6262d 100644 --- a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt +++ b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt @@ -16,8 +16,8 @@ open class EmbulkExtension(project: Project) { var jrubyVersion = "1.7.19" // TODO: update (currently v9.1.x) var checkstyleVersion = "6.14.1" - var checkstyleConfig = project.resources.text.fromFile("config/checkstyle/checkstyle.xml").asFile() - var checkstyleDefaultConfig = project.resources.text.fromFile("config/checkstyle/default.xml").asFile() + var checkstyleConfig : File? = null + var checkstyleDefaultConfig : File? = null var checkstyleIgnoreFailures = true var workDir = project.file("${project.projectDir.absolutePath}/.gradle/embulk") diff --git a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt index 07ed698..7525ee5 100644 --- a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt +++ b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt @@ -10,6 +10,7 @@ import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.plugins.quality.Checkstyle import org.gradle.api.plugins.quality.CheckstyleExtension +import org.gradle.api.plugins.quality.CheckstylePlugin import org.gradle.api.tasks.Copy import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.bundling.Jar @@ -36,6 +37,7 @@ class EmbulkPlugin : Plugin { this.git = Git.new(project.rootProject.rootDir) project.plugins.apply(JavaPlugin::class.java) project.plugins.apply(JRubyPlugin::class.java) + project.plugins.apply(CheckstylePlugin::class.java) project.configurations.maybeCreate("provided") newPluginTask() @@ -148,19 +150,21 @@ class EmbulkPlugin : Plugin { } fun checkstyleTask() { - project.plugins.apply("checkstyle") project.afterEvaluate { + val config = extension.checkstyleConfig ?: getConfigFromResources("checkstyle/checkstyle.xml") + val defaultConfig = extension.checkstyleDefaultConfig ?: getConfigFromResources("checkstyle/default.xml") + project.extensions.configure(CheckstyleExtension::class.java) { checkstyle -> - checkstyle.configFile = extension.checkstyleConfig + checkstyle.configFile = config checkstyle.toolVersion = extension.checkstyleVersion } val checkstyleMain = project.tasks.findByName("checkstyleMain") as Checkstyle - checkstyleMain.configFile = extension.checkstyleDefaultConfig + checkstyleMain.configFile = defaultConfig checkstyleMain.ignoreFailures = extension.checkstyleIgnoreFailures val checkstyleTest = project.tasks.findByName("checkstyleTest") as Checkstyle - checkstyleTest.configFile = extension.checkstyleDefaultConfig + checkstyleTest.configFile = defaultConfig checkstyleTest.ignoreFailures = extension.checkstyleIgnoreFailures val sourceSets = project.the().sourceSets @@ -244,6 +248,23 @@ class EmbulkPlugin : Plugin { } } + private fun getConfigFromResources(path: String): File { + val tmpConfig = project.file("${project.buildDir.absolutePath}/embulk/config/$path") + if (!tmpConfig.parentFile.exists()) { + tmpConfig.parentFile.mkdirs() + } + tmpConfig.delete() + tmpConfig.createNewFile() + + this.javaClass.classLoader.getResourceAsStream("config/$path").use { input -> + FileOutputStream(tmpConfig).use { output -> + input.copyTo(output) + } + } + + return tmpConfig + } + class EmbulkExecRule(val project: Project, val extension: EmbulkExtension) : Rule { override fun getDescription() = """Pattern: "embulk_": Executes an Embulk command.""" From 44dc73b7b2b8f20fb581dfb0a16df30a7a73db84 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 15:04:29 +0900 Subject: [PATCH 02/11] Add a test for checkstyle task --- build.gradle | 6 +- .../gradle/embulk/EmbulkPluginTest.kt | 69 +++++++++++++++---- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/build.gradle b/build.gradle index b208326..6777de1 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ buildscript { apply plugin: "idea" apply plugin: "kotlin" +apply plugin: "java-gradle-plugin" apply plugin: "com.github.kamatama41.git-release" repositories { @@ -21,13 +22,16 @@ repositories { sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7 +def jgitVersion = "4.3.1.201605051710-r" dependencies { compile gradleApi() compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - compile "org.eclipse.jgit:org.eclipse.jgit:4.3.1.201605051710-r" + compile "org.eclipse.jgit:org.eclipse.jgit:$jgitVersion" compile "com.google.guava:guava:20.0" compile "com.github.jruby-gradle:jruby-gradle-plugin:0.1.5" + testCompile gradleTestKit() testCompile "junit:junit:4.12" + testCompile "org.eclipse.jgit:org.eclipse.jgit.junit:$jgitVersion" } gitRelease { diff --git a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt index cf08e34..99f2d5a 100644 --- a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt +++ b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt @@ -1,23 +1,62 @@ package com.github.kamatama41.gradle.embulk -import org.gradle.api.Project -import org.gradle.api.tasks.Copy -import org.gradle.testfixtures.ProjectBuilder +import org.eclipse.jgit.internal.storage.file.FileRepository +import org.eclipse.jgit.junit.RepositoryTestCase +import org.gradle.testkit.runner.BuildResult +import org.gradle.testkit.runner.GradleRunner import org.junit.Assert.assertTrue import org.junit.Test -import java.nio.file.Files - -class EmbulkPluginTest { - val project: Project by lazy { - val tmpDir = Files.createTempDirectory("gradle-embulk-plugin").toFile() - Git.init(tmpDir) - val project = ProjectBuilder.builder().withProjectDir(tmpDir).build() - project.pluginManager.apply("com.github.kamatama41.embulk") - project +import java.io.File + +class EmbulkPluginTest : RepositoryTestCase() { + lateinit var testProjectDir: FileRepository + val projectDir by lazy { File("${testProjectDir.directory}/..") } + val buildDir by lazy { "${projectDir.absolutePath}/build/embulk" } + + override fun setUp() { + super.setUp() + setupProject() + } + + @Test + fun checkstyle() { + // Generated plugin Java code has checkstyle error by default, so it will fail. + buildAndFail("checkstyle") + + // Check generated checkstyle.xml and default.xml to build dir. + assertTrue(File("$buildDir/config/checkstyle/checkstyle.xml").exists()) + assertTrue(File("$buildDir/config/checkstyle/default.xml").exists()) } - @Test fun classpath() { - val classpath = project.tasks.findByName("classpath") - assertTrue("classpath is a Copy task", classpath is Copy) + private fun setupProject() { + testProjectDir = createWorkRepository() + createFile("build.gradle").writeText(""" + plugins { id "com.github.kamatama41.embulk" } + + embulk { + version = "0.8.18" + category = "filter" + name = "myfilter" + homepage = "https://github.com/someuser/embulk-filter-myfilter" + } + """) + + build("newPlugin") + assertTrue(File("$projectDir", "README.md").exists()) + assertTrue(File("$projectDir", "LICENSE.txt").exists()) + assertTrue(File("$projectDir", ".gitignore").exists()) + assertTrue(File("$projectDir", "lib/embulk/filter/myfilter.rb").exists()) + assertTrue(File("$projectDir", "src/main/java/org/embulk/filter/myfilter/MyFilterFilterPlugin.java").exists()) } + + private fun build(vararg args: String): BuildResult = newRunner(*args, "--stacktrace").build() + private fun buildAndFail(vararg args: String): BuildResult = newRunner(*args, "--stacktrace").buildAndFail() + + private fun newRunner(vararg args: String): GradleRunner = GradleRunner.create() + .withProjectDir(projectDir) + .withArguments(*args) + .withDebug(true) + .withPluginClasspath() + + private fun createFile(name: String) = File(projectDir, name) } From 0c4e14227074190774283c4a18c6f15d20325da9 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 15:16:34 +0900 Subject: [PATCH 03/11] Add a test for classpath task --- .../kamatama41/gradle/embulk/EmbulkPluginTest.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt index 99f2d5a..e8bee8a 100644 --- a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt +++ b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt @@ -18,6 +18,13 @@ class EmbulkPluginTest : RepositoryTestCase() { setupProject() } + @Test + fun classpath() { + build("classpath") + // Check generated a Jar file + assertTrue(File("$projectDir/classpath/embulk-filter-myfilter-0.1.0.jar").exists()) + } + @Test fun checkstyle() { // Generated plugin Java code has checkstyle error by default, so it will fail. @@ -28,11 +35,17 @@ class EmbulkPluginTest : RepositoryTestCase() { assertTrue(File("$buildDir/config/checkstyle/default.xml").exists()) } + ////////////////////////////////////////////////////////////// + // Helper functions + ////////////////////////////////////////////////////////////// + private fun setupProject() { testProjectDir = createWorkRepository() createFile("build.gradle").writeText(""" plugins { id "com.github.kamatama41.embulk" } + version = "0.1.0" + embulk { version = "0.8.18" category = "filter" @@ -40,7 +53,9 @@ class EmbulkPluginTest : RepositoryTestCase() { homepage = "https://github.com/someuser/embulk-filter-myfilter" } """) + createFile("settings.gradle").writeText("""rootProject.name = 'embulk-filter-myfilter'""") + // Generate new plugin codes build("newPlugin") assertTrue(File("$projectDir", "README.md").exists()) assertTrue(File("$projectDir", "LICENSE.txt").exists()) From 1cd600fdcbd6f4ce0ba342fcab7d5b218303a8f9 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 16:44:17 +0900 Subject: [PATCH 04/11] Add a test for gemspec task --- build.gradle | 3 - .../gradle/embulk/EmbulkExtension.kt | 10 ++- .../kamatama41/gradle/embulk/EmbulkPlugin.kt | 39 +++------ .../github/kamatama41/gradle/embulk/Git.kt | 43 ---------- .../gradle/embulk/EmbulkPluginTest.kt | 83 ++++++++++++++----- 5 files changed, 85 insertions(+), 93 deletions(-) delete mode 100644 src/main/kotlin/com/github/kamatama41/gradle/embulk/Git.kt diff --git a/build.gradle b/build.gradle index 6777de1..12e100e 100644 --- a/build.gradle +++ b/build.gradle @@ -22,16 +22,13 @@ repositories { sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7 -def jgitVersion = "4.3.1.201605051710-r" dependencies { compile gradleApi() compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - compile "org.eclipse.jgit:org.eclipse.jgit:$jgitVersion" compile "com.google.guava:guava:20.0" compile "com.github.jruby-gradle:jruby-gradle-plugin:0.1.5" testCompile gradleTestKit() testCompile "junit:junit:4.12" - testCompile "org.eclipse.jgit:org.eclipse.jgit.junit:$jgitVersion" } gitRelease { diff --git a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt index ab6262d..affede3 100644 --- a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt +++ b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt @@ -7,10 +7,10 @@ open class EmbulkExtension(project: Project) { lateinit var version: String lateinit var category: String lateinit var name: String - var authors: Array = emptyArray() + lateinit var authors: Array + lateinit var email: String var summary: String? = null var description: String? = null - var email: String? = null var licenses = arrayOf("MIT") var homepage = "" var jrubyVersion = "1.7.19" // TODO: update (currently v9.1.x) @@ -24,4 +24,10 @@ open class EmbulkExtension(project: Project) { val binFile get() = File("${workDir.absolutePath}/$version/embulk") var configYaml = "config.yml" var outputYaml = "output.yml" + + val embulkCategory get() = when(category) { + "file-input" -> "input" + "file-output" -> "output" + else -> category + } } diff --git a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt index 7525ee5..8130edd 100644 --- a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt +++ b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt @@ -21,7 +21,6 @@ import java.net.URL class EmbulkPlugin : Plugin { lateinit var project: Project lateinit var extension: EmbulkExtension - lateinit var git: Git val extensionName = "embulk" val classpathDir = "classpath" val gemspecFile: File by lazy { project.file("${project.name}.gemspec") } @@ -34,7 +33,6 @@ class EmbulkPlugin : Plugin { override fun apply(project: Project) { this.project = project this.extension = project.extensions.create(extensionName, EmbulkExtension::class.java, project) - this.git = Git.new(project.rootProject.rootDir) project.plugins.apply(JavaPlugin::class.java) project.plugins.apply(JRubyPlugin::class.java) project.plugins.apply(CheckstylePlugin::class.java) @@ -58,14 +56,16 @@ class EmbulkPlugin : Plugin { task.group = groupName project.afterEvaluate { task.dependsOn("embulk_new_java-${extension.category}_${extension.name}") - task.from("embulk-${extension.category}-${extension.name}") { spec -> + + val pluginName = "embulk-${extension.embulkCategory}-${extension.name}" + task.from(pluginName) { spec -> DirectoryScanner.removeDefaultExclude("**/.gitignore") spec.include("lib/**", "src/**", "README.md", "LICENSE.txt", ".gitignore") } task.into(".") task.doLast { - project.delete("embulk-${extension.category}-${extension.name}") + project.delete(pluginName) } } } @@ -100,17 +100,16 @@ class EmbulkPlugin : Plugin { task.inputs.file("build.gradle") task.outputs.file(gemspecFile) - git.config() task.doLast { gemspecFile.writeText(""" |Gem::Specification.new do |spec| | spec.name = "${project.name}" | spec.version = "${project.version}" - | spec.authors = ["${generateAuthors(extension)}"] - | spec.summary = %[${generateSummary(extension)}] - | spec.description = %[${generateDescription(extension)}] - | spec.email = ["${generateEmail(extension)}"] + | spec.authors = ["${extension.authors.joinToString("\", \"")}"] + | spec.summary = %[${generateSummary()}] + | spec.description = %[${generateDescription()}] + | spec.email = ["${extension.email}"] | spec.licenses = ["${extension.licenses.joinToString()}"] | spec.homepage = "${extension.homepage}" | @@ -218,29 +217,17 @@ class EmbulkPlugin : Plugin { project.tasks.addRule(EmbulkExecRule(project, extension)) } - private fun generateAuthors(extension: EmbulkExtension): String { - return if (extension.authors.isEmpty()) { - this.git.config().getString("user", null, "name") - } else { - extension.authors.joinToString() - } - } - - private fun generateEmail(extension: EmbulkExtension): String - = extension.email ?: this.git.config().getString("user", null, "email") - - private fun generateSummary(extension: EmbulkExtension): String { - return extension.summary ?: "${extension.name.toUpperCamel()} ${extension.category} plugin for Embulk" - } + private fun generateSummary(): String + = extension.summary ?: "${extension.name.toUpperCamel()} ${extension.category.replace("-", " ")} plugin for Embulk" - private fun generateDescription(extension: EmbulkExtension): String { + private fun generateDescription(): String { return extension.description ?: when (extension.category) { "input" -> "Loads records from ${extension.name}." - "file_input" -> "Reads files stored on ${extension.name}." + "file-input" -> "Reads files stored on ${extension.name}." "parser" -> "Parses ${extension.name} files read by other file input plugins." "decoder" -> "Decodes ${extension.name}}-encoded files read by other file input plugins." "output" -> "Dumps records to ${extension.name}." - "file_output" -> "Stores files on ${extension.name}." + "file-output" -> "Stores files on ${extension.name}." "formatter" -> "Formats ${extension.name} files for other file output plugins." "encoder" -> "Encodes files using ${extension.name} for other file output plugins." "filter" -> extension.name diff --git a/src/main/kotlin/com/github/kamatama41/gradle/embulk/Git.kt b/src/main/kotlin/com/github/kamatama41/gradle/embulk/Git.kt deleted file mode 100644 index c46ee49..0000000 --- a/src/main/kotlin/com/github/kamatama41/gradle/embulk/Git.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.github.kamatama41.gradle.embulk - -import org.eclipse.jgit.lib.Config -import org.eclipse.jgit.storage.file.FileRepositoryBuilder -import org.eclipse.jgit.api.Git as JGit -import java.io.File - -class Git private constructor(val git: JGit) { - - fun add(vararg patterns: String) { - val cmd = git.add() - if (patterns.isEmpty()) { - cmd.isUpdate = true - } else { - patterns.forEach { cmd.addFilepattern(it) } - } - cmd.call() - } - - fun rm(vararg patterns: String, cached: Boolean = false) { - val cmd = git.rm() - cmd.setCached(cached) - patterns.forEach { cmd.addFilepattern(it) } - cmd.call() - } - - fun commit(vararg paths: String, message: String = "Commit by Gradle") { - val commit = git.commit() - commit.message = message - paths.forEach { commit.setOnly(it) } - commit.call() - } - - fun config(): Config = git.repository.config - - companion object { - fun new(gitDir: File): Git = - Git(JGit(FileRepositoryBuilder().readEnvironment().findGitDir(gitDir).build())) - - fun init(gitDir: File): Git = - Git(JGit.init().setDirectory(gitDir).call()) - } -} diff --git a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt index e8bee8a..ab48875 100644 --- a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt +++ b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt @@ -1,20 +1,25 @@ package com.github.kamatama41.gradle.embulk -import org.eclipse.jgit.internal.storage.file.FileRepository -import org.eclipse.jgit.junit.RepositoryTestCase import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner +import org.hamcrest.CoreMatchers.`is` +import org.junit.Assert.assertFalse +import org.junit.Assert.assertThat import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Rule import org.junit.Test +import org.junit.rules.TemporaryFolder import java.io.File -class EmbulkPluginTest : RepositoryTestCase() { - lateinit var testProjectDir: FileRepository - val projectDir by lazy { File("${testProjectDir.directory}/..") } +class EmbulkPluginTest { + @Rule @JvmField + val testProjectDir = TemporaryFolder() + val projectDir by lazy { testProjectDir.root!! } val buildDir by lazy { "${projectDir.absolutePath}/build/embulk" } - override fun setUp() { - super.setUp() + @Before + fun setUp() { setupProject() } @@ -22,7 +27,32 @@ class EmbulkPluginTest : RepositoryTestCase() { fun classpath() { build("classpath") // Check generated a Jar file - assertTrue(File("$projectDir/classpath/embulk-filter-myfilter-0.1.0.jar").exists()) + assertTrue(File("$projectDir/classpath/embulk-input-xlsx-0.1.0.jar").exists()) + } + + @Test + fun gemspec() { + build("gemspec") + assertThat(projectFile("embulk-input-xlsx.gemspec").readText(), `is`(""" + |Gem::Specification.new do |spec| + | spec.name = "embulk-input-xlsx" + | spec.version = "0.1.0" + | spec.authors = ["Author 1", "Author 2"] + | spec.summary = %[Xlsx file input plugin for Embulk] + | spec.description = %[Reads files stored on xlsx.] + | spec.email = ["auser@example.com"] + | spec.licenses = ["MIT"] + | spec.homepage = "https://github.com/someuser/embulk-input-xlsx" + | + | 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 + """.trimMargin())) } @Test @@ -40,32 +70,47 @@ class EmbulkPluginTest : RepositoryTestCase() { ////////////////////////////////////////////////////////////// private fun setupProject() { - testProjectDir = createWorkRepository() - createFile("build.gradle").writeText(""" + projectFile("build.gradle").writeText(""" plugins { id "com.github.kamatama41.embulk" } version = "0.1.0" embulk { version = "0.8.18" - category = "filter" - name = "myfilter" - homepage = "https://github.com/someuser/embulk-filter-myfilter" + category = "file-input" + name = "xlsx" + authors = ["Author 1", "Author 2"] + email = "auser@example.com" + homepage = "https://github.com/someuser/embulk-input-xlsx" } """) - createFile("settings.gradle").writeText("""rootProject.name = 'embulk-filter-myfilter'""") + projectFile("settings.gradle").writeText("""rootProject.name = 'embulk-input-xlsx'""") // Generate new plugin codes build("newPlugin") assertTrue(File("$projectDir", "README.md").exists()) assertTrue(File("$projectDir", "LICENSE.txt").exists()) assertTrue(File("$projectDir", ".gitignore").exists()) - assertTrue(File("$projectDir", "lib/embulk/filter/myfilter.rb").exists()) - assertTrue(File("$projectDir", "src/main/java/org/embulk/filter/myfilter/MyFilterFilterPlugin.java").exists()) + assertTrue(File("$projectDir", "lib/embulk/input/xlsx.rb").exists()) + assertTrue(File("$projectDir", "src/main/java/org/embulk/input/xlsx/XlsxFileInputPlugin.java").exists()) + assertFalse(File("$projectDir", "embulk-input-xlsx").exists()) } - private fun build(vararg args: String): BuildResult = newRunner(*args, "--stacktrace").build() - private fun buildAndFail(vararg args: String): BuildResult = newRunner(*args, "--stacktrace").buildAndFail() + private fun build(vararg args: String): BuildResult { + val result = newRunner(*args, "--stacktrace").build() + println("===========================================") + println(result.output) + println("===========================================") + return result + } + + private fun buildAndFail(vararg args: String): BuildResult { + val result = newRunner(*args, "--stacktrace").buildAndFail() + println("===========================================") + println(result.output) + println("===========================================") + return result + } private fun newRunner(vararg args: String): GradleRunner = GradleRunner.create() .withProjectDir(projectDir) @@ -73,5 +118,5 @@ class EmbulkPluginTest : RepositoryTestCase() { .withDebug(true) .withPluginClasspath() - private fun createFile(name: String) = File(projectDir, name) + private fun projectFile(name: String) = File(projectDir, name) } From 908216ec0c7c96d9707057e01ec574d76dc1cc1e Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 16:49:36 +0900 Subject: [PATCH 05/11] Refactor --- .../com/github/kamatama41/gradle/embulk/EmbulkExtension.kt | 2 ++ .../kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt index affede3..69c973e 100644 --- a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt +++ b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkExtension.kt @@ -25,6 +25,8 @@ open class EmbulkExtension(project: Project) { var configYaml = "config.yml" var outputYaml = "output.yml" + val displayName get() = name.toUpperCamel() + val displayCategory get() = category.replace("-", " ") val embulkCategory get() = when(category) { "file-input" -> "input" "file-output" -> "output" diff --git a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt index 8130edd..2056077 100644 --- a/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt +++ b/src/main/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPlugin.kt @@ -218,7 +218,7 @@ class EmbulkPlugin : Plugin { } private fun generateSummary(): String - = extension.summary ?: "${extension.name.toUpperCamel()} ${extension.category.replace("-", " ")} plugin for Embulk" + = extension.summary ?: "${extension.displayName} ${extension.displayCategory} plugin for Embulk" private fun generateDescription(): String { return extension.description ?: when (extension.category) { From 589850eb273a165e11e2460f675cb9f614144459 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 16:55:36 +0900 Subject: [PATCH 06/11] Set workdir to reduce testing time --- .../com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt index ab48875..6916481 100644 --- a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt +++ b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt @@ -82,6 +82,7 @@ class EmbulkPluginTest { authors = ["Author 1", "Author 2"] email = "auser@example.com" homepage = "https://github.com/someuser/embulk-input-xlsx" + workDir = file("${File("./.gradle/embulk").absolutePath}") } """) projectFile("settings.gradle").writeText("""rootProject.name = 'embulk-input-xlsx'""") From cb7d24ffc28efc1084ab3acc1073892df8ddca6d Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 17:11:41 +0900 Subject: [PATCH 07/11] Fix a but that cannot be published --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index 12e100e..02d026a 100644 --- a/build.gradle +++ b/build.gradle @@ -37,3 +37,7 @@ gitRelease { repoUri = "git@github.com:kamatama41/maven-repository.git" repoDir = file("${System.getProperty("user.home")}/gh-maven-repository") } + +gradlePlugin { + automatedPublishing = false +} From d7b1c07b969d4e78e85867ded5f35149cd330ba1 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 17:12:11 +0900 Subject: [PATCH 08/11] Add a sandbox directory --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e808150..5e12a26 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ gradle-app.setting # gradle/wrapper/gradle-wrapper.properties .idea + +sandbox From 61b2c554ea5d29330f9198fe6256f2b5cea184d9 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 17:13:44 +0900 Subject: [PATCH 09/11] Integrate tests for gemspec and classpath --- .../kamatama41/gradle/embulk/EmbulkPluginTest.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt index 6916481..d944acf 100644 --- a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt +++ b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt @@ -24,15 +24,11 @@ class EmbulkPluginTest { } @Test - fun classpath() { - build("classpath") - // Check generated a Jar file + fun packageTask() { + build("package") + // Check a Jar file was generated assertTrue(File("$projectDir/classpath/embulk-input-xlsx-0.1.0.jar").exists()) - } - - @Test - fun gemspec() { - build("gemspec") + // Check a content of generated gemspec file assertThat(projectFile("embulk-input-xlsx.gemspec").readText(), `is`(""" |Gem::Specification.new do |spec| | spec.name = "embulk-input-xlsx" @@ -56,7 +52,7 @@ class EmbulkPluginTest { } @Test - fun checkstyle() { + fun checkstyleTask() { // Generated plugin Java code has checkstyle error by default, so it will fail. buildAndFail("checkstyle") From e2afd3bc982641e721435af2b3ace40d69f86d44 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 17:35:21 +0900 Subject: [PATCH 10/11] Refactor --- .../gradle/embulk/EmbulkPluginTest.kt | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt index d944acf..77d8c39 100644 --- a/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt +++ b/src/test/kotlin/com/github/kamatama41/gradle/embulk/EmbulkPluginTest.kt @@ -3,6 +3,7 @@ package com.github.kamatama41.gradle.embulk import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner import org.hamcrest.CoreMatchers.`is` +import org.hamcrest.CoreMatchers.containsString import org.junit.Assert.assertFalse import org.junit.Assert.assertThat import org.junit.Assert.assertTrue @@ -23,9 +24,20 @@ class EmbulkPluginTest { setupProject() } + @Test + fun newPluginTask() { + build("newPlugin") + assertTrue(File("$projectDir", "README.md").exists()) + assertTrue(File("$projectDir", "LICENSE.txt").exists()) + assertTrue(File("$projectDir", ".gitignore").exists()) + assertTrue(File("$projectDir", "lib/embulk/input/xlsx.rb").exists()) + assertTrue(File("$projectDir", "src/main/java/org/embulk/input/xlsx/XlsxFileInputPlugin.java").exists()) + assertFalse(File("$projectDir", "embulk-input-xlsx").exists()) + } + @Test fun packageTask() { - build("package") + build("newPlugin", "package") // Check a Jar file was generated assertTrue(File("$projectDir/classpath/embulk-input-xlsx-0.1.0.jar").exists()) // Check a content of generated gemspec file @@ -51,10 +63,29 @@ class EmbulkPluginTest { """.trimMargin())) } + @Test + fun runEmbulkTask() { + projectFile("config.yml").writeText(""" + |in: + | type: xlsx + | option1: 1 + | option2: opt2 + | option3: opt3 + | parser: + | type: csv + | columns: [] + |out: {type: stdout} + """.trimMargin()) + + // Run will fail because of UnsupportedOperationException + val result = buildAndFail("newPlugin", "embulk_run") + assertThat(result.output, containsString("Caused by: java.lang.UnsupportedOperationException: XlsxFileInputPlugin.open method is not implemented yet")) + } + @Test fun checkstyleTask() { // Generated plugin Java code has checkstyle error by default, so it will fail. - buildAndFail("checkstyle") + buildAndFail("newPlugin", "checkstyle") // Check generated checkstyle.xml and default.xml to build dir. assertTrue(File("$buildDir/config/checkstyle/checkstyle.xml").exists()) @@ -82,15 +113,6 @@ class EmbulkPluginTest { } """) projectFile("settings.gradle").writeText("""rootProject.name = 'embulk-input-xlsx'""") - - // Generate new plugin codes - build("newPlugin") - assertTrue(File("$projectDir", "README.md").exists()) - assertTrue(File("$projectDir", "LICENSE.txt").exists()) - assertTrue(File("$projectDir", ".gitignore").exists()) - assertTrue(File("$projectDir", "lib/embulk/input/xlsx.rb").exists()) - assertTrue(File("$projectDir", "src/main/java/org/embulk/input/xlsx/XlsxFileInputPlugin.java").exists()) - assertFalse(File("$projectDir", "embulk-input-xlsx").exists()) } private fun build(vararg args: String): BuildResult { From 4a1171b8c829e26be243ebc0f178a3b007bddd61 Mon Sep 17 00:00:00 2001 From: Shinichi Ishimura Date: Sun, 19 Mar 2017 18:24:25 +0900 Subject: [PATCH 11/11] Update README --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 235117e..b7270a9 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,11 @@ apply plugin: "com.github.kamatama41.embulk" embulk { version = "0.8.18" - category = "filter" - name = "myfilter" - homepage = "https://github.com/someuser/embulk-filter-myfilter" + category = "file-input" + name = "xlsx" + authors = ["A User"] + email = "a.user@example.com" + homepage = "https://github.com/a.user/embulk-input-xlsx" } ```