Skip to content

Commit 454b3ce

Browse files
committed
Fix checkstyle error. Reformat codes and Optimize imports
1 parent 54b86e4 commit 454b3ce

File tree

2 files changed

+67
-88
lines changed

2 files changed

+67
-88
lines changed

src/main/java/org/embulk/input/CommandFileInputPlugin.java

Lines changed: 61 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
package org.embulk.input;
22

3+
import java.io.FilterInputStream;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.util.ArrayList;
37
import java.util.Arrays;
48
import java.util.Collections;
59
import java.util.List;
6-
import java.util.ArrayList;
7-
import java.io.InputStream;
8-
import java.io.IOException;
9-
import java.io.FilterInputStream;
10-
import org.slf4j.Logger;
10+
import org.embulk.config.ConfigDiff;
11+
import org.embulk.config.ConfigException;
12+
import org.embulk.config.ConfigSource;
1113
import org.embulk.config.TaskReport;
14+
import org.embulk.config.TaskSource;
15+
import org.embulk.spi.Exec;
16+
import org.embulk.spi.FileInputPlugin;
17+
import org.embulk.spi.TransactionalFileInput;
1218
import org.embulk.util.config.Config;
1319
import org.embulk.util.config.ConfigDefault;
1420
import org.embulk.util.config.ConfigMapper;
1521
import org.embulk.util.config.ConfigMapperFactory;
1622
import org.embulk.util.config.Task;
1723
import org.embulk.util.config.TaskMapper;
18-
import org.embulk.config.ConfigDiff;
19-
import org.embulk.config.ConfigSource;
20-
import org.embulk.config.ConfigException;
21-
import org.embulk.config.TaskSource;
22-
import org.embulk.spi.Exec;
23-
import org.embulk.spi.FileInputPlugin;
24-
import org.embulk.spi.TransactionalFileInput;
2524
import org.embulk.util.file.InputStreamFileInput;
25+
import org.slf4j.Logger;
2626
import org.slf4j.LoggerFactory;
2727

2828
public class CommandFileInputPlugin
29-
implements FileInputPlugin
30-
{
29+
implements FileInputPlugin {
3130
public interface PluginTask
32-
extends Task
33-
{
31+
extends Task {
3432
@Config("command")
3533
public String getCommand();
3634

@@ -41,18 +39,17 @@ public interface PluginTask
4139
}
4240

4341
@Override
44-
public ConfigDiff transaction(ConfigSource config, FileInputPlugin.Control control)
45-
{
42+
public ConfigDiff transaction(ConfigSource config, FileInputPlugin.Control control) {
4643
final ConfigMapper configMapper = CONFIG_MAPPER_FACTORY.createConfigMapper();
4744
final PluginTask task = configMapper.map(config, PluginTask.class);
4845

4946
switch (task.getPipe()) {
50-
case "stdout":
51-
break;
52-
case "stderr":
53-
break;
54-
default:
55-
throw new ConfigException(String.format(
47+
case "stdout":
48+
break;
49+
case "stderr":
50+
break;
51+
default:
52+
throw new ConfigException(String.format(
5653
"Unknown 'pipe' option '%s'. It must be either 'stdout' or 'stderr'", task.getPipe()));
5754
}
5855

@@ -61,24 +58,22 @@ public ConfigDiff transaction(ConfigSource config, FileInputPlugin.Control contr
6158

6259
@Override
6360
public ConfigDiff resume(TaskSource taskSource,
64-
int taskCount,
65-
FileInputPlugin.Control control)
66-
{
61+
int taskCount,
62+
FileInputPlugin.Control control) {
6763
control.run(taskSource, taskCount);
6864

6965
return CONFIG_MAPPER_FACTORY.newConfigDiff();
7066
}
7167

7268
@Override
7369
public void cleanup(TaskSource taskSource,
74-
int taskCount,
75-
List<TaskReport> successTaskReports)
76-
{
70+
int taskCount,
71+
List<TaskReport> successTaskReports) {
7772
}
7873

74+
@SuppressWarnings("MissingSwitchDefault")
7975
@Override
80-
public TransactionalFileInput open(TaskSource taskSource, int taskIndex)
81-
{
76+
public TransactionalFileInput open(TaskSource taskSource, int taskIndex) {
8277
final TaskMapper taskMapper = CONFIG_MAPPER_FACTORY.createTaskMapper();
8378
final PluginTask task = taskMapper.map(taskSource, PluginTask.class);
8479

@@ -90,12 +85,12 @@ public TransactionalFileInput open(TaskSource taskSource, int taskIndex)
9085

9186
ProcessBuilder builder = new ProcessBuilder(cmdline.toArray(new String[cmdline.size()]));
9287
switch (task.getPipe()) {
93-
case "stdout":
94-
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
95-
break;
96-
case "stderr":
97-
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
98-
break;
88+
case "stdout":
89+
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
90+
break;
91+
case "stderr":
92+
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
93+
break;
9994
}
10095

10196
try {
@@ -104,12 +99,12 @@ public TransactionalFileInput open(TaskSource taskSource, int taskIndex)
10499
InputStream stream = null;
105100
try {
106101
switch (task.getPipe()) {
107-
case "stdout":
108-
stream = process.getInputStream();
109-
break;
110-
case "stderr":
111-
stream = process.getErrorStream();
112-
break;
102+
case "stdout":
103+
stream = process.getInputStream();
104+
break;
105+
case "stderr":
106+
stream = process.getErrorStream();
107+
break;
113108
}
114109

115110
PluginFileInput input = new PluginFileInput(task, new ProcessWaitInputStream(stream, process));
@@ -126,30 +121,26 @@ public TransactionalFileInput open(TaskSource taskSource, int taskIndex)
126121
}
127122
}
128123

129-
static List<String> buildShell()
130-
{
124+
static List<String> buildShell() {
131125
String osName = System.getProperty("os.name");
132-
if(osName.indexOf("Windows") >= 0) {
126+
if (osName.indexOf("Windows") >= 0) {
133127
return Collections.unmodifiableList(Arrays.asList("PowerShell.exe", "-Command"));
134128
} else {
135129
return Collections.unmodifiableList(Arrays.asList("sh", "-c"));
136130
}
137131
}
138132

139133
private static class ProcessWaitInputStream
140-
extends FilterInputStream
141-
{
134+
extends FilterInputStream {
142135
private Process process;
143136

144-
public ProcessWaitInputStream(InputStream in, Process process)
145-
{
137+
public ProcessWaitInputStream(InputStream in, Process process) {
146138
super(in);
147139
this.process = process;
148140
}
149141

150142
@Override
151-
public int read() throws IOException
152-
{
143+
public int read() throws IOException {
153144
int c = super.read();
154145
if (c < 0) {
155146
waitFor();
@@ -158,8 +149,7 @@ public int read() throws IOException
158149
}
159150

160151
@Override
161-
public int read(byte[] b) throws IOException
162-
{
152+
public int read(byte[] b) throws IOException {
163153
int c = super.read(b);
164154
if (c < 0) {
165155
waitFor();
@@ -168,8 +158,7 @@ public int read(byte[] b) throws IOException
168158
}
169159

170160
@Override
171-
public int read(byte[] b, int off, int len) throws IOException
172-
{
161+
public int read(byte[] b, int off, int len) throws IOException {
173162
int c = super.read(b, off, len);
174163
if (c < 0) {
175164
waitFor();
@@ -178,14 +167,12 @@ public int read(byte[] b, int off, int len) throws IOException
178167
}
179168

180169
@Override
181-
public void close() throws IOException
182-
{
170+
public void close() throws IOException {
183171
super.close();
184172
waitFor();
185173
}
186174

187-
private synchronized void waitFor() throws IOException
188-
{
175+
private synchronized void waitFor() throws IOException {
189176
if (process != null) {
190177
int code;
191178
try {
@@ -196,7 +183,7 @@ private synchronized void waitFor() throws IOException
196183
process = null;
197184
if (code != 0) {
198185
throw new IOException(String.format(
199-
"Command finished with non-zero exit code. Exit code is %d.", code));
186+
"Command finished with non-zero exit code. Exit code is %d.", code));
200187
}
201188
}
202189
}
@@ -205,22 +192,18 @@ private synchronized void waitFor() throws IOException
205192
// TODO almost copied from S3FileInputPlugin. include an InputStreamFileInput utility to embulk-core.
206193
public static class PluginFileInput
207194
extends InputStreamFileInput
208-
implements TransactionalFileInput
209-
{
195+
implements TransactionalFileInput {
210196
private static class SingleFileProvider
211-
implements InputStreamFileInput.Provider
212-
{
197+
implements InputStreamFileInput.Provider {
213198
private final InputStream stream;
214199
private boolean opened = false;
215200

216-
public SingleFileProvider(InputStream stream)
217-
{
201+
public SingleFileProvider(InputStream stream) {
218202
this.stream = stream;
219203
}
220204

221205
@Override
222-
public InputStream openNext() throws IOException
223-
{
206+
public InputStream openNext() throws IOException {
224207
if (opened) {
225208
return null;
226209
}
@@ -229,29 +212,29 @@ public InputStream openNext() throws IOException
229212
}
230213

231214
@Override
232-
public void close() throws IOException
233-
{
215+
public void close() throws IOException {
234216
if (!opened) {
235217
stream.close();
236218
}
237219
}
238220
}
239221

240-
public PluginFileInput(PluginTask task, InputStream stream)
241-
{
222+
public PluginFileInput(PluginTask task, InputStream stream) {
242223
super(Exec.getBufferAllocator(), new SingleFileProvider(stream));
243224
}
244225

245-
public void abort() { }
226+
public void abort() {
227+
}
246228

247-
public TaskReport commit()
248-
{
229+
public TaskReport commit() {
249230
return CONFIG_MAPPER_FACTORY.newTaskReport();
250231
}
251232

252233
@Override
253-
public void close() { }
234+
public void close() {
235+
}
254236
}
237+
255238
private static final Logger logger = LoggerFactory.getLogger(CommandFileInputPlugin.class);
256239

257240
private static final ConfigMapperFactory CONFIG_MAPPER_FACTORY = ConfigMapperFactory.builder().addDefaultModules().build();

src/test/java/org/embulk/input/TestCommandFileInputPlugin.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
package org.embulk.input;
22

3+
import static org.embulk.input.CommandFileInputPlugin.buildShell;
4+
import static org.junit.Assert.assertEquals;
5+
36
import java.util.Arrays;
47
import java.util.Collections;
8+
import org.embulk.test.EmbulkTestRuntime;
59
import org.junit.Rule;
610
import org.junit.Test;
7-
import org.embulk.test.EmbulkTestRuntime;
8-
import static org.embulk.input.CommandFileInputPlugin.buildShell;
9-
10-
import java.util.List;
1111

12-
import static org.junit.Assert.assertEquals;
13-
14-
public class TestCommandFileInputPlugin
15-
{
12+
public class TestCommandFileInputPlugin {
1613
@Rule
1714
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
1815

1916
@Test
2017
public void testShell() {
2118
if (System.getProperty("os.name").indexOf("Windows") >= 0) {
2219
assertEquals(Collections.unmodifiableList(Arrays.asList("PowerShell.exe", "-Command")), buildShell());
23-
}
24-
else {
20+
} else {
2521
assertEquals(Collections.unmodifiableList(Arrays.asList("sh", "-c")), buildShell());
2622
}
2723
}

0 commit comments

Comments
 (0)