Search in sources :

Example 1 with UniqueDetectorNotFoundDecision

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;
}
Also used : UniqueDetectorNotFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorNotFoundDecision) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) Logger(org.slf4j.Logger) NameVersionDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.NameVersionDecision) LoggerFactory(org.slf4j.LoggerFactory) ArbitraryNameVersionDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.ArbitraryNameVersionDecision) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) NameVersion(com.synopsys.integration.util.NameVersion) List(java.util.List) UniqueDetectorDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorDecision) PreferredDetectorDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorDecision) PreferredDetectorNotFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorNotFoundDecision) Map(java.util.Map) Optional(java.util.Optional) Comparator(java.util.Comparator) TooManyPreferredDetectorTypesFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.TooManyPreferredDetectorTypesFoundDecision) NameVersionDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.NameVersionDecision) ArbitraryNameVersionDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.ArbitraryNameVersionDecision) PreferredDetectorDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorDecision) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) UniqueDetectorDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorDecision) TooManyPreferredDetectorTypesFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.TooManyPreferredDetectorTypesFoundDecision) PreferredDetectorNotFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorNotFoundDecision) UniqueDetectorNotFoundDecision(com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorNotFoundDecision)

Aggregations

DetectorType (com.blackducksoftware.integration.hub.detect.detector.DetectorType)1 ArbitraryNameVersionDecision (com.blackducksoftware.integration.hub.detect.workflow.project.decisions.ArbitraryNameVersionDecision)1 NameVersionDecision (com.blackducksoftware.integration.hub.detect.workflow.project.decisions.NameVersionDecision)1 PreferredDetectorDecision (com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorDecision)1 PreferredDetectorNotFoundDecision (com.blackducksoftware.integration.hub.detect.workflow.project.decisions.PreferredDetectorNotFoundDecision)1 TooManyPreferredDetectorTypesFoundDecision (com.blackducksoftware.integration.hub.detect.workflow.project.decisions.TooManyPreferredDetectorTypesFoundDecision)1 UniqueDetectorDecision (com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorDecision)1 UniqueDetectorNotFoundDecision (com.blackducksoftware.integration.hub.detect.workflow.project.decisions.UniqueDetectorNotFoundDecision)1 NameVersion (com.synopsys.integration.util.NameVersion)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1