use of com.synopsys.integration.detectable.Detectable 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.detectable.Detectable in project synopsys-detect by blackducksoftware.
the class DetectableFunctionalTest method run.
@Test
public void run() throws IOException, DetectableException, ExecutableFailedException, MissingExternalIdException, CycleDetectedException, ExecutableRunnerException, ParserConfigurationException, SAXException {
System.out.println(String.format("Function Test (%s) is using temp directory: %s", name, tempDirectory.toAbsolutePath().toString()));
setup();
DetectableEnvironment detectableEnvironment = new DetectableEnvironment(sourceDirectory.toFile());
Detectable detectable = create(detectableEnvironment);
DetectableResult applicable = detectable.applicable();
Assertions.assertTrue(applicable.getPassed(), String.format("Applicable should have passed but was: %s", applicable.toDescription()));
DetectableResult extractable = detectable.extractable();
Assertions.assertTrue(extractable.getPassed(), String.format("Extractable should have passed but was: %s", extractable.toDescription()));
ExtractionEnvironment extractionEnvironment = new ExtractionEnvironment(outputDirectory.toFile());
Extraction extraction = detectable.extract(extractionEnvironment);
Assertions.assertNotNull(extraction, "Detectable did not return an extraction!");
assertExtraction(extraction);
FileUtils.deleteDirectory(tempDirectory.toFile());
}
Aggregations