Search in sources :

Example 11 with DetectorEvaluation

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

the class ExtractionEvaluatorTest method testEvaluationSuccess.

@Test
public void testEvaluationSuccess() throws DetectableException, ExecutableFailedException, IOException, CycleDetectedException, MissingExternalIdException, ExecutableRunnerException, ParserConfigurationException, SAXException {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ExtractionEvaluator evaluator = new ExtractionEvaluator(evaluationOptions);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, false);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).extractionStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setExtraction(Mockito.any(Extraction.class));
    Mockito.verify(detectorEvaluatorListener).extractionEnded(detectorEvaluation);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 12 with DetectorEvaluation

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

the class ExtractionEvaluatorTest method testEvaluationException.

@Test
public void testEvaluationException() throws DetectableException, ExecutableFailedException, IOException, CycleDetectedException, MissingExternalIdException, ExecutableRunnerException, ParserConfigurationException, SAXException {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ExtractionEvaluator evaluator = new ExtractionEvaluator(evaluationOptions);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, true);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).extractionStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setExtraction(Mockito.any(Extraction.class));
    Mockito.verify(detectorEvaluatorListener).extractionEnded(detectorEvaluation);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 13 with DetectorEvaluation

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

the class DetectorFinder method findDetectors.

private Optional<DetectorEvaluationTree> findDetectors(File directory, DetectorRuleSet detectorRuleSet, int depth, DetectorFinderOptions options, FileFinder fileFinder) {
    if (depth > options.getMaximumDepth()) {
        logger.trace("Skipping directory as it exceeds max depth: {}", directory);
        return Optional.empty();
    }
    String directoryString = Optional.ofNullable(directory).map(File::toString).orElse("null");
    if (null == directory || !directory.isDirectory()) {
        logger.trace("Skipping file as it is not a directory: {}", directoryString);
        return Optional.empty();
    }
    if (Files.isSymbolicLink(directory.toPath())) {
        if (!options.followSymLinks()) {
            logger.debug("Skipping file as it is a symbolic link and following symbolic links has been disabled: {}", directoryString);
            return Optional.empty();
        } else {
            logger.debug("Following symbolic link: {}", directoryString);
            Path linkTarget;
            try {
                linkTarget = directory.toPath().toRealPath();
            } catch (IOException e) {
                logger.debug("Symbolic link: {} does not point to a valid directory; skipping it", directoryString);
                return Optional.empty();
            }
            if (!linkTarget.toFile().isDirectory()) {
                logger.debug("Symbolic link: {} does not point to a valid directory; skipping it", directoryString);
                return Optional.empty();
            }
            directory = linkTarget.toFile();
        }
    }
    List<DetectorEvaluation> evaluations = detectorRuleSet.getOrderedDetectorRules().stream().map(DetectorEvaluation::new).collect(Collectors.toList());
    logger.trace("Traversing directory: {}", directory.getPath());
    Set<DetectorEvaluationTree> children = new HashSet<>();
    List<File> subDirectories = fileFinder.findFiles(directory, options.getFileFilter());
    logger.debug("filteredSubDirectories: {}", subDirectories);
    for (File subDirectory : subDirectories) {
        Optional<DetectorEvaluationTree> childEvaluationSet = findDetectors(subDirectory, detectorRuleSet, depth + 1, options, fileFinder);
        childEvaluationSet.ifPresent(children::add);
    }
    return Optional.of(new DetectorEvaluationTree(directory, depth, detectorRuleSet, evaluations, children));
}
Also used : Path(java.nio.file.Path) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) IOException(java.io.IOException) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) HashSet(java.util.HashSet)

Example 14 with DetectorEvaluation

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

the class ApplicableEvaluatorTest method testEvaluationNotSearchable.

@Test
public void testEvaluationNotSearchable() {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ApplicableEvaluator evaluator = new ApplicableEvaluator(evaluationOptions);
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, false);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).applicableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluatorListener).applicableEnded(detectorEvaluation);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 15 with DetectorEvaluation

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

the class ApplicableEvaluatorTest method createEvaluationMocks.

private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean alreadyApplicable, boolean searchable) {
    DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
    List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
    Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
    DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
    Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
    Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
    Mockito.when(detectorEvaluation.isApplicable()).thenReturn(alreadyApplicable);
    Mockito.when(detectorEvaluation.isSearchable()).thenReturn(searchable);
    Mockito.when(detectorEvaluationTree.getDepthFromRoot()).thenReturn(0);
    Mockito.when(evaluationOptions.isForceNested()).thenReturn(true);
    Predicate<DetectorRule> rulePredicate = it -> true;
    Mockito.when(evaluationOptions.getDetectorFilter()).thenReturn(rulePredicate);
    Mockito.when(detectorEvaluation.isSearchable()).thenReturn(true);
    Detectable detectable = Mockito.mock(Detectable.class);
    Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
    Mockito.when(detectable.applicable()).thenReturn(new FailedDetectableResult());
    return detectorEvaluation;
}
Also used : Predicate(java.util.function.Predicate) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) File(java.io.File) Test(org.junit.jupiter.api.Test) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Mockito(org.mockito.Mockito) List(java.util.List) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Detectable(com.synopsys.integration.detectable.Detectable) FailedDetectableResult(com.synopsys.integration.detectable.detectable.result.FailedDetectableResult) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collections(java.util.Collections) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Detectable(com.synopsys.integration.detectable.Detectable) FailedDetectableResult(com.synopsys.integration.detectable.detectable.result.FailedDetectableResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment)

Aggregations

DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)30 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)28 File (java.io.File)15 Test (org.junit.jupiter.api.Test)14 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)11 Detectable (com.synopsys.integration.detectable.Detectable)10 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)9 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)8 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)7 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)7 List (java.util.List)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Mockito (org.mockito.Mockito)7 Collections (java.util.Collections)6 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)5 Extraction (com.synopsys.integration.detectable.extraction.Extraction)5 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)5 Function (java.util.function.Function)5 Predicate (java.util.function.Predicate)5