From 1ffa5d9440018701a41561526d5e620871903dcf Mon Sep 17 00:00:00 2001 From: Sadayuki Furuhashi Date: Wed, 13 Jan 2016 17:14:06 -0800 Subject: [PATCH 1/2] add support for windows environment --- build.gradle | 5 ++-- .../embulk/input/CommandFileInputPlugin.java | 14 ++++++++++- .../input/TestCommandFileInputPlugin.java | 23 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index a1a26da..71b67bc 100644 --- a/build.gradle +++ b/build.gradle @@ -15,8 +15,9 @@ configurations { version = "0.1.3" dependencies { - compile "org.embulk:embulk-core:0.7.0" - provided "org.embulk:embulk-core:0.7.0" + compile "org.embulk:embulk-core:0.7.+" + provided "org.embulk:embulk-core:0.7.+" + testCompile 'org.embulk:embulk-core:0.7.+:tests' testCompile "junit:junit:4.+" } diff --git a/src/main/java/org/embulk/input/CommandFileInputPlugin.java b/src/main/java/org/embulk/input/CommandFileInputPlugin.java index 3c866a9..d6570b4 100644 --- a/src/main/java/org/embulk/input/CommandFileInputPlugin.java +++ b/src/main/java/org/embulk/input/CommandFileInputPlugin.java @@ -5,6 +5,7 @@ import java.io.InputStream; import java.io.IOException; import java.io.FilterInputStream; +import com.google.common.annotations.VisibleForTesting; import org.slf4j.Logger; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; @@ -88,7 +89,7 @@ public TransactionalFileInput open(TaskSource taskSource, int taskIndex) PluginTask task = taskSource.loadTask(PluginTask.class); List cmdline = new ArrayList(); - cmdline.addAll(SHELL); + cmdline.addAll(buildShell()); cmdline.add(task.getCommand()); logger.info("Running command {}", cmdline); @@ -131,6 +132,17 @@ public TransactionalFileInput open(TaskSource taskSource, int taskIndex) } } + @VisibleForTesting + static List buildShell() + { + String osName = System.getProperty("os.name"); + if(osName.indexOf("Windows") >= 0) { + return ImmutableList.of("PowerShell.exe", "-Command"); + } else { + return ImmutableList.of("sh", "-c"); + } + } + private static class ProcessWaitInputStream extends FilterInputStream { diff --git a/src/test/java/org/embulk/input/TestCommandFileInputPlugin.java b/src/test/java/org/embulk/input/TestCommandFileInputPlugin.java index 6a4b3d0..b54af75 100644 --- a/src/test/java/org/embulk/input/TestCommandFileInputPlugin.java +++ b/src/test/java/org/embulk/input/TestCommandFileInputPlugin.java @@ -1,5 +1,28 @@ package org.embulk.input; +import com.google.common.collect.ImmutableList; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.embulk.EmbulkTestRuntime; +import static org.embulk.input.CommandFileInputPlugin.buildShell; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + public class TestCommandFileInputPlugin { + @Rule + public EmbulkTestRuntime runtime = new EmbulkTestRuntime(); + + @Test + public void testShell() { + if (System.getProperty("os.name").indexOf("Windows") >= 0) { + assertEquals(ImmutableList.of("PowerShell.exe", "-Command"), buildShell()); + } + else { + assertEquals(ImmutableList.of("sh", "-c"), buildShell()); + } + } } From 3c558f9876f70a72f7334b89269da58a70988834 Mon Sep 17 00:00:00 2001 From: Sadayuki Furuhashi Date: Wed, 13 Jan 2016 17:15:19 -0800 Subject: [PATCH 2/2] updated README.md about shell on windows --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ec1ae0..00e68fd 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This plugin runs a command and reads data from its stdout (or stderr). - **command**: command line (string, required) - **pipe**: stdout or stderr (string, default: stdout) -The **command** is exected using a shell. So it can include pipe (`|`), environment variables (`$VAR`), redirects, and so on. +The **command** is exected using a shell (`sh -c` on UNIX/Linux, `PowerShell.exe -Command` on Windows). Therefore, it can include pipe (`|`), environment variables (`$VAR`), redirects, and so on. ## Example