Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,7 @@ private Map<String, List<String>> getFinalPackagesVersionsForModule(
Operations.runProcessGetOutput(manifestPath.getParent(), goExecutable, "mod", "download");
String finalVersionsForAllModules =
Operations.runProcessGetOutput(manifestPath.getParent(), goExecutable, "list", "-m", "all");
Map<String, String> finalModulesVersions =
Arrays.stream(finalVersionsForAllModules.split(Operations.GENERIC_LINE_SEPARATOR))
.filter(string -> string.trim().split(" ").length == 2)
.collect(
Collectors.toMap(
t -> t.split(" ")[0], t -> t.split(" ")[1], (first, second) -> second));
Map<String, String> finalModulesVersions = parseModuleVersions(finalVersionsForAllModules);
Map<String, List<String>> listWithModifiedVersions = new HashMap<>();
// Process all entries, including those without versions (like the root module)
edges.forEach(
Expand Down Expand Up @@ -387,6 +382,24 @@ private Map<String, List<String>> getFinalPackagesVersionsForModule(
return listWithModifiedVersions;
}

/**
* Parses {@code go list -m all} output into a map of module names to their final resolved
* versions. Handles both standard lines ({@code name version}) and replace directive lines
* ({@code name v1 => replacement v2}).
*/
static Map<String, String> parseModuleVersions(String goListOutput) {
return Arrays.stream(goListOutput.split(Operations.GENERIC_LINE_SEPARATOR))
.map(String::trim)
.map(line -> line.split(" "))
.filter(parts -> parts.length == 2 || (parts.length >= 4 && parts[2].equals("=>")))
.collect(
Collectors.toMap(
parts -> parts[0],
parts ->
parts.length >= 4 && parts[2].equals("=>") ? parts[parts.length - 1] : parts[1],
(first, second) -> second));
}

private List<String> getListOfPackagesWithFinalVersions(
Map<String, String> finalModulesVersions, List<String> packages) {
return packages.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@
},
{
"type": "library",
"bom-ref": "pkg:golang/gopkg.in/yaml.v3@v3.0.1",
"bom-ref": "pkg:golang/gopkg.in/yaml.v3@v3.0.0",
"group": "gopkg.in",
"name": "yaml.v3",
"version": "v3.0.1",
"purl": "pkg:golang/gopkg.in/yaml.v3@v3.0.1"
"version": "v3.0.0",
"purl": "pkg:golang/gopkg.in/yaml.v3@v3.0.0"
},
{
"type": "library",
Expand Down Expand Up @@ -497,7 +497,7 @@
"dependsOn": []
},
{
"ref": "pkg:golang/gopkg.in/yaml.v3@v3.0.1",
"ref": "pkg:golang/gopkg.in/yaml.v3@v3.0.0",
"dependsOn": [
"pkg:golang/gopkg.in/check.v1@v0.0.0-20161208181325-20d25e280405"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ require golang.org/x/tools v0.0.0-20210112183307-1e6ecd4bf1b0
require github.com/spf13/cobra v0.0.5

require gopkg.in/yaml.v3 v3.0.1 // indirect

replace gopkg.in/yaml.v3 v3.0.1 => gopkg.in/yaml.v3 v3.0.0
Loading