use of com.synopsys.integration.detector.base.DetectorType 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.DetectorType 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.DetectorType in project synopsys-detect by blackducksoftware.
the class DetectorEvaluationNameVersionDecider method decideSuggestion.
public Optional<NameVersion> decideSuggestion(List<DetectorEvaluation> detectorEvaluations, String projectDetector) {
List<DetectorProjectInfo> detectorProjectInfoList = detectorEvaluations.stream().filter(DetectorEvaluation::wasExtractionSuccessful).filter(detectorEvaluation -> StringUtils.isNotBlank(detectorEvaluation.getExtraction().getProjectName())).map(this::toProjectInfo).collect(Collectors.toList());
DetectorType detectorType = preferredDetectorTypeFromString(projectDetector);
return detectorNameVersionDecider.decideProjectNameVersion(detectorProjectInfoList, detectorType);
}
use of com.synopsys.integration.detector.base.DetectorType in project synopsys-detect by blackducksoftware.
the class DetectorAggregateEvaluationResultTest method testSingleLevel.
@Test
public void testSingleLevel() {
DetectorType detectorType = DetectorType.GRADLE;
DetectorEvaluationTree evaluationTree = generateDetectorEvaluationTreeMock(detectorType);
DetectorAggregateEvaluationResult result = new DetectorAggregateEvaluationResult(evaluationTree);
assertEquals(1, result.getApplicableDetectorTypes().size());
assertTrue(result.getApplicableDetectorTypes().contains(detectorType));
}
use of com.synopsys.integration.detector.base.DetectorType in project synopsys-detect by blackducksoftware.
the class DetectorRuleSetEvaluator method evaluateSearchable.
public DetectorResult evaluateSearchable(DetectorRuleSet detectorRuleSet, DetectorRule detectorRule, SearchEnvironment environment) {
if (!environment.getDetectorFilter().test(detectorRule)) {
return new ExcludedDetectorResult();
}
int maxDepth = detectorRule.getMaxDepth();
if (environment.getDepth() > maxDepth) {
return new MaxDepthExceededDetectorResult(environment.getDepth(), maxDepth);
}
Set<DetectorRule> yieldTo = environment.getAppliedSoFar().stream().filter(it -> detectorRuleSet.getYieldsTo(detectorRule).contains(it)).collect(Collectors.toSet());
if (yieldTo.size() > 0) {
return new YieldedDetectorResult(yieldTo.stream().map(DetectorRule::getName).collect(Collectors.toSet()));
}
boolean nestable = detectorRule.isNestable();
boolean selfNestable = detectorRule.isSelfNestable();
boolean selfTypeNestable = detectorRule.isSelfTypeNestable();
DetectorType detectorType = detectorRule.getDetectorType();
Set<DetectorType> notNestableBeneath = detectorRule.getNotNestableBeneath();
if (environment.isForceNestedSearch()) {
return new ForcedNestedPassedDetectorResult();
} else if (nestable) {
if (!selfNestable && environment.getAppliedToParent().stream().anyMatch(detectorRule::equals)) {
return new NotSelfNestableDetectorResult();
}
if (!selfTypeNestable && environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).anyMatch(detectorType::equals)) {
return new NotSelfTypeNestableDetectorResult(detectorType);
}
if (notNestableBeneath.size() > 0) {
Optional<DetectorType> notNestableBeneathType = environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).filter(notNestableBeneath::contains).findAny();
if (notNestableBeneathType.isPresent()) {
return new NotNestableBeneathDetectorResult(notNestableBeneathType.get());
}
}
} else if (environment.getAppliedToParent().stream().anyMatch(it -> !it.isNestInvisible())) {
return new NotNestableDetectorResult();
}
return new PassedDetectorResult();
}
Aggregations