|
27 | 27 | import java.io.File;
|
28 | 28 | import java.io.IOException;
|
29 | 29 | import java.io.PrintStream;
|
| 30 | +import java.io.UncheckedIOException; |
30 | 31 | import java.lang.reflect.Field;
|
31 | 32 | import java.lang.reflect.InvocationTargetException;
|
32 | 33 | import java.net.URI;
|
33 | 34 | import java.net.URISyntaxException;
|
| 35 | +import java.nio.file.Files; |
| 36 | +import java.nio.file.Path; |
34 | 37 | import java.nio.file.Paths;
|
35 | 38 | import java.text.ParseException;
|
36 | 39 | import java.util.ArrayList;
|
37 | 40 | import java.util.Arrays;
|
| 41 | +import java.util.Collection; |
38 | 42 | import java.util.Collections;
|
39 | 43 | import java.util.HashMap;
|
40 | 44 | import java.util.HashSet;
|
@@ -711,19 +715,24 @@ public static String[] parseOptions(String[] argv) throws ParseException {
|
711 | 715 | "with lots of renamed files. Default is off.").execute(v ->
|
712 | 716 | cfg.setHandleHistoryOfRenamedFiles((Boolean) v));
|
713 | 717 |
|
714 |
| - parser.on("--repository", "=path/to/repository", |
| 718 | + parser.on("--repository", "=[path/to/repository|@file_with_paths]", |
715 | 719 | "Path (relative to the source root) to a repository for generating",
|
716 | 720 | "history (if -H,--history is on). By default all discovered repositories",
|
717 | 721 | "are history-eligible; using --repository limits to only those specified.",
|
718 |
| - "Option may be repeated.").execute(v -> repositories.add((String) v)); |
| 722 | + "File containing paths can be specified via @path syntax.", |
| 723 | + "Option may be repeated.") |
| 724 | + .execute(v -> handlePathParameter(repositories, ((String) v).trim())); |
719 | 725 |
|
720 |
| - parser.on("-S", "--search", "=[path/to/repository]", |
| 726 | + parser.on("-S", "--search", "=[path/to/repository|@file_with_paths]", |
721 | 727 | "Search for source repositories under -s,--source, and add them. Path",
|
722 |
| - "(relative to the source root) is optional. Option may be repeated.").execute(v -> { |
| 728 | + "(relative to the source root) is optional. ", |
| 729 | + "File containing paths can be specified via @path syntax.", |
| 730 | + "Option may be repeated.") |
| 731 | + .execute(v -> { |
723 | 732 | searchRepositories = true;
|
724 |
| - String repoPath = (String) v; |
725 |
| - if (!repoPath.isEmpty()) { |
726 |
| - searchPaths.add(repoPath); |
| 733 | + String value = ((String) v).trim(); |
| 734 | + if (!value.isEmpty()) { |
| 735 | + handlePathParameter(searchPaths, value); |
727 | 736 | }
|
728 | 737 | });
|
729 | 738 |
|
@@ -1143,6 +1152,24 @@ private static void pauseToAwaitProfiler() {
|
1143 | 1152 | }
|
1144 | 1153 | }
|
1145 | 1154 |
|
| 1155 | + // Visible for testing |
| 1156 | + static void handlePathParameter(Collection<String> paramValueStore, String pathValue) { |
| 1157 | + if (pathValue.startsWith("@")) { |
| 1158 | + paramValueStore.addAll(loadPathsFromFile(pathValue.substring(1))); |
| 1159 | + } else { |
| 1160 | + paramValueStore.add(pathValue); |
| 1161 | + } |
| 1162 | + } |
| 1163 | + |
| 1164 | + private static List<String> loadPathsFromFile(String filename) { |
| 1165 | + try { |
| 1166 | + return Files.readAllLines(Path.of(filename)); |
| 1167 | + } catch (IOException e) { |
| 1168 | + LOGGER.log(Level.SEVERE, String.format("Could not load paths from %s", filename), e); |
| 1169 | + throw new UncheckedIOException(e); |
| 1170 | + } |
| 1171 | + } |
| 1172 | + |
1146 | 1173 | private static void exitWithHelp() {
|
1147 | 1174 | PrintStream helpStream = status != 0 ? System.err : System.out;
|
1148 | 1175 | switch (helpMode) {
|
|
0 commit comments