use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.
the class DetectorAggregateEvaluationResult method getApplicableDetectorTypesRecursively.
private Set<DetectorType> getApplicableDetectorTypesRecursively(DetectorEvaluationTree givenEvaluationTree) {
Set<DetectorType> applied = new HashSet<>();
applied.addAll(getApplicableDetectorTypes(givenEvaluationTree));
for (DetectorEvaluationTree childEvaluationTree : givenEvaluationTree.getChildren()) {
applied.addAll(getApplicableDetectorTypesRecursively(childEvaluationTree));
}
return applied;
}
use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.
the class DetectorTool method printExplanations.
private void printExplanations(DetectorEvaluationTree root) {
logger.info(ReportConstants.HEADING);
logger.info("Detector Report");
logger.info(ReportConstants.HEADING);
boolean anyFound = false;
for (DetectorEvaluationTree tree : root.asFlatList()) {
List<DetectorEvaluation> applicable = DetectorEvaluationUtils.applicableChildren(tree);
if (!applicable.isEmpty()) {
anyFound = true;
logger.info("\t" + tree.getDirectory() + " (depth " + tree.getDepthFromRoot() + ")");
applicable.forEach(evaluation -> {
logger.info("\t\t" + evaluation.getDetectorRule().getDescriptiveName());
evaluation.getAllExplanations().forEach(explanation -> logger.info("\t\t\t" + explanation.describeSelf()));
});
}
}
if (!anyFound) {
logger.info("No detectors found.");
}
logger.info(ReportConstants.RUN_SEPARATOR);
}
use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.
the class DetectorTool method performDetectors.
public DetectorToolResult performDetectors(File directory, DetectorRuleSet detectorRuleSet, DetectorFinderOptions detectorFinderOptions, DetectorEvaluationOptions evaluationOptions, String projectDetector, List<DetectorType> requiredDetectors, FileFinder fileFinder) {
logger.debug("Initializing detector system.");
Optional<DetectorEvaluationTree> possibleRootEvaluation;
logger.debug("Starting detector file system traversal.");
possibleRootEvaluation = detectorFinder.findDetectors(directory, detectorRuleSet, detectorFinderOptions, fileFinder);
if (!possibleRootEvaluation.isPresent()) {
logger.error("The source directory could not be searched for detectors - detector tool failed.");
logger.error("Please ensure the provided source path is a directory and detect has access.");
exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_CONFIGURATION, "Detector tool failed to run on the configured source path.");
return new DetectorToolResult();
}
DetectorEvaluationTree rootEvaluation = possibleRootEvaluation.get();
List<DetectorEvaluation> detectorEvaluations = rootEvaluation.allDescendentEvaluations();
logger.trace("Setting up detector events.");
// DetectorNameVersionHandler detectorNameVersionHandler = createNameVersionHandler(projectDetector);
DetectorEvaluatorBroadcaster eventBroadcaster = new DetectorEvaluatorBroadcaster(eventSystem);
DetectorEvaluator detectorEvaluator = new DetectorEvaluator(evaluationOptions, extractionEnvironmentProvider::createExtractionEnvironment);
detectorEvaluator.setDetectorEvaluatorListener(eventBroadcaster);
detectorEvaluator.registerPostApplicableCallback(detectorAggregateEvaluationResult -> {
detectorEventPublisher.publishApplicableCompleted(detectorAggregateEvaluationResult.getApplicableDetectorTypesRecursively());
detectorEventPublisher.publishSearchCompleted(detectorAggregateEvaluationResult.getEvaluationTree());
logger.info("");
});
detectorEvaluator.registerPostExtractableCallback(detectorAggregateEvaluationResult -> {
detectorEventPublisher.publishPreparationsCompleted(detectorAggregateEvaluationResult.getEvaluationTree());
logger.debug("Counting detectors that will be evaluated.");
Integer extractionCount = detectorAggregateEvaluationResult.getExtractionCount();
detectorEventPublisher.publishExtractionCount(extractionCount);
logger.debug("Total number of detectors: {}", extractionCount);
});
detectorEvaluator.registerPostExtractionCallback(detectorAggregateEvaluationResult -> detectorEventPublisher.publishExtractionsCompleted(detectorAggregateEvaluationResult.getEvaluationTree()));
DetectorAggregateEvaluationResult evaluationResult = detectorEvaluator.evaluate(rootEvaluation);
// TODO- finished extractions?
logger.debug("Finished detectors.");
printExplanations(rootEvaluation);
Map<DetectorType, StatusType> statusMap = extractStatus(detectorEvaluations);
publishStatusEvents(statusMap);
publishFileEvents(detectorEvaluations);
detectorIssuePublisher.publishEvents(statusEventPublisher, rootEvaluation);
publishMissingDetectorEvents(requiredDetectors, evaluationResult.getApplicableDetectorTypesRecursively());
Map<CodeLocation, DetectCodeLocation> codeLocationMap = createCodeLocationMap(detectorEvaluations, directory);
DetectorEvaluationNameVersionDecider detectorEvaluationNameVersionDecider = new DetectorEvaluationNameVersionDecider(new DetectorNameVersionDecider());
Optional<NameVersion> bomToolProjectNameVersion = detectorEvaluationNameVersionDecider.decideSuggestion(detectorEvaluations, projectDetector);
logger.debug("Finished evaluating detectors for project info.");
DetectorToolResult detectorToolResult = new DetectorToolResult(bomToolProjectNameVersion.orElse(null), new ArrayList<>(codeLocationMap.values()), evaluationResult.getApplicableDetectorTypes(), new HashSet<>(), rootEvaluation, codeLocationMap);
// Completed.
logger.debug("Finished running detectors.");
detectorEventPublisher.publishDetectorsComplete(detectorToolResult);
return detectorToolResult;
}
use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.
the class DetailedSearchSummaryReporter method printDirectoriesDebug.
private void printDirectoriesDebug(ReportWriter writer, List<DetectorEvaluationTree> trees) {
for (DetectorEvaluationTree tree : trees) {
List<String> toPrint = new ArrayList<>();
toPrint.addAll(printDetails(" APPLIED: ", DetectorEvaluationUtils.applicableChildren(tree), DetectorEvaluation::getApplicabilityMessage));
toPrint.addAll(printDetails("DID NOT APPLY: ", DetectorEvaluationUtils.notSearchableChildren(tree), DetectorEvaluation::getSearchabilityMessage));
toPrint.addAll(printDetails("DID NOT APPLY: ", DetectorEvaluationUtils.searchableButNotApplicableChildren(tree), DetectorEvaluation::getApplicabilityMessage));
if (toPrint.size() > 0) {
writer.writeSeparator();
writer.writeLine("Detailed search results for directory");
writer.writeLine(tree.getDirectory().toString());
writer.writeSeparator();
toPrint.stream().sorted().forEach(writer::writeLine);
writer.writeSeparator();
}
}
}
use of com.synopsys.integration.detector.base.DetectorEvaluationTree in project synopsys-detect by blackducksoftware.
the class OverviewSummaryReporter method writeSummaries.
private void writeSummaries(ReportWriter writer, List<DetectorEvaluationTree> detectorEvaluationTrees) {
writer.writeSeparator();
for (DetectorEvaluationTree detectorEvaluationTree : detectorEvaluationTrees) {
for (DetectorEvaluation detectorEvaluation : detectorEvaluationTree.getOrderedEvaluations()) {
if (detectorEvaluation.isSearchable() && detectorEvaluation.isApplicable()) {
writer.writeLine("DIRECTORY: " + detectorEvaluationTree.getDirectory());
writer.writeLine("DETECTOR: " + detectorEvaluation.getDetectorRule().getDescriptiveName());
writer.writeLine("\tEXTRACTABLE: " + detectorEvaluation.getExtractabilityMessage());
writer.writeLine("\tEXTRACTED: " + detectorEvaluation.wasExtractionSuccessful());
if (detectorEvaluation.getExtraction() != null && StringUtils.isNotBlank(detectorEvaluation.getExtraction().getDescription())) {
writer.writeLine("\tEXTRACTION: " + detectorEvaluation.getExtraction().getDescription());
}
Map<String, String> data = new HashMap<>();
ObjectPrinter.populateObjectPrivate(null, detectorEvaluation.getDetectable(), data);
data.forEach((key, value) -> writer.writeLine("\t" + key + ": " + value));
}
}
}
writer.writeLine(ReportConstants.HEADING);
writer.writeLine("");
writer.writeLine("");
}
Aggregations