use of com.synopsys.integration.detector.base.DetectorEvaluationTree 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.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.
the class Evaluator method evaluate.
public DetectorAggregateEvaluationResult evaluate(DetectorEvaluationTree rootEvaluation) {
DetectorEvaluationTree evaluationTree = performEvaluation(rootEvaluation);
DetectorAggregateEvaluationResult result = new DetectorAggregateEvaluationResult(evaluationTree);
executeResultCallbacks(result);
return result;
}
use of com.synopsys.integration.detector.base.DetectorEvaluationTree 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.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.
the class DetectorToolTest method executeToolTest.
private DetectorToolResult executeToolTest(Extraction extraction, DetectableResult extractionResult, String projectBomTool) throws DetectableException, ExecutableFailedException {
ExtractionEnvironmentProvider extractionEnvironmentProvider = Mockito.mock(ExtractionEnvironmentProvider.class);
DetectorFinder detectorFinder = Mockito.mock(DetectorFinder.class);
EventSystem eventSystem = Mockito.mock(EventSystem.class);
CodeLocationConverter codeLocationConverter = Mockito.mock(CodeLocationConverter.class);
DetectorIssuePublisher detectorIssuePublisher = Mockito.mock(DetectorIssuePublisher.class);
StatusEventPublisher statusEventPublisher = Mockito.mock(StatusEventPublisher.class);
ExitCodePublisher exitCodePublisher = Mockito.mock(ExitCodePublisher.class);
DetectorEventPublisher detectorEventPublisher = Mockito.mock(DetectorEventPublisher.class);
DetectorTool tool = new DetectorTool(detectorFinder, extractionEnvironmentProvider, eventSystem, codeLocationConverter, detectorIssuePublisher, statusEventPublisher, exitCodePublisher, detectorEventPublisher);
File directory = new File(".");
GoModCliDetectable detectable = createDetectable(extraction, extractionResult);
DetectorRule<GoModCliDetectable> rule = createRule(detectable);
DetectorRuleSet detectorRuleSet = createRuleSet(rule);
DetectorFinderOptions detectorFinderOptions = createFinderOptions();
DetectorEvaluationOptions evaluationOptions = createEvaluationOptions();
DetectorEvaluationTree evaluationTree = createEvaluationTree(extraction, extractionResult, directory, rule, detectorRuleSet);
Mockito.when(detectorFinder.findDetectors(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(Optional.of(evaluationTree));
return tool.performDetectors(directory, detectorRuleSet, detectorFinderOptions, evaluationOptions, projectBomTool, new ArrayList<>(), new SimpleFileFinder());
}
use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.
the class DetectorFinderTest method testSymLinks.
private void testSymLinks(boolean followSymLinks) throws IOException {
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS);
File initialDirectory = createDirWithSymLink("testSymLinks");
DetectorRuleSet detectorRuleSet = new DetectorRuleSet(new ArrayList<>(0), new HashMap<>(0));
DetectorFinderOptions options = createFinderOptions(followSymLinks);
DetectorFinder finder = new DetectorFinder();
Optional<DetectorEvaluationTree> tree = finder.findDetectors(initialDirectory, detectorRuleSet, options, new SimpleFileFinder());
// make sure the symlink was omitted from results
// final Set<DetectorEvaluationTree> subDirResults = tree.get().getChildren().iterator().next().getChildren();
Set<DetectorEvaluationTree> testDirs = tree.get().getChildren();
DetectorEvaluationTree symLinkTestDir = null;
for (DetectorEvaluationTree testDir : testDirs) {
if (testDir.getDirectory().getName().equals("testSymLinks")) {
symLinkTestDir = testDir;
break;
}
}
Set<DetectorEvaluationTree> subDirResults = symLinkTestDir.getChildren();
if (followSymLinks) {
assertEquals(2, subDirResults.size());
} else {
assertEquals(1, subDirResults.size());
String subDirContentsName = subDirResults.iterator().next().getDirectory().getName();
assertEquals("regularDir", subDirContentsName);
}
FileUtils.deleteDirectory(initialDirectory);
}
Aggregations