Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
provided "org.embulk:embulk-core:0.7.0"
// compile "YOUR_JAR_DEPENDENCY_GROUP:YOUR_JAR_DEPENDENCY_MODULE:YOUR_JAR_DEPENDENCY_VERSION"
testCompile "junit:junit:4.+"
testCompile 'org.embulk:embulk-core:0.7.+:tests'
}

task classpath(type: Copy, dependsOn: ["jar"]) {
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/org/embulk/output/CommandFileOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.io.OutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;

import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -32,11 +34,6 @@ public interface PluginTask
public String getCommand();
}

public static final List<String> SHELL = ImmutableList.of(
// TODO use ["PowerShell.exe", "-Command"] on windows?
"sh", "-c"
);

@Override
public ConfigDiff transaction(ConfigSource config, int taskCount,
FileOutputPlugin.Control control)
Expand Down Expand Up @@ -68,15 +65,36 @@ public TransactionalFileOutput open(TaskSource taskSource, final int taskIndex)
{
PluginTask task = taskSource.loadTask(PluginTask.class);

List<String> shell = new ShellFactory().build().get();
List<String> cmdline = new ArrayList<String>();
cmdline.addAll(SHELL);
cmdline.addAll(shell);
cmdline.add(task.getCommand());

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

return new PluginFileOutput(cmdline, taskIndex);
}

@VisibleForTesting
static class ShellFactory
{
private List<String> shell;

public List<String> get() {
return this.shell;
}

public ShellFactory build() {
String osName = System.getProperty("os.name");
if(osName.indexOf("Windows") >= 0) {
this.shell = ImmutableList.of("PowerShell.exe", "-Command");
} else {
this.shell = ImmutableList.of("sh", "-c");
}
return this;
}
}

private static class ProcessWaitOutputStream
extends FilterOutputStream
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
package org.embulk.output;

import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.embulk.EmbulkTestRuntime;
import org.embulk.output.CommandFileOutputPlugin.ShellFactory;

import java.util.List;

import static org.junit.Assert.assertEquals;

public class TestCommandFileOutputPlugin
{
@Rule
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();

private ShellFactory shellFactory;

@Before
public void createResources()
{
shellFactory = new ShellFactory().build();
}

@Test
public void testShell() {
List<String> shell = shellFactory.get();
String osName = System.getProperty("os.name");
List<String> actualShellCmd;
if (osName.indexOf("Windows") >= 0) {
actualShellCmd = ImmutableList.of("PowerShell.exe", "-Command");
} else {
actualShellCmd = ImmutableList.of("sh", "-c");
}
assertEquals(actualShellCmd, shell);
}
}