From 3f3a49c9998bc547c1d965f87a831dc7887345d6 Mon Sep 17 00:00:00 2001 From: TKlerx Date: Fri, 13 Mar 2015 15:12:35 +0100 Subject: [PATCH] Fixed reading from file when using standard separator (" ") --- .../java/com/beust/jcommander/JCommander.java | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/beust/jcommander/JCommander.java b/src/main/java/com/beust/jcommander/JCommander.java index 2e049a11b..f3ad628ce 100644 --- a/src/main/java/com/beust/jcommander/JCommander.java +++ b/src/main/java/com/beust/jcommander/JCommander.java @@ -38,6 +38,8 @@ import java.util.Map; import java.util.ResourceBundle; +import bsh.classpath.BshClassPath.GeneratedClassSource; + import com.beust.jcommander.FuzzyMap.IKey; import com.beust.jcommander.converters.IParameterSplitter; import com.beust.jcommander.converters.NoConverter; @@ -351,11 +353,28 @@ private String[] expandArgs(String[] originalArgv) { // Expand @ // for (String arg : originalArgv) { - if (arg.startsWith("@")) { String fileName = arg.substring(1); - vResult1.addAll(readFile(fileName)); - } + List fileArgs = readFile(fileName); + List splitFileArgs = Lists.newArrayList(); + //special treatment for standard separator (" ") + String[] v1 = fileArgs.toArray(new String[0]); + for (int i = 0; i < fileArgs.size(); i++) { + String arg2 = fileArgs.get(i); + if (isOption(v1, arg2)) { + String sep = getSeparatorFor(v1, arg2); + if (" ".equals(sep)) { + String[] sp = arg2.split("[" + sep + "]", 2); + for (String ssp : sp) { + splitFileArgs.add(ssp); + } + }else{ + splitFileArgs.add(arg2); + } + } + } + vResult1.addAll(splitFileArgs); + } else { List expanded = expandDynamicArg(arg); vResult1.addAll(expanded); @@ -481,9 +500,9 @@ private static List readFile(String fileName) { try { BufferedReader bufRead = new BufferedReader(new FileReader(fileName)); - + String line; - + // Read through file one line at time. Print line # and line while ((line = bufRead.readLine()) != null) { // Allow empty lines and # comments in these at files