Shorter implementation for nuget code location combining.
@@ -181,35 +181,22 @@ class NugetBomTool extends BomTool {
return []
}
- Map<String, List<DetectCodeLocation>> codeLocationSourcePathMap = new HashMap<>();
- codeLocations.forEach { DetectCodeLocation codeLocation ->
- String sourcePath = codeLocation.getSourcePath();
- if (!codeLocationSourcePathMap.containsKey(sourcePath)) {
- codeLocationSourcePathMap.put(sourcePath, new ArrayList<>());
- }
- codeLocationSourcePathMap.get(sourcePath).add(codeLocation);
- }
-
- List<DetectCodeLocation> mergedCodeLocations = new ArrayList<>();
+ Map<String, DetectCodeLocation> codeLocationsBySource = new HashMap<>();
DependencyGraphCombiner combiner = new DependencyGraphCombiner();
- for (def codeLocationList in codeLocationSourcePathMap.values()) {
- if (codeLocationList.size() > 1) {
- DetectCodeLocation merger = codeLocationList.first();
- logger.info("Multiple project code locations (" + codeLocationList.size()+ ") were generated for: " + merger.sourcePath);
+
+ codeLocations.forEach { DetectCodeLocation codeLocation ->
+ if (codeLocationsBySource.containsKey(codeLocation.getSourcePath())) {
+ logger.info("Multiple project code locations were generated for: " + codeLocation.sourcePath);
logger.info("This most likely means the same project exists in multiple solutions.")
logger.info("The code location's dependencies will be combined, in the future they will exist seperately for each solution.")
- codeLocationList.stream()
- .skip(1)
- .forEach{
- combiner.addGraphAsChildrenToRoot((MutableDependencyGraph) merger.getDependencyGraph(), it.getDependencyGraph())
- };
- mergedCodeLocations.add(merger);
- }else if (codeLocationList.size() == 1) {
- mergedCodeLocations.add(codeLocationList.first());
+ DetectCodeLocation destination = codeLocationsBySource.get(codeLocation.getSourcePath());
+ combiner.addGraphAsChildrenToRoot((MutableDependencyGraph) destination.getDependencyGraph(), codeLocation.getDependencyGraph());
+ }else {
+ codeLocationsBySource.put(codeLocation.getSourcePath(), codeLocation);
}
}
- mergedCodeLocations
+ codeLocationsBySource.values().toList()
}
String getInspectorVersion() {
