diff --git a/analyzer/src/main/kotlin/managers/GoMod.kt b/analyzer/src/main/kotlin/managers/GoMod.kt index 50bb8b785eda7..72c39d6c61206 100644 --- a/analyzer/src/main/kotlin/managers/GoMod.kt +++ b/analyzer/src/main/kotlin/managers/GoMod.kt @@ -288,13 +288,26 @@ class GoMod( // See https://pkg.go.dev/text/template for the format syntax. val list = run( - "list", "-deps", "-f", "{{with .Module}}{{.Path}} {{.Version}}{{end}}", "-buildvcs=false", "./...", + "list", "-deps", "-json=Module", "-buildvcs=false", "./...", workingDir = projectDir ) - list.stdout.lines().forEach { line -> - val columns = line.splitOnWhitespace() - if (columns.size in 1..2) result += columns.first() + data class DepInfo( + @JsonProperty("Module") + val module: ModuleInfo? = null + ) + + list.stdout.byteInputStream().use { inputStream -> + JsonFactory().createParser(inputStream).apply { + codec = ObjectMapper() + nextToken() + + while (hasCurrentToken()) { + val moduleInfo = jsonMapper.readValue(this, DepInfo::class.java).module + if (moduleInfo != null) result += moduleInfo.path + nextToken() + } + } } return result