Search in sources :

Example 1 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation 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);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation)

Example 2 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation 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;
}
Also used : DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) DetectorEvaluator(com.synopsys.integration.detector.evaluation.DetectorEvaluator) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) DetectorAggregateEvaluationResult(com.synopsys.integration.detector.evaluation.DetectorAggregateEvaluationResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorType(com.synopsys.integration.detector.base.DetectorType) StatusType(com.synopsys.integration.detect.workflow.status.StatusType) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) DetectorEvaluationNameVersionDecider(com.synopsys.integration.detect.workflow.nameversion.DetectorEvaluationNameVersionDecider) DetectorNameVersionDecider(com.synopsys.integration.detect.workflow.nameversion.DetectorNameVersionDecider)

Example 3 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation 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("");
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) HashMap(java.util.HashMap) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation)

Example 4 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.

the class SearchSummaryReporter method printDirectoriesInfo.

private void printDirectoriesInfo(ReportWriter writer, List<DetectorEvaluationTree> trees) {
    ReporterUtils.printHeader(writer, "Search results");
    boolean printedAtLeastOne = false;
    for (DetectorEvaluationTree tree : trees) {
        List<DetectorEvaluation> applicable = DetectorEvaluationUtils.applicableChildren(tree);
        if (applicable.size() > 0) {
            writer.writeLine(tree.getDirectory().toString());
            writer.writeLine("\tAPPLIES: " + applicable.stream().map(it -> it.getDetectorRule().getDescriptiveName()).sorted().collect(Collectors.joining(", ")));
            printedAtLeastOne = true;
        }
    }
    if (!printedAtLeastOne) {
        writer.writeLine("No detectors found.");
    }
    ReporterUtils.printFooter(writer);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation)

Example 5 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.

the class FormattedOutputManagerTest method detectorOutputStatusDataTest.

@Test
public <T extends Detectable> void detectorOutputStatusDataTest() throws IllegalAccessException {
    EventSystem eventSystem = new EventSystem();
    FormattedOutputManager formattedOutputManager = new FormattedOutputManager(eventSystem);
    DetectorRule rule = Mockito.mock(DetectorRule.class);
    Mockito.when(rule.getDescriptiveName()).thenReturn("");
    Mockito.when(rule.getName()).thenReturn("");
    Mockito.when(rule.getDetectorType()).thenReturn(DetectorType.GO_MOD);
    DetectorEvaluation detectorEvaluation = new DetectorEvaluation(rule);
    ExecutableNotFoundDetectableResult result = new ExecutableNotFoundDetectableResult("go");
    DetectorResult extractableResult = new DetectorResult(result.getPassed(), result.toDescription(), result.getClass(), Collections.emptyList(), Collections.emptyList());
    detectorEvaluation.setExtractable(extractableResult);
    detectorEvaluation.setApplicable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setSearchable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setDetectableEnvironment(new DetectableEnvironment(new File("")));
    DetectorToolResult detectorToolResult = new DetectorToolResult(null, null, null, new HashSet<>(), new DetectorEvaluationTree(null, 0, null, Collections.singletonList(detectorEvaluation), new HashSet<>()), null);
    eventSystem.publishEvent(Event.DetectorsComplete, detectorToolResult);
    DetectInfo detectInfo = new DetectInfo("", null, "");
    FormattedOutput formattedOutput = formattedOutputManager.createFormattedOutput(detectInfo);
    FormattedDetectorOutput detectorOutput = formattedOutput.detectors.get(0);
    Assertions.assertEquals("FAILURE", detectorOutput.status);
    Assertions.assertEquals(DetectorStatusCode.EXECUTABLE_NOT_FOUND, detectorOutput.statusCode);
    Assertions.assertEquals("No go executable was found.", detectorOutput.statusReason);
}
Also used : ExecutableNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult) DetectInfo(com.synopsys.integration.detect.configuration.DetectInfo) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) FormattedOutputManager(com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput) DetectorToolResult(com.synopsys.integration.detect.tool.detector.DetectorToolResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) FormattedDetectorOutput(com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)30 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)28 File (java.io.File)15 Test (org.junit.jupiter.api.Test)14 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)11 Detectable (com.synopsys.integration.detectable.Detectable)10 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)9 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)8 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)7 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)7 List (java.util.List)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Mockito (org.mockito.Mockito)7 Collections (java.util.Collections)6 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)5 Extraction (com.synopsys.integration.detectable.extraction.Extraction)5 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)5 Function (java.util.function.Function)5 Predicate (java.util.function.Predicate)5