Search in sources :

Example 1 with PreferredDetectorNotFoundDecision

use of com.synopsys.integration.detect.workflow.nameversion.decision.PreferredDetectorNotFoundDecision in project synopsys-detect by blackducksoftware.

the class DetectorNameVersionDecider method decideProjectNameVersionFromDetector.

private NameVersionDecision decideProjectNameVersionFromDetector(List<DetectorProjectInfo> projectNamePossibilities, DetectorType preferredDetectorType) {
    if (preferredDetectorType != null) {
        List<DetectorProjectInfo> preferredPossibilities = projectNamePossibilities.stream().filter(info -> info.getDetectorType() == preferredDetectorType).collect(Collectors.toList());
        List<DetectorProjectInfo> lowestDepthPossibilities = projectNamesAtLowestDepth(preferredPossibilities);
        List<DetectorProjectInfo> uniqueDetectorsAtLowestDepth = filterUniqueDetectorsOnly(lowestDepthPossibilities);
        if (uniqueDetectorsAtLowestDepth.isEmpty()) {
            return new PreferredDetectorNotFoundDecision(preferredDetectorType);
        } else if (uniqueDetectorsAtLowestDepth.size() == 1) {
            return new PreferredDetectorDecision(uniqueDetectorsAtLowestDepth.get(0));
        } else {
            return new TooManyPreferredDetectorTypesFoundDecision(preferredDetectorType);
        }
    } else {
        List<DetectorProjectInfo> lowestDepthPossibilities = projectNamesAtLowestDepth(projectNamePossibilities);
        List<DetectorProjectInfo> uniqueDetectorsAtLowestDepth = filterUniqueDetectorsOnly(lowestDepthPossibilities);
        if (uniqueDetectorsAtLowestDepth.size() == 1) {
            return new UniqueDetectorDecision(uniqueDetectorsAtLowestDepth.get(0));
        } else if (uniqueDetectorsAtLowestDepth.size() > 1) {
            return decideProjectNameVersionArbitrarily(lowestDepthPossibilities);
        } else {
            return new UniqueDetectorNotFoundDecision();
        }
    }
}
Also used : Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArbitraryNameVersionDecision(com.synopsys.integration.detect.workflow.nameversion.decision.ArbitraryNameVersionDecision) NameVersionDecision(com.synopsys.integration.detect.workflow.nameversion.decision.NameVersionDecision) NameVersion(com.synopsys.integration.util.NameVersion) List(java.util.List) PreferredDetectorNotFoundDecision(com.synopsys.integration.detect.workflow.nameversion.decision.PreferredDetectorNotFoundDecision) Map(java.util.Map) UniqueDetectorDecision(com.synopsys.integration.detect.workflow.nameversion.decision.UniqueDetectorDecision) Optional(java.util.Optional) TooManyPreferredDetectorTypesFoundDecision(com.synopsys.integration.detect.workflow.nameversion.decision.TooManyPreferredDetectorTypesFoundDecision) DetectorType(com.synopsys.integration.detector.base.DetectorType) UniqueDetectorNotFoundDecision(com.synopsys.integration.detect.workflow.nameversion.decision.UniqueDetectorNotFoundDecision) Comparator(java.util.Comparator) LinkedList(java.util.LinkedList) PreferredDetectorDecision(com.synopsys.integration.detect.workflow.nameversion.decision.PreferredDetectorDecision) UniqueDetectorDecision(com.synopsys.integration.detect.workflow.nameversion.decision.UniqueDetectorDecision) TooManyPreferredDetectorTypesFoundDecision(com.synopsys.integration.detect.workflow.nameversion.decision.TooManyPreferredDetectorTypesFoundDecision) PreferredDetectorNotFoundDecision(com.synopsys.integration.detect.workflow.nameversion.decision.PreferredDetectorNotFoundDecision) PreferredDetectorDecision(com.synopsys.integration.detect.workflow.nameversion.decision.PreferredDetectorDecision) UniqueDetectorNotFoundDecision(com.synopsys.integration.detect.workflow.nameversion.decision.UniqueDetectorNotFoundDecision)

Aggregations

ArbitraryNameVersionDecision (com.synopsys.integration.detect.workflow.nameversion.decision.ArbitraryNameVersionDecision)1 NameVersionDecision (com.synopsys.integration.detect.workflow.nameversion.decision.NameVersionDecision)1 PreferredDetectorDecision (com.synopsys.integration.detect.workflow.nameversion.decision.PreferredDetectorDecision)1 PreferredDetectorNotFoundDecision (com.synopsys.integration.detect.workflow.nameversion.decision.PreferredDetectorNotFoundDecision)1 TooManyPreferredDetectorTypesFoundDecision (com.synopsys.integration.detect.workflow.nameversion.decision.TooManyPreferredDetectorTypesFoundDecision)1 UniqueDetectorDecision (com.synopsys.integration.detect.workflow.nameversion.decision.UniqueDetectorDecision)1 UniqueDetectorNotFoundDecision (com.synopsys.integration.detect.workflow.nameversion.decision.UniqueDetectorNotFoundDecision)1 DetectorType (com.synopsys.integration.detector.base.DetectorType)1 NameVersion (com.synopsys.integration.util.NameVersion)1 Collections.emptyList (java.util.Collections.emptyList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1