Search in sources :

Example 1 with DetectorType

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

the class DetectorAggregateEvaluationResult method getApplicableDetectorTypesRecursively.

private Set<DetectorType> getApplicableDetectorTypesRecursively(DetectorEvaluationTree givenEvaluationTree) {
    Set<DetectorType> applied = new HashSet<>();
    applied.addAll(getApplicableDetectorTypes(givenEvaluationTree));
    for (DetectorEvaluationTree childEvaluationTree : givenEvaluationTree.getChildren()) {
        applied.addAll(getApplicableDetectorTypesRecursively(childEvaluationTree));
    }
    return applied;
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorType(com.synopsys.integration.detector.base.DetectorType) HashSet(java.util.HashSet)

Example 2 with DetectorType

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

the class DetectorTool method performDetectors.

public DetectorToolResult performDetectors(File directory, DetectorRuleSet detectorRuleSet, DetectorFinderOptions detectorFinderOptions, DetectorEvaluationOptions evaluationOptions, String projectDetector, List<DetectorType> requiredDetectors, FileFinder fileFinder) {
    logger.debug("Initializing detector system.");
    Optional<DetectorEvaluationTree> possibleRootEvaluation;
    logger.debug("Starting detector file system traversal.");
    possibleRootEvaluation = detectorFinder.findDetectors(directory, detectorRuleSet, detectorFinderOptions, fileFinder);
    if (!possibleRootEvaluation.isPresent()) {
        logger.error("The source directory could not be searched for detectors - detector tool failed.");
        logger.error("Please ensure the provided source path is a directory and detect has access.");
        exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_CONFIGURATION, "Detector tool failed to run on the configured source path.");
        return new DetectorToolResult();
    }
    DetectorEvaluationTree rootEvaluation = possibleRootEvaluation.get();
    List<DetectorEvaluation> detectorEvaluations = rootEvaluation.allDescendentEvaluations();
    logger.trace("Setting up detector events.");
    // DetectorNameVersionHandler detectorNameVersionHandler = createNameVersionHandler(projectDetector);
    DetectorEvaluatorBroadcaster eventBroadcaster = new DetectorEvaluatorBroadcaster(eventSystem);
    DetectorEvaluator detectorEvaluator = new DetectorEvaluator(evaluationOptions, extractionEnvironmentProvider::createExtractionEnvironment);
    detectorEvaluator.setDetectorEvaluatorListener(eventBroadcaster);
    detectorEvaluator.registerPostApplicableCallback(detectorAggregateEvaluationResult -> {
        detectorEventPublisher.publishApplicableCompleted(detectorAggregateEvaluationResult.getApplicableDetectorTypesRecursively());
        detectorEventPublisher.publishSearchCompleted(detectorAggregateEvaluationResult.getEvaluationTree());
        logger.info("");
    });
    detectorEvaluator.registerPostExtractableCallback(detectorAggregateEvaluationResult -> {
        detectorEventPublisher.publishPreparationsCompleted(detectorAggregateEvaluationResult.getEvaluationTree());
        logger.debug("Counting detectors that will be evaluated.");
        Integer extractionCount = detectorAggregateEvaluationResult.getExtractionCount();
        detectorEventPublisher.publishExtractionCount(extractionCount);
        logger.debug("Total number of detectors: {}", extractionCount);
    });
    detectorEvaluator.registerPostExtractionCallback(detectorAggregateEvaluationResult -> detectorEventPublisher.publishExtractionsCompleted(detectorAggregateEvaluationResult.getEvaluationTree()));
    DetectorAggregateEvaluationResult evaluationResult = detectorEvaluator.evaluate(rootEvaluation);
    // TODO- finished extractions?
    logger.debug("Finished detectors.");
    printExplanations(rootEvaluation);
    Map<DetectorType, StatusType> statusMap = extractStatus(detectorEvaluations);
    publishStatusEvents(statusMap);
    publishFileEvents(detectorEvaluations);
    detectorIssuePublisher.publishEvents(statusEventPublisher, rootEvaluation);
    publishMissingDetectorEvents(requiredDetectors, evaluationResult.getApplicableDetectorTypesRecursively());
    Map<CodeLocation, DetectCodeLocation> codeLocationMap = createCodeLocationMap(detectorEvaluations, directory);
    DetectorEvaluationNameVersionDecider detectorEvaluationNameVersionDecider = new DetectorEvaluationNameVersionDecider(new DetectorNameVersionDecider());
    Optional<NameVersion> bomToolProjectNameVersion = detectorEvaluationNameVersionDecider.decideSuggestion(detectorEvaluations, projectDetector);
    logger.debug("Finished evaluating detectors for project info.");
    DetectorToolResult detectorToolResult = new DetectorToolResult(bomToolProjectNameVersion.orElse(null), new ArrayList<>(codeLocationMap.values()), evaluationResult.getApplicableDetectorTypes(), new HashSet<>(), rootEvaluation, codeLocationMap);
    // Completed.
    logger.debug("Finished running detectors.");
    detectorEventPublisher.publishDetectorsComplete(detectorToolResult);
    return detectorToolResult;
}
Also used : DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) DetectorEvaluator(com.synopsys.integration.detector.evaluation.DetectorEvaluator) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) DetectorAggregateEvaluationResult(com.synopsys.integration.detector.evaluation.DetectorAggregateEvaluationResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorType(com.synopsys.integration.detector.base.DetectorType) StatusType(com.synopsys.integration.detect.workflow.status.StatusType) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) DetectorEvaluationNameVersionDecider(com.synopsys.integration.detect.workflow.nameversion.DetectorEvaluationNameVersionDecider) DetectorNameVersionDecider(com.synopsys.integration.detect.workflow.nameversion.DetectorNameVersionDecider)

Example 3 with DetectorType

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

the class DetectorEvaluationNameVersionDecider method decideSuggestion.

public Optional<NameVersion> decideSuggestion(List<DetectorEvaluation> detectorEvaluations, String projectDetector) {
    List<DetectorProjectInfo> detectorProjectInfoList = detectorEvaluations.stream().filter(DetectorEvaluation::wasExtractionSuccessful).filter(detectorEvaluation -> StringUtils.isNotBlank(detectorEvaluation.getExtraction().getProjectName())).map(this::toProjectInfo).collect(Collectors.toList());
    DetectorType detectorType = preferredDetectorTypeFromString(projectDetector);
    return detectorNameVersionDecider.decideProjectNameVersion(detectorProjectInfoList, detectorType);
}
Also used : DetectorType(com.synopsys.integration.detector.base.DetectorType)

Example 4 with DetectorType

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

the class DetectorAggregateEvaluationResultTest method testSingleLevel.

@Test
public void testSingleLevel() {
    DetectorType detectorType = DetectorType.GRADLE;
    DetectorEvaluationTree evaluationTree = generateDetectorEvaluationTreeMock(detectorType);
    DetectorAggregateEvaluationResult result = new DetectorAggregateEvaluationResult(evaluationTree);
    assertEquals(1, result.getApplicableDetectorTypes().size());
    assertTrue(result.getApplicableDetectorTypes().contains(detectorType));
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorType(com.synopsys.integration.detector.base.DetectorType) Test(org.junit.jupiter.api.Test)

Example 5 with DetectorType

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

the class DetectorRuleSetEvaluator method evaluateSearchable.

public DetectorResult evaluateSearchable(DetectorRuleSet detectorRuleSet, DetectorRule detectorRule, SearchEnvironment environment) {
    if (!environment.getDetectorFilter().test(detectorRule)) {
        return new ExcludedDetectorResult();
    }
    int maxDepth = detectorRule.getMaxDepth();
    if (environment.getDepth() > maxDepth) {
        return new MaxDepthExceededDetectorResult(environment.getDepth(), maxDepth);
    }
    Set<DetectorRule> yieldTo = environment.getAppliedSoFar().stream().filter(it -> detectorRuleSet.getYieldsTo(detectorRule).contains(it)).collect(Collectors.toSet());
    if (yieldTo.size() > 0) {
        return new YieldedDetectorResult(yieldTo.stream().map(DetectorRule::getName).collect(Collectors.toSet()));
    }
    boolean nestable = detectorRule.isNestable();
    boolean selfNestable = detectorRule.isSelfNestable();
    boolean selfTypeNestable = detectorRule.isSelfTypeNestable();
    DetectorType detectorType = detectorRule.getDetectorType();
    Set<DetectorType> notNestableBeneath = detectorRule.getNotNestableBeneath();
    if (environment.isForceNestedSearch()) {
        return new ForcedNestedPassedDetectorResult();
    } else if (nestable) {
        if (!selfNestable && environment.getAppliedToParent().stream().anyMatch(detectorRule::equals)) {
            return new NotSelfNestableDetectorResult();
        }
        if (!selfTypeNestable && environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).anyMatch(detectorType::equals)) {
            return new NotSelfTypeNestableDetectorResult(detectorType);
        }
        if (notNestableBeneath.size() > 0) {
            Optional<DetectorType> notNestableBeneathType = environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).filter(notNestableBeneath::contains).findAny();
            if (notNestableBeneathType.isPresent()) {
                return new NotNestableBeneathDetectorResult(notNestableBeneathType.get());
            }
        }
    } else if (environment.getAppliedToParent().stream().anyMatch(it -> !it.isNestInvisible())) {
        return new NotNestableDetectorResult();
    }
    return new PassedDetectorResult();
}
Also used : MaxDepthExceededDetectorResult(com.synopsys.integration.detector.result.MaxDepthExceededDetectorResult) PassedDetectorResult(com.synopsys.integration.detector.result.PassedDetectorResult) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) NotSelfNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfNestableDetectorResult) Set(java.util.Set) Collectors(java.util.stream.Collectors) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Optional(java.util.Optional) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) ExcludedDetectorResult(com.synopsys.integration.detector.result.ExcludedDetectorResult) NotNestableDetectorResult(com.synopsys.integration.detector.result.NotNestableDetectorResult) YieldedDetectorResult(com.synopsys.integration.detector.result.YieldedDetectorResult) Optional(java.util.Optional) YieldedDetectorResult(com.synopsys.integration.detector.result.YieldedDetectorResult) PassedDetectorResult(com.synopsys.integration.detector.result.PassedDetectorResult) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) MaxDepthExceededDetectorResult(com.synopsys.integration.detector.result.MaxDepthExceededDetectorResult) DetectorType(com.synopsys.integration.detector.base.DetectorType) NotSelfNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfNestableDetectorResult) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ForcedNestedPassedDetectorResult(com.synopsys.integration.detector.result.ForcedNestedPassedDetectorResult) NotNestableDetectorResult(com.synopsys.integration.detector.result.NotNestableDetectorResult) ExcludedDetectorResult(com.synopsys.integration.detector.result.ExcludedDetectorResult)

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