use of com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorNotFoundDecision in project hub-detect by blackducksoftware.
the class DetectorNameVersionDecider method decideProjectNameVersionFromDetector.
private NameVersionDecision decideProjectNameVersionFromDetector(final List<DetectorProjectInfo> projectNamePossibilities, final DetectorType preferredBomToolType) {
final NameVersionDecision decision;
if (preferredBomToolType != null) {
final List<DetectorProjectInfo> possiblePreferred = projectNamePossibilities.stream().filter(it -> it.getDetectorType() == preferredBomToolType).collect(Collectors.toList());
final List<DetectorProjectInfo> lowestDepthPossibilities = projectNamesAtLowestDepth(possiblePreferred);
if (lowestDepthPossibilities.size() == 0) {
decision = new PreferredDetectorNotFoundDecision(preferredBomToolType);
} else if (lowestDepthPossibilities.size() == 1) {
decision = new PreferredDetectorDecision(lowestDepthPossibilities.get(0));
} else {
decision = new TooManyPreferredDetectorTypesFoundDecision(preferredBomToolType);
}
} else {
final List<DetectorProjectInfo> lowestDepthPossibilities = projectNamesAtLowestDepth(projectNamePossibilities);
final Map<DetectorType, Long> lowestDepthTypeCounts = lowestDepthPossibilities.stream().collect(Collectors.groupingBy(it -> it.getDetectorType(), Collectors.counting()));
final List<DetectorType> singleInstanceLowestDepthBomTools = lowestDepthTypeCounts.entrySet().stream().filter(it -> it.getValue() == 1).map(it -> it.getKey()).collect(Collectors.toList());
if (singleInstanceLowestDepthBomTools.size() == 1) {
final DetectorType type = singleInstanceLowestDepthBomTools.get(0);
final Optional<DetectorProjectInfo> chosen = lowestDepthPossibilities.stream().filter(it -> it.getDetectorType() == type).findFirst();
if (chosen.isPresent()) {
decision = new UniqueDetectorDecision(chosen.get());
} else {
decision = new UniqueDetectorNotFoundDecision();
}
} else if (singleInstanceLowestDepthBomTools.size() > 1) {
decision = decideProjectNameVersionArbitrarily(lowestDepthPossibilities, singleInstanceLowestDepthBomTools);
} else {
decision = new UniqueDetectorNotFoundDecision();
}
}
return decision;
}
Aggregations