refactor(go-mod): Moved all duplicated strings into comments.
@@ -33,10 +33,15 @@ public class GoModCommandExecutor {
private static final String FAILURE_MSG_QUERYING_FOR_GO_MOD_WHY = "Querying for the go modules compiled into the binary failed:";
private static final Pattern GENERATE_GO_LIST_U_JSON_OUTPUT_PATTERN = Pattern.compile("\\d+\\.[\\d.]+");
+ private static final String LIST_COMMAND = "list";
+ private static final String MOD_COMMAND = "mod";
+
private static final String MODULE_FLAG = "-m";
private static final String JSON_FLAG = "-json";
private static final String UPGRADE_FLAG = "-u";
+ private static final String ALL_ARGUMENT = "all";
+
private final DetectableExecutableRunner executableRunner;
public GoModCommandExecutor(DetectableExecutableRunner executableRunner) {
@@ -44,7 +49,7 @@ public class GoModCommandExecutor {
}
List<String> generateGoListOutput(File directory, ExecutableTarget goExe) throws ExecutableRunnerException, DetectableException {
- return execute(directory, goExe, FAILURE_MSG_QUERYING_GO_FOR_THE_LIST_OF_MODULES, "list", MODULE_FLAG, JSON_FLAG);
+ return execute(directory, goExe, FAILURE_MSG_QUERYING_GO_FOR_THE_LIST_OF_MODULES, LIST_COMMAND, MODULE_FLAG, JSON_FLAG);
}
List<String> generateGoListUJsonOutput(File directory, ExecutableTarget goExe) throws ExecutableRunnerException, DetectableException {
@@ -54,22 +59,22 @@ public class GoModCommandExecutor {
String version = matcher.group();
String[] parts = version.split("\\.");
if (Integer.parseInt(parts[0]) > 1 || Integer.parseInt(parts[1]) >= 14) {
- return execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_THE_GO_MOD_GRAPH, "list", "-mod=readonly", MODULE_FLAG, UPGRADE_FLAG, JSON_FLAG, "all");
+ return execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_THE_GO_MOD_GRAPH, LIST_COMMAND, "-mod=readonly", MODULE_FLAG, UPGRADE_FLAG, JSON_FLAG, ALL_ARGUMENT);
} else {
- return execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_THE_GO_MOD_GRAPH, "list", MODULE_FLAG, UPGRADE_FLAG, JSON_FLAG, "all");
+ return execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_THE_GO_MOD_GRAPH, LIST_COMMAND, MODULE_FLAG, UPGRADE_FLAG, JSON_FLAG, ALL_ARGUMENT);
}
}
return new ArrayList<>();
}
List<String> generateGoModGraphOutput(File directory, ExecutableTarget goExe) throws ExecutableRunnerException, DetectableException {
- return execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_THE_GO_MOD_GRAPH, "mod", "graph");
+ return execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_THE_GO_MOD_GRAPH, MOD_COMMAND, "graph");
}
List<String> generateGoModWhyOutput(File directory, ExecutableTarget goExe) {
try {
// executing this command helps produce more accurate results. Parse the output to create a module exclusion list.
- return execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_GO_MOD_WHY, "mod", "why", MODULE_FLAG, "all");
+ return execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_GO_MOD_WHY, MOD_COMMAND, "why", MODULE_FLAG, ALL_ARGUMENT);
} catch (ExecutableRunnerException | DetectableException ex) {
logger.error("{} Will not be able to create an accurate module exclusion list.", FAILURE_MSG_QUERYING_FOR_GO_MOD_WHY);
logger.debug("Error executing go mod why command. ", ex);
