Support for nuget to combine duplicate project code locations if the same project is used in multiple solutions.
package com.blackducksoftware.integration.hub.detect.bomtool.nuget
import com.blackducksoftware.integration.hub.detect.bomtool.BomTool
+import com.blackducksoftware.integration.hub.detect.codelocation.CodeLocationName
+
import org.apache.commons.io.FileUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
-
+import com.blackducksoftware.integration.hub.bdio.graph.DependencyGraphCombiner
+import com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph
import com.blackducksoftware.integration.hub.detect.DetectInfo
import com.blackducksoftware.integration.hub.detect.model.BomToolType
import com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation
@@ -179,7 +182,34 @@ class NugetBomTool extends BomTool {
return []
}
- codeLocations
+ 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<>();
+ 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);
+ 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())
+ };
+ }else if (codeLocationList.size() == 1) {
+ mergedCodeLocations.add(codeLocationList.first());
+ }
+ }
+
+ mergedCodeLocations
}
String getInspectorVersion() {
