Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the Gradle wrapper to 8.7, the Gradle plugin to 0.7.0, and the embulk-spi to v0.11 #6

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
42 changes: 22 additions & 20 deletions src/main/java/org/embulk/output/CommandFileOutputPlugin.java
hiroyuki-sato marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,28 @@

import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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;
import org.embulk.config.TaskReport;
import org.embulk.config.Config;
import org.embulk.config.ConfigDefault;
import org.embulk.util.config.Config;
import org.embulk.config.ConfigDiff;
import org.embulk.config.ConfigSource;
import org.embulk.config.Task;
import org.embulk.util.config.ConfigMapper;
import org.embulk.util.config.ConfigMapperFactory;
import org.embulk.util.config.Task;
import org.embulk.util.config.TaskMapper;
import org.embulk.config.TaskSource;
import org.embulk.spi.Buffer;
import org.embulk.spi.Exec;
import org.embulk.spi.FileOutputPlugin;
import org.embulk.spi.TransactionalFileOutput;

public class CommandFileOutputPlugin
implements FileOutputPlugin
{
private final Logger logger = Exec.getLogger(getClass());

public interface PluginTask
extends Task
{
Expand All @@ -37,10 +35,11 @@ public interface PluginTask
public ConfigDiff transaction(ConfigSource config, int taskCount,
FileOutputPlugin.Control control)
{
PluginTask task = config.loadConfig(PluginTask.class);
final ConfigMapper configMapper = CONFIG_MAPPER_FACTORY.createConfigMapper();
final PluginTask task = configMapper.map(config, PluginTask.class);

// retryable (idempotent) output:
return resume(task.dump(), taskCount, control);
return resume(task.toTaskSource(), taskCount, control);
}

@Override
Expand All @@ -49,7 +48,7 @@ public ConfigDiff resume(TaskSource taskSource,
FileOutputPlugin.Control control)
{
control.run(taskSource);
return Exec.newConfigDiff();
return CONFIG_MAPPER_FACTORY.newConfigDiff();
}

@Override
Expand All @@ -62,7 +61,8 @@ public void cleanup(TaskSource taskSource,
@Override
public TransactionalFileOutput open(TaskSource taskSource, final int taskIndex)
{
PluginTask task = taskSource.loadTask(PluginTask.class);
final TaskMapper taskMapper = CONFIG_MAPPER_FACTORY.createTaskMapper();
final PluginTask task = taskMapper.map(taskSource, PluginTask.class);

List<String> cmdline = new ArrayList<String>();
cmdline.addAll(buildShell());
Expand All @@ -73,14 +73,13 @@ public TransactionalFileOutput open(TaskSource taskSource, final int taskIndex)
return new PluginFileOutput(cmdline, taskIndex);
}

@VisibleForTesting
static List<String> buildShell()
{
String osName = System.getProperty("os.name");
if(osName.indexOf("Windows") >= 0) {
return ImmutableList.of("PowerShell.exe", "-Command");
return Collections.unmodifiableList(Arrays.asList("PowerShell.exe", "-Command"));
} else {
return ImmutableList.of("sh", "-c");
return Collections.unmodifiableList(Arrays.asList("sh", "-c"));
}
}

Expand Down Expand Up @@ -109,7 +108,7 @@ private synchronized void waitFor() throws IOException
try {
code = process.waitFor();
} catch (InterruptedException ex) {
throw Throwables.propagate(ex);
throw new RuntimeException(ex);
}
process = null;
if (code != 0) {
Expand Down Expand Up @@ -171,7 +170,7 @@ public void abort()

public TaskReport commit()
{
return Exec.newTaskReport();
return CONFIG_MAPPER_FACTORY.newTaskReport();
}

private void closeCurrentProcess()
Expand All @@ -182,7 +181,7 @@ private void closeCurrentProcess()
currentProcess = null;
}
} catch (IOException ex) {
throw Throwables.propagate(ex);
throw new RuntimeException(ex);
}
}

Expand All @@ -198,8 +197,11 @@ private Process startProcess(List<String> cmdline, int taskIndex, int seqId)
try {
return builder.start();
} catch (IOException ex) {
throw Throwables.propagate(ex);
throw new RuntimeException(ex);
}
}
}
private static final Logger logger = org.slf4j.LoggerFactory.getLogger(CommandFileOutputPlugin.class);

private static final ConfigMapperFactory CONFIG_MAPPER_FACTORY = ConfigMapperFactory.builder().addDefaultModules().build();
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.embulk.output;

import com.google.common.collect.ImmutableList;
import org.junit.Before;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.embulk.EmbulkTestRuntime;
import org.embulk.test.EmbulkTestRuntime;
import static org.embulk.output.CommandFileOutputPlugin.buildShell;

import java.util.List;

import static org.junit.Assert.assertEquals;

public class TestCommandFileOutputPlugin
Expand All @@ -19,10 +17,11 @@ public class TestCommandFileOutputPlugin
@Test
public void testShell() {
if (System.getProperty("os.name").indexOf("Windows") >= 0) {
assertEquals(ImmutableList.of("PowerShell.exe", "-Command"), buildShell());
assertEquals(Collections.unmodifiableList(Arrays.asList("PowerShell.exe", "-Command"))
, buildShell());
}
else {
assertEquals(ImmutableList.of("sh", "-c"), buildShell());
assertEquals(Collections.unmodifiableList(Arrays.asList("sh", "-c")), buildShell());
}
}
}
Loading