Add support for multiple flag files.  This simplifies support in the bazel rules.
@@ -635,8 +635,8 @@ public class CommandLineRunner extends
@Option(name = "--flagfile",
hidden = true,
- usage = "A file containing additional command-line options.")
- private String flagFile = "";
+ usage = "A file (or files) containing additional command-line options.")
+ private List<String> flagFiles = new ArrayList<>();
@Option(name = "--warnings_whitelist_file",
usage = "A file containing warnings to suppress. Each line should be "
@@ -1297,9 +1297,19 @@ public class CommandLineRunner extends
errorStream.flush();
}
- private void processFlagFile()
+ private void processFlagFiles() throws CmdLineException {
+ for (String flagFile : flags.flagFiles) {
+ try {
+ processFlagFile(flagFile);
+ } catch (IOException ioErr) {
+ reportError("ERROR - " + flagFile + " read error.");
+ }
+ }
+ }
+
+ private void processFlagFile(String flagFileString)
throws CmdLineException, IOException {
- Path flagFile = Paths.get(flags.flagFile);
+ Path flagFile = Paths.get(flagFileString);
BufferedReader buffer =
java.nio.file.Files.newBufferedReader(flagFile, UTF_8);
@@ -1356,7 +1366,7 @@ public class CommandLineRunner extends
tokens.add(builder.toString());
}
- flags.flagFile = "";
+ flags.flagFiles = new ArrayList<>();
tokens = processArgs(tokens.toArray(new String[0]));
@@ -1371,7 +1381,7 @@ public class CommandLineRunner extends
Flags.mixedJsSources.addAll(previousMixedJsSources);
// Currently we are not supporting this (prevent direct/indirect loops)
- if (!flags.flagFile.isEmpty()) {
+ if (!flags.flagFiles.isEmpty()) {
reportError("ERROR - Arguments in the file cannot contain "
+ "--flagfile option.");
}
@@ -1394,10 +1404,7 @@ public class CommandLineRunner extends
try {
flags.parse(processedArgs);
- // For contains --flagfile flag
- if (!flags.flagFile.isEmpty()) {
- processFlagFile();
- }
+ processFlagFiles();
jsFiles = flags.getJsFiles();
mixedSources = flags.getMixedJsSources();
@@ -1408,7 +1415,7 @@ public class CommandLineRunner extends
} catch (CmdLineException e) {
reportError(e.getMessage());
} catch (IOException ioErr) {
- reportError("ERROR - " + flags.flagFile + " read error.");
+ reportError("ERROR - ioException: " + ioErr);
}
List<ModuleIdentifier> entryPoints = new ArrayList<>();
