diff --git a/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/GoDriver.java b/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/GoDriver.java index e39c3a062..1a53f1837 100644 --- a/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/GoDriver.java +++ b/build-info-extractor-go/src/main/java/org/jfrog/build/extractor/go/GoDriver.java @@ -83,8 +83,11 @@ public void modTidy(boolean prompt) throws IOException { runCmd(GO_MOD_TIDY_CMD, prompt); } - public CommandResults getUsedModules(boolean prompt) throws IOException { + public CommandResults getUsedModules(boolean prompt, boolean ignoreErrors) throws IOException { List argsList = new ArrayList<>(GO_LIST_USED_MODULES_CMD); + if (ignoreErrors) { + argsList.add(1, "-e"); + } return runCmd(argsList, prompt); } diff --git a/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/GoDriverTest.java b/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/GoDriverTest.java index 5503b5b33..cc423c1f7 100644 --- a/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/GoDriverTest.java +++ b/build-info-extractor-go/src/test/java/org/jfrog/build/extractor/go/GoDriverTest.java @@ -35,11 +35,20 @@ public void testListUsedModules() throws IOException { FileUtils.copyDirectory(PROJECT_ORIGIN.toFile(), projectDir); GoDriver driver = new GoDriver(null, System.getenv(), projectDir, new NullLog()); driver.modTidy(false); - CommandResults results = driver.getUsedModules(false); + + // Run "go list -f {{with .Module}}{{.Path}} {{.Version}}{{end}} all" + CommandResults results = driver.getUsedModules(false, false); Set actualUsedModules = Arrays.stream(results.getRes().split("\\r?\\n")) .map(String::trim) .collect(Collectors.toSet()); assertEquals(actualUsedModules, EXPECTED_USED_MODULES); + + // Run "go list -e -f {{with .Module}}{{.Path}} {{.Version}}{{end}} all" + results = driver.getUsedModules(false, true); + actualUsedModules = Arrays.stream(results.getRes().split("\\r?\\n")) + .map(String::trim) + .collect(Collectors.toSet()); + assertEquals(actualUsedModules, EXPECTED_USED_MODULES); } finally { FileUtils.deleteDirectory(projectDir); }