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);
}
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);
}
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));
}
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);
}
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;
}
Aggregations