use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.
the class ExtractableEvaluator method setupDiscoveryAndExtractions.
public void setupDiscoveryAndExtractions(DetectorEvaluationTree detectorEvaluationTree, Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider) {
for (DetectorEvaluation detectorEvaluation : detectorEvaluationTree.getOrderedEvaluations()) {
if (detectorEvaluation.isExtractable()) {
ExtractionEnvironment extractionEnvironment = extractionEnvironmentProvider.apply(detectorEvaluation);
detectorEvaluation.setExtractionEnvironment(extractionEnvironment);
}
}
for (DetectorEvaluationTree childDetectorEvaluationTree : detectorEvaluationTree.getChildren()) {
setupDiscoveryAndExtractions(childDetectorEvaluationTree, extractionEnvironmentProvider);
}
}
use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.
the class ExtractableEvaluator method extractableEvaluation.
public void extractableEvaluation(DetectorEvaluationTree detectorEvaluationTree) {
logger.trace("Determining extractable detectors in the directory: {}", detectorEvaluationTree.getDirectory());
for (DetectorEvaluation detectorEvaluation : detectorEvaluationTree.getOrderedEvaluations()) {
if (detectorEvaluation.isSearchable() && detectorEvaluation.isApplicable()) {
getDetectorEvaluatorListener().ifPresent(it -> it.extractableStarted(detectorEvaluation));
logger.trace("Detector was searchable and applicable, will check extractable: {}", detectorEvaluation.getDetectorRule().getDescriptiveName());
DetectableResult detectableExtractableResult = getDetectableExtractableResult(detectorEvaluation);
DetectorResult extractableResult = new DetectorResult(detectableExtractableResult.getPassed(), detectableExtractableResult.toDescription(), detectableExtractableResult.getClass(), detectableExtractableResult.getExplanation(), detectableExtractableResult.getRelevantFiles());
detectorEvaluation.setExtractable(extractableResult);
if (detectorEvaluation.isExtractable()) {
logger.trace("Extractable passed. Done evaluating for now.");
} else {
logger.trace("Extractable did not pass: {}", detectorEvaluation.getExtractabilityMessage());
}
getDetectorEvaluatorListener().ifPresent(it -> it.extractableEnded(detectorEvaluation));
}
}
for (DetectorEvaluationTree childDetectorEvaluationTree : detectorEvaluationTree.getChildren()) {
extractableEvaluation(childDetectorEvaluationTree);
}
}
use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.
the class ExtractionEvaluator method extractionEvaluation.
public void extractionEvaluation(DetectorEvaluationTree detectorEvaluationTree) {
logger.trace("Extracting detectors in the directory: {}", detectorEvaluationTree.getDirectory());
for (DetectorEvaluation detectorEvaluation : detectorEvaluationTree.getOrderedEvaluations()) {
if (detectorEvaluation.isExtractable() && detectorEvaluation.getExtractionEnvironment() != null) {
logger.trace("Detector was searchable, applicable and extractable, will perform extraction: {}", detectorEvaluation.getDetectorRule().getDescriptiveName());
Detectable detectable = detectorEvaluation.getDetectable();
getDetectorEvaluatorListener().ifPresent(it -> it.extractionStarted(detectorEvaluation));
try {
Extraction extraction = detectable.extract(detectorEvaluation.getExtractionEnvironment());
detectorEvaluation.setExtraction(extraction);
} catch (Exception e) {
detectorEvaluation.setExtraction(new Extraction.Builder().exception(e).build());
}
getDetectorEvaluatorListener().ifPresent(it -> it.extractionEnded(detectorEvaluation));
logger.trace("Extraction result: {}", detectorEvaluation.wasExtractionSuccessful());
}
}
for (DetectorEvaluationTree childDetectorEvaluationTree : detectorEvaluationTree.getChildren()) {
extractionEvaluation(childDetectorEvaluationTree);
}
}
use of com.synopsys.integration.detector.base.DetectorEvaluation 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);
}
}
use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.
the class DetectorIssuePublisher method publishEvents.
private void publishEvents(StatusEventPublisher statusEventPublisher, List<DetectorEvaluationTree> trees) {
String spacer = "\t";
for (DetectorEvaluationTree tree : trees) {
List<DetectorEvaluation> excepted = DetectorEvaluationUtils.filteredChildren(tree, DetectorEvaluation::wasExtractionException);
List<DetectorEvaluation> failed = DetectorEvaluationUtils.filteredChildren(tree, DetectorEvaluation::wasExtractionFailure);
List<DetectorEvaluation> notExtractable = DetectorEvaluationUtils.filteredChildren(tree, evaluation -> evaluation.isApplicable() && !evaluation.isExtractable());
List<String> messages = new ArrayList<>();
addIfNotEmpty(messages, "Not Extractable: ", spacer, notExtractable, DetectorEvaluation::getExtractabilityMessage);
addIfNotEmpty(messages, "Failure: ", spacer, failed, detectorEvaluation -> detectorEvaluation.getExtraction().getDescription());
addIfNotEmpty(messages, "Exception: ", spacer, excepted, detectorEvaluation -> ExceptionUtil.oneSentenceDescription(detectorEvaluation.getExtraction().getError()));
if (messages.size() > 0) {
messages.add(0, tree.getDirectory().toString());
statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTOR, "Detector Issue", messages));
}
}
}
Aggregations