Skip to content

Commit 8f4f05e

Browse files
committed
Merge pull request #1 from cosmo0920/initial-support-windows
Initial support windows
2 parents af04e7b + 5bed377 commit 8f4f05e

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919
provided "org.embulk:embulk-core:0.7.0"
2020
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
2121
testCompile "junit:junit:4.+"
22+
testCompile 'org.embulk:embulk-core:0.7.+:tests'
2223
}
2324

2425
task classpath(type: Copy, dependsOn: ["jar"]) {

src/main/java/org/embulk/output/CommandFileOutputPlugin.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.io.OutputStream;
66
import java.io.FilterOutputStream;
77
import java.io.IOException;
8+
9+
import com.google.common.annotations.VisibleForTesting;
810
import org.slf4j.Logger;
911
import com.google.common.base.Throwables;
1012
import com.google.common.collect.ImmutableList;
@@ -32,11 +34,6 @@ public interface PluginTask
3234
public String getCommand();
3335
}
3436

35-
public static final List<String> SHELL = ImmutableList.of(
36-
// TODO use ["PowerShell.exe", "-Command"] on windows?
37-
"sh", "-c"
38-
);
39-
4037
@Override
4138
public ConfigDiff transaction(ConfigSource config, int taskCount,
4239
FileOutputPlugin.Control control)
@@ -68,15 +65,36 @@ public TransactionalFileOutput open(TaskSource taskSource, final int taskIndex)
6865
{
6966
PluginTask task = taskSource.loadTask(PluginTask.class);
7067

68+
List<String> shell = new ShellFactory().build().get();
7169
List<String> cmdline = new ArrayList<String>();
72-
cmdline.addAll(SHELL);
70+
cmdline.addAll(shell);
7371
cmdline.add(task.getCommand());
7472

7573
logger.info("Using command {}", cmdline);
7674

7775
return new PluginFileOutput(cmdline, taskIndex);
7876
}
7977

78+
@VisibleForTesting
79+
static class ShellFactory
80+
{
81+
private List<String> shell;
82+
83+
public List<String> get() {
84+
return this.shell;
85+
}
86+
87+
public ShellFactory build() {
88+
String osName = System.getProperty("os.name");
89+
if(osName.indexOf("Windows") >= 0) {
90+
this.shell = ImmutableList.of("PowerShell.exe", "-Command");
91+
} else {
92+
this.shell = ImmutableList.of("sh", "-c");
93+
}
94+
return this;
95+
}
96+
}
97+
8098
private static class ProcessWaitOutputStream
8199
extends FilterOutputStream
82100
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,39 @@
11
package org.embulk.output;
22

3+
import com.google.common.collect.ImmutableList;
4+
import org.junit.Before;
5+
import org.junit.Rule;
6+
import org.junit.Test;
7+
import org.embulk.EmbulkTestRuntime;
8+
import org.embulk.output.CommandFileOutputPlugin.ShellFactory;
9+
10+
import java.util.List;
11+
12+
import static org.junit.Assert.assertEquals;
13+
314
public class TestCommandFileOutputPlugin
415
{
16+
@Rule
17+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
18+
19+
private ShellFactory shellFactory;
20+
21+
@Before
22+
public void createResources()
23+
{
24+
shellFactory = new ShellFactory().build();
25+
}
26+
27+
@Test
28+
public void testShell() {
29+
List<String> shell = shellFactory.get();
30+
String osName = System.getProperty("os.name");
31+
List<String> actualShellCmd;
32+
if (osName.indexOf("Windows") >= 0) {
33+
actualShellCmd = ImmutableList.of("PowerShell.exe", "-Command");
34+
} else {
35+
actualShellCmd = ImmutableList.of("sh", "-c");
36+
}
37+
assertEquals(actualShellCmd, shell);
38+
}
539
}

0 commit comments

Comments
 (0)