Search in sources :

Example 6 with Detectable

use of com.synopsys.integration.detectable.Detectable 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 7 with Detectable

use of com.synopsys.integration.detectable.Detectable in project synopsys-detect by blackducksoftware.

the class DetectableFunctionalTest method run.

@Test
public void run() throws IOException, DetectableException, ExecutableFailedException, MissingExternalIdException, CycleDetectedException, ExecutableRunnerException, ParserConfigurationException, SAXException {
    System.out.println(String.format("Function Test (%s) is using temp directory: %s", name, tempDirectory.toAbsolutePath().toString()));
    setup();
    DetectableEnvironment detectableEnvironment = new DetectableEnvironment(sourceDirectory.toFile());
    Detectable detectable = create(detectableEnvironment);
    DetectableResult applicable = detectable.applicable();
    Assertions.assertTrue(applicable.getPassed(), String.format("Applicable should have passed but was: %s", applicable.toDescription()));
    DetectableResult extractable = detectable.extractable();
    Assertions.assertTrue(extractable.getPassed(), String.format("Extractable should have passed but was: %s", extractable.toDescription()));
    ExtractionEnvironment extractionEnvironment = new ExtractionEnvironment(outputDirectory.toFile());
    Extraction extraction = detectable.extract(extractionEnvironment);
    Assertions.assertNotNull(extraction, "Detectable did not return an extraction!");
    assertExtraction(extraction);
    FileUtils.deleteDirectory(tempDirectory.toFile());
}
Also used : Detectable(com.synopsys.integration.detectable.Detectable) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

Detectable (com.synopsys.integration.detectable.Detectable)7 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)5 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)5 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)5 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)5 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)4 List (java.util.List)4 Test (org.junit.jupiter.api.Test)4 Extraction (com.synopsys.integration.detectable.extraction.Extraction)3 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)3 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)3 File (java.io.File)3 Collections (java.util.Collections)3 Predicate (java.util.function.Predicate)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Mockito (org.mockito.Mockito)3 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)2 PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)2 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)2 Gson (com.google.gson.Gson)1