From dc947e6c5cd3edd81af2c1ec3f6dbe5efa1bae7f Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Wed, 6 Jan 2021 18:08:11 +0800 Subject: [PATCH] style: avoid compile pattern multiple times, compile it only once is a better choice --- .../detectables/go/gomod/GoModCommandExecutor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/detectable/src/main/java/com/synopsys/integration/detectable/detectables/go/gomod/GoModCommandExecutor.java b/detectable/src/main/java/com/synopsys/integration/detectable/detectables/go/gomod/GoModCommandExecutor.java index 6cf8845da8..0d26ba0de7 100644 --- a/detectable/src/main/java/com/synopsys/integration/detectable/detectables/go/gomod/GoModCommandExecutor.java +++ b/detectable/src/main/java/com/synopsys/integration/detectable/detectables/go/gomod/GoModCommandExecutor.java @@ -47,10 +47,11 @@ List generateGoListOutput(File directory, File goExe) throws ExecutableR return execute(directory, goExe, FAILURE_MSG_QUERYING_GO_FOR_THE_LIST_OF_MODULES, "list", "-m"); } + private static final Pattern GENERATE_GO_LIST_U_JSON_OUTPUT_PATTERN = Pattern.compile("\\d+\\.[\\d.]+"); + List generateGoListUJsonOutput(File directory, File goExe) throws ExecutableRunnerException, DetectableException { List goVersionOutput = execute(directory, goExe, FAILURE_MSG_QUERYING_FOR_THE_VERSION, "version"); - Pattern pattern = Pattern.compile("\\d+\\.[\\d.]+"); - Matcher matcher = pattern.matcher(goVersionOutput.get(0)); + Matcher matcher = GENERATE_GO_LIST_U_JSON_OUTPUT_PATTERN.matcher(goVersionOutput.get(0)); if (matcher.find()) { String version = matcher.group(); String[] parts = version.split("\\.");