Search in sources :

Example 1 with StatusType

use of com.synopsys.integration.detect.workflow.status.StatusType 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 2 with StatusType

use of com.synopsys.integration.detect.workflow.status.StatusType in project synopsys-detect by blackducksoftware.

the class DetectorTool method extractStatus.

private Map<DetectorType, StatusType> extractStatus(List<DetectorEvaluation> detectorEvaluations) {
    EnumMap<DetectorType, StatusType> statusMap = new EnumMap<>(DetectorType.class);
    for (DetectorEvaluation detectorEvaluation : detectorEvaluations) {
        DetectorType detectorType = detectorEvaluation.getDetectorType();
        Optional<StatusType> foundStatusType = determineDetectorExtractionStatus(detectorEvaluation);
        if (foundStatusType.isPresent()) {
            StatusType statusType = foundStatusType.get();
            if (statusType == StatusType.FAILURE || !statusMap.containsKey(detectorType)) {
                statusMap.put(detectorType, statusType);
            }
        }
    }
    return statusMap;
}
Also used : DetectorType(com.synopsys.integration.detector.base.DetectorType) StatusType(com.synopsys.integration.detect.workflow.status.StatusType) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) EnumMap(java.util.EnumMap)

Example 3 with StatusType

use of com.synopsys.integration.detect.workflow.status.StatusType in project synopsys-detect by blackducksoftware.

the class DetectorTool method determineDetectorExtractionStatus.

private Optional<StatusType> determineDetectorExtractionStatus(DetectorEvaluation detectorEvaluation) {
    StatusType statusType = null;
    if (detectorEvaluation.isApplicable()) {
        if (detectorEvaluation.isExtractable()) {
            if (detectorEvaluation.wasExtractionSuccessful()) {
                statusType = StatusType.SUCCESS;
            } else {
                statusType = StatusType.FAILURE;
                boolean extractionUnknownFailure = !detectorEvaluation.wasExtractionFailure() && !detectorEvaluation.wasExtractionException();
                if (extractionUnknownFailure) {
                    logger.warn("An issue occurred in the detector system, an unknown evaluation status was created. Please contact support.");
                }
            }
        } else {
            statusType = StatusType.FAILURE;
        }
    }
    return Optional.ofNullable(statusType);
}
Also used : StatusType(com.synopsys.integration.detect.workflow.status.StatusType)

Example 4 with StatusType

use of com.synopsys.integration.detect.workflow.status.StatusType in project synopsys-detect by blackducksoftware.

the class SignatureScannerReport method create.

public static SignatureScannerReport create(SignatureScanPath signatureScanPath, @Nullable ScanCommandOutput scanCommandOutput) {
    StatusType statusType;
    if (scanCommandOutput == null || Result.FAILURE.equals(scanCommandOutput.getResult())) {
        statusType = StatusType.FAILURE;
    } else {
        statusType = StatusType.SUCCESS;
    }
    Optional<ScanCommandOutput> optionalOutput = Optional.ofNullable(scanCommandOutput);
    boolean hasOutput = optionalOutput.isPresent();
    Integer exitCode = optionalOutput.map(ScanCommandOutput::getScanExitCode).filter(Optional::isPresent).map(Optional::get).orElse(null);
    Exception exception = optionalOutput.map(ScanCommandOutput::getException).filter(Optional::isPresent).map(Optional::get).orElse(null);
    String errorMessage = optionalOutput.map(ScanCommandOutput::getErrorMessage).filter(Optional::isPresent).map(Optional::get).orElse(null);
    return new SignatureScannerReport(signatureScanPath, statusType, exitCode, exception, errorMessage, hasOutput);
}
Also used : Optional(java.util.Optional) StatusType(com.synopsys.integration.detect.workflow.status.StatusType) ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput)

Aggregations

StatusType (com.synopsys.integration.detect.workflow.status.StatusType)4 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)2 DetectorType (com.synopsys.integration.detector.base.DetectorType)2 ScanCommandOutput (com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput)1 DetectCodeLocation (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)1 DetectorEvaluationNameVersionDecider (com.synopsys.integration.detect.workflow.nameversion.DetectorEvaluationNameVersionDecider)1 DetectorNameVersionDecider (com.synopsys.integration.detect.workflow.nameversion.DetectorNameVersionDecider)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)1 DetectorAggregateEvaluationResult (com.synopsys.integration.detector.evaluation.DetectorAggregateEvaluationResult)1 DetectorEvaluator (com.synopsys.integration.detector.evaluation.DetectorEvaluator)1 NameVersion (com.synopsys.integration.util.NameVersion)1 EnumMap (java.util.EnumMap)1 Optional (java.util.Optional)1