Skip to content

Commit 9af05b3

Browse files
committed
refactoring
1 parent 354b380 commit 9af05b3

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/main/java/io/github/fvarrui/javapackager/utils/CommandUtils.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ public static String execute(String executable, List<Object> arguments) throws I
3737
public static ExecutionResult executeWithResult(File workingDirectory, String executable, Object... arguments) throws IOException, CommandLineException {
3838
ExecutionResult result = new ExecutionResult();
3939

40-
StringBuffer outputBuffer = new StringBuffer();
41-
StringBuffer errorBuffer = new StringBuffer();
40+
StringBuilder outputBuffer = new StringBuilder();
41+
StringBuilder errorBuffer = new StringBuilder();
4242

4343
Commandline command = new Commandline();
4444
command.setWorkingDirectory(workingDirectory);
4545
command.setExecutable(executable);
4646
command.createArguments(arguments);
47-
command.toString();
48-
47+
4948
String commandLine = command.getCommandLineAsString();
5049

5150
Logger.info("Executing command: " + commandLine);
@@ -58,12 +57,12 @@ public static ExecutionResult executeWithResult(File workingDirectory, String ex
5857
if (output.ready()) {
5958
String outputLine = output.readLine();
6059
Logger.info(outputLine);
61-
outputBuffer.append(outputLine + "\n");
60+
outputBuffer.append(outputLine).append("\n");
6261
}
6362
if (error.ready()) {
6463
String errorLine = error.readLine();
6564
Logger.error(errorLine);
66-
errorBuffer.append(errorLine + "\n");
65+
errorBuffer.append(errorLine).append("\n");
6766
}
6867
}
6968
output.close();

src/main/java/io/github/fvarrui/javapackager/utils/Commandline.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.fvarrui.javapackager.utils;
22

33
import java.io.File;
4+
import java.util.Collection;
45

56
import org.apache.commons.lang3.StringUtils;
67
import org.apache.commons.lang3.SystemUtils;
@@ -28,12 +29,20 @@ public void createArguments(Object... arguments) {
2829

2930
if (argument == null)
3031
continue;
31-
32+
33+
// expands collections
34+
if (argument instanceof Collection) {
35+
createArguments(((Collection<?>) argument).toArray(new Object[0]));
36+
continue;
37+
}
38+
39+
// expands array
3240
if (argument.getClass().isArray()) {
33-
createArguments((Object[])argument);
41+
createArguments((Object[])argument);
3442
continue;
3543
}
36-
44+
45+
// process file argument
3746
if (argument instanceof File) {
3847

3948
File argFile = (File) argument;

0 commit comments

Comments
 (0)