Search in sources :

Example 6 with DetectorType

use of com.synopsys.integration.detector.base.DetectorType in project synopsys-detect by blackducksoftware.

the class DetectorAggregateEvaluationResultTest method testMultiLevel.

@Test
public void testMultiLevel() {
    DetectorType topLevelDetectorType = DetectorType.GRADLE;
    DetectorType secondLevelDetectorType = DetectorType.MAVEN;
    DetectorEvaluationTree topLevelEvaluationTree = generateDetectorEvaluationTreeMock(topLevelDetectorType);
    DetectorEvaluationTree secondLevelEvaluationTree = generateDetectorEvaluationTreeMock(secondLevelDetectorType);
    Set<DetectorEvaluationTree> secondLevelEvaluationTrees = new HashSet<>();
    secondLevelEvaluationTrees.add(secondLevelEvaluationTree);
    Mockito.when(topLevelEvaluationTree.getChildren()).thenReturn(secondLevelEvaluationTrees);
    DetectorAggregateEvaluationResult result = new DetectorAggregateEvaluationResult(topLevelEvaluationTree);
    assertEquals(1, result.getApplicableDetectorTypes().size());
    assertEquals(2, result.getApplicableDetectorTypesRecursively().size());
    assertTrue(result.getApplicableDetectorTypesRecursively().contains(topLevelDetectorType));
    assertTrue(result.getApplicableDetectorTypesRecursively().contains(secondLevelDetectorType));
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorType(com.synopsys.integration.detector.base.DetectorType) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 7 with DetectorType

use of com.synopsys.integration.detector.base.DetectorType in project synopsys-detect by blackducksoftware.

the class DetectorTool method extractStatus.

private Map<DetectorType, StatusType> extractStatus(List<DetectorEvaluation> detectorEvaluations) {
    EnumMap<DetectorType, StatusType> statusMap = new EnumMap<>(DetectorType.class);
    for (DetectorEvaluation detectorEvaluation : detectorEvaluations) {
        DetectorType detectorType = detectorEvaluation.getDetectorType();
        Optional<StatusType> foundStatusType = determineDetectorExtractionStatus(detectorEvaluation);
        if (foundStatusType.isPresent()) {
            StatusType statusType = foundStatusType.get();
            if (statusType == StatusType.FAILURE || !statusMap.containsKey(detectorType)) {
                statusMap.put(detectorType, statusType);
            }
        }
    }
    return statusMap;
}
Also used : DetectorType(com.synopsys.integration.detector.base.DetectorType) StatusType(com.synopsys.integration.detect.workflow.status.StatusType) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) EnumMap(java.util.EnumMap)

Example 8 with DetectorType

use of com.synopsys.integration.detector.base.DetectorType in project synopsys-detect by blackducksoftware.

the class DetectorTool method publishMissingDetectorEvents.

private void publishMissingDetectorEvents(List<DetectorType> requiredDetectors, Set<DetectorType> applicable) {
    Set<DetectorType> missingDetectors = requiredDetectors.stream().filter(it -> !applicable.contains(it)).collect(Collectors.toSet());
    if (!missingDetectors.isEmpty()) {
        String missingDetectorDisplay = missingDetectors.stream().map(Enum::toString).collect(Collectors.joining(","));
        logger.error("One or more required detector types were not found: {}", missingDetectorDisplay);
        exitCodePublisher.publishExitCode(new ExitCodeRequest(ExitCodeType.FAILURE_DETECTOR_REQUIRED));
    }
}
Also used : DetectorNameVersionDecider(com.synopsys.integration.detect.workflow.nameversion.DetectorNameVersionDecider) StatusEventPublisher(com.synopsys.integration.detect.workflow.status.StatusEventPublisher) DetectorEvaluationUtils(com.synopsys.integration.detect.workflow.report.util.DetectorEvaluationUtils) DetectorStatus(com.synopsys.integration.detect.workflow.status.DetectorStatus) ExtractionEnvironmentProvider(com.synopsys.integration.detect.tool.detector.extraction.ExtractionEnvironmentProvider) DetectorFinder(com.synopsys.integration.detector.finder.DetectorFinder) UnrecognizedPaths(com.synopsys.integration.detect.workflow.status.UnrecognizedPaths) LoggerFactory(org.slf4j.LoggerFactory) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) ReportConstants(com.synopsys.integration.detect.workflow.report.util.ReportConstants) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) DetectorFinderOptions(com.synopsys.integration.detector.finder.DetectorFinderOptions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NameVersion(com.synopsys.integration.util.NameVersion) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) Map(java.util.Map) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) ExitCodeType(com.synopsys.integration.detect.configuration.enumeration.ExitCodeType) Logger(org.slf4j.Logger) EnumMap(java.util.EnumMap) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) StatusType(com.synopsys.integration.detect.workflow.status.StatusType) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectorEvaluator(com.synopsys.integration.detector.evaluation.DetectorEvaluator) DetectorEvaluationOptions(com.synopsys.integration.detector.evaluation.DetectorEvaluationOptions) Optional(java.util.Optional) ExitCodePublisher(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher) DetectorAggregateEvaluationResult(com.synopsys.integration.detector.evaluation.DetectorAggregateEvaluationResult) DetectorEvaluationNameVersionDecider(com.synopsys.integration.detect.workflow.nameversion.DetectorEvaluationNameVersionDecider) ExitCodeRequest(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest) DetectorType(com.synopsys.integration.detector.base.DetectorType) ExitCodeRequest(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest)

Example 9 with DetectorType

use of com.synopsys.integration.detector.base.DetectorType 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)

Example 10 with DetectorType

use of com.synopsys.integration.detector.base.DetectorType in project synopsys-detect by blackducksoftware.

the class DetectorProfiler method addAggregateByDetectorGroupType.

private void addAggregateByDetectorGroupType(Map<DetectorType, Long> aggregate, List<Timing<DetectorEvaluation>> timings) {
    for (Timing<DetectorEvaluation> timing : timings) {
        DetectorType type = timing.getKey().getDetectorType();
        if (!aggregate.containsKey(type)) {
            aggregate.put(type, 0L);
        }
        long time = timing.getMs();
        Long currentTime = aggregate.get(type);
        Long sum = time + currentTime;
        aggregate.put(type, sum);
    }
}
Also used : DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation)

Aggregations

DetectorType (com.synopsys.integration.detector.base.DetectorType)10 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)5 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)4 StatusType (com.synopsys.integration.detect.workflow.status.StatusType)3 NameVersion (com.synopsys.integration.util.NameVersion)3 HashSet (java.util.HashSet)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 DetectCodeLocation (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)2 DetectorEvaluationNameVersionDecider (com.synopsys.integration.detect.workflow.nameversion.DetectorEvaluationNameVersionDecider)2 DetectorNameVersionDecider (com.synopsys.integration.detect.workflow.nameversion.DetectorNameVersionDecider)2 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 DetectorAggregateEvaluationResult (com.synopsys.integration.detector.evaluation.DetectorAggregateEvaluationResult)2 DetectorEvaluator (com.synopsys.integration.detector.evaluation.DetectorEvaluator)2 EnumMap (java.util.EnumMap)2 List (java.util.List)2 Map (java.util.Map)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 FileFinder (com.synopsys.integration.common.util.finder.FileFinder)1