Search in sources :

Example 6 with DetectorResult

use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.

the class ExtractableEvaluator method extractableEvaluation.

public void extractableEvaluation(DetectorEvaluationTree detectorEvaluationTree) {
    logger.trace("Determining extractable detectors in the directory: {}", detectorEvaluationTree.getDirectory());
    for (DetectorEvaluation detectorEvaluation : detectorEvaluationTree.getOrderedEvaluations()) {
        if (detectorEvaluation.isSearchable() && detectorEvaluation.isApplicable()) {
            getDetectorEvaluatorListener().ifPresent(it -> it.extractableStarted(detectorEvaluation));
            logger.trace("Detector was searchable and applicable, will check extractable: {}", detectorEvaluation.getDetectorRule().getDescriptiveName());
            DetectableResult detectableExtractableResult = getDetectableExtractableResult(detectorEvaluation);
            DetectorResult extractableResult = new DetectorResult(detectableExtractableResult.getPassed(), detectableExtractableResult.toDescription(), detectableExtractableResult.getClass(), detectableExtractableResult.getExplanation(), detectableExtractableResult.getRelevantFiles());
            detectorEvaluation.setExtractable(extractableResult);
            if (detectorEvaluation.isExtractable()) {
                logger.trace("Extractable passed. Done evaluating for now.");
            } else {
                logger.trace("Extractable did not pass: {}", detectorEvaluation.getExtractabilityMessage());
            }
            getDetectorEvaluatorListener().ifPresent(it -> it.extractableEnded(detectorEvaluation));
        }
    }
    for (DetectorEvaluationTree childDetectorEvaluationTree : detectorEvaluationTree.getChildren()) {
        extractableEvaluation(childDetectorEvaluationTree);
    }
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) ExceptionDetectableResult(com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation)

Example 7 with DetectorResult

use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.

the class ApplicableEvaluator method searchAndApplicableEvaluation.

public void searchAndApplicableEvaluation(DetectorEvaluationTree detectorEvaluationTree, Set<DetectorRule> appliedInParent) {
    logger.trace("Determining applicable detectors on the directory: {}", detectorEvaluationTree.getDirectory());
    Set<DetectorRule> appliedSoFar = new HashSet<>();
    for (DetectorEvaluation detectorEvaluation : detectorEvaluationTree.getOrderedEvaluations()) {
        getDetectorEvaluatorListener().ifPresent(it -> it.applicableStarted(detectorEvaluation));
        DetectorRule detectorRule = detectorEvaluation.getDetectorRule();
        logger.trace("Evaluating detector: {}", detectorRule.getDescriptiveName());
        SearchEnvironment searchEnvironment = new SearchEnvironment(detectorEvaluationTree.getDepthFromRoot(), getEvaluationOptions().getDetectorFilter(), getEvaluationOptions().isForceNested(), getEvaluationOptions().isFollowSymLinks(), appliedInParent, appliedSoFar);
        detectorEvaluation.setSearchEnvironment(searchEnvironment);
        DetectorResult searchableResult = detectorRuleSetEvaluator.evaluateSearchable(detectorEvaluationTree.getDetectorRuleSet(), detectorEvaluation.getDetectorRule(), searchEnvironment);
        detectorEvaluation.setSearchable(searchableResult);
        if (detectorEvaluation.isSearchable()) {
            logger.trace("Searchable passed, will continue evaluating.");
            // TODO: potential todo, this could be invoked as part of the rule - ie we make a DetectableEnvironmentCreatable and the file could be given to the creatable (detectorRule.createEnvironment(file)
            DetectableEnvironment detectableEnvironment = new DetectableEnvironment(detectorEvaluationTree.getDirectory());
            detectorEvaluation.setDetectableEnvironment(detectableEnvironment);
            Detectable detectable = detectorRule.createDetectable(detectableEnvironment);
            detectorEvaluation.setDetectable(detectable);
            DetectableResult applicable = detectable.applicable();
            DetectorResult applicableResult = new DetectorResult(applicable.getPassed(), applicable.toDescription(), applicable.getClass(), applicable.getExplanation(), applicable.getRelevantFiles());
            detectorEvaluation.setApplicable(applicableResult);
            if (detectorEvaluation.isApplicable()) {
                logger.trace("Found applicable detector: {}", detectorRule.getDescriptiveName());
                appliedSoFar.add(detectorRule);
            } else {
                logger.trace("Applicable did not pass: {}", detectorEvaluation.getApplicabilityMessage());
            }
        } else {
            logger.trace("Searchable did not pass: {}", detectorEvaluation.getSearchabilityMessage());
        }
        getDetectorEvaluatorListener().ifPresent(it -> it.applicableEnded(detectorEvaluation));
    }
    if (!appliedSoFar.isEmpty()) {
        // TODO: Perfect log level also matters here. To little and we may appear stuck, but we may also be flooding the logs.
        logger.debug("Found ({}) applicable detectors in: {}", appliedSoFar.size(), detectorEvaluationTree.getDirectory());
    }
    Set<DetectorRule> nextAppliedInParent = new HashSet<>();
    nextAppliedInParent.addAll(appliedInParent);
    nextAppliedInParent.addAll(appliedSoFar);
    for (DetectorEvaluationTree childDetectorEvaluationTree : detectorEvaluationTree.getChildren()) {
        searchAndApplicableEvaluation(childDetectorEvaluationTree, nextAppliedInParent);
    }
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Detectable(com.synopsys.integration.detectable.Detectable) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) HashSet(java.util.HashSet)

Example 8 with DetectorResult

use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.

the class DetectorToolTest method createEvaluationTree.

private DetectorEvaluationTree createEvaluationTree(Extraction extraction, DetectableResult extractionResult, File directory, DetectorRule<GoModCliDetectable> rule, DetectorRuleSet detectorRuleSet) {
    DetectorEvaluation detectorEvaluation = new DetectorEvaluation(rule);
    DetectorResult extractableResult = new DetectorResult(extractionResult.getPassed(), extractionResult.toDescription(), extractionResult.getClass(), Collections.emptyList(), Collections.emptyList());
    detectorEvaluation.setExtractable(extractableResult);
    detectorEvaluation.setExtraction(extraction);
    detectorEvaluation.setApplicable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setSearchable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setDetectableEnvironment(new DetectableEnvironment(new File("")));
    return new DetectorEvaluationTree(directory, 0, detectorRuleSet, Collections.singletonList(detectorEvaluation), new HashSet<>());
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment)

Aggregations

DetectorResult (com.synopsys.integration.detector.result.DetectorResult)8 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)6 HashSet (java.util.HashSet)5 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)4 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)4 DetectorType (com.synopsys.integration.detector.base.DetectorType)4 NotNestableBeneathDetectorResult (com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult)4 NotSelfTypeNestableDetectorResult (com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult)4 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)4 Set (java.util.Set)4 Test (org.junit.jupiter.api.Test)4 Sets (com.github.jsonldjava.shaded.com.google.common.collect.Sets)3 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)3 SwiftCliDetectable (com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable)3 XcodeProjectDetectable (com.synopsys.integration.detectable.detectables.xcode.XcodeProjectDetectable)3 XcodeWorkspaceDetectable (com.synopsys.integration.detectable.detectables.xcode.XcodeWorkspaceDetectable)3 DetectorRuleSetBuilder (com.synopsys.integration.detector.rule.DetectorRuleSetBuilder)3 Predicate (java.util.function.Predicate)3 Assertions (org.junit.jupiter.api.Assertions)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3