Search in sources :

Example 1 with StatusType

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

the class BlackDuckSignatureScanner method reportResults.

private void reportResults(List<SignatureScanPath> signatureScanPaths, List<ScanCommandOutput> scanCommandOutputList) {
    boolean anyFailed = false;
    boolean anyExitCodeIs64 = false;
    for (final SignatureScanPath target : signatureScanPaths) {
        Optional<ScanCommandOutput> targetOutput = scanCommandOutputList.stream().filter(output -> output.getScanTarget().equals(target.targetPath)).findFirst();
        StatusType scanStatus;
        if (!targetOutput.isPresent()) {
            scanStatus = StatusType.FAILURE;
            logger.info(String.format("Scanning target %s was never scanned by the BlackDuck CLI.", target.targetPath));
        } else {
            ScanCommandOutput output = targetOutput.get();
            if (output.getResult() == Result.FAILURE) {
                scanStatus = StatusType.FAILURE;
                if (output.getException().isPresent() && output.getErrorMessage().isPresent()) {
                    logger.error(String.format("Scanning target %s failed: %s", target.targetPath, output.getErrorMessage().get()));
                    logger.debug(output.getErrorMessage().get(), output.getException().get());
                } else if (output.getErrorMessage().isPresent()) {
                    logger.error(String.format("Scanning target %s failed: %s", target.targetPath, output.getErrorMessage().get()));
                } else {
                    logger.error(String.format("Scanning target %s failed for an unknown reason.", target.targetPath));
                }
                if (output.getScanExitCode().isPresent()) {
                    anyExitCodeIs64 = anyExitCodeIs64 || output.getScanExitCode().get() == 64;
                }
            } else {
                scanStatus = StatusType.SUCCESS;
                logger.info(String.format("%s was successfully scanned by the BlackDuck CLI.", target.targetPath));
            }
        }
        anyFailed = anyFailed || scanStatus == StatusType.FAILURE;
        eventSystem.publishEvent(Event.StatusSummary, new SignatureScanStatus(target.targetPath, scanStatus));
    }
    if (anyFailed) {
        eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_SCAN));
    }
    if (anyExitCodeIs64) {
        logger.error("");
        logger.error("Signature scanner returned 64. The most likely cause is you are using an unsupported version of Black Duck (<5.0.0).");
        logger.error("You should update your Black Duck or downgrade your version of detect.");
        logger.error("If you are using the detect scripts, you can use DETECT_LATEST_RELEASE_VERSION.");
        logger.error("");
        eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_BLACKDUCK_VERSION_NOT_SUPPORTED));
    }
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) LoggerFactory(org.slf4j.LoggerFactory) ScanTarget(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanTarget) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ArrayList(java.util.ArrayList) ScanBatchBuilder(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchBuilder) NameVersion(com.synopsys.integration.util.NameVersion) ExitCodeType(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType) Event(com.blackducksoftware.integration.hub.detect.workflow.event.Event) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) ScanBatchOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchOutput) DetectFileFinder(com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder) CodeLocationNameManager(com.blackducksoftware.integration.hub.detect.workflow.codelocation.CodeLocationNameManager) DetectProperty(com.blackducksoftware.integration.hub.detect.configuration.DetectProperty) Logger(org.slf4j.Logger) ExclusionPatternCreator(com.blackducksoftware.integration.hub.detect.workflow.hub.ExclusionPatternCreator) SignatureScanStatus(com.blackducksoftware.integration.hub.detect.workflow.status.SignatureScanStatus) SnippetMatching(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.SnippetMatching) ScanBatch(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch) Set(java.util.Set) IOException(java.io.IOException) EventSystem(com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem) ScanBatchRunner(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchRunner) StatusType(com.blackducksoftware.integration.hub.detect.workflow.status.StatusType) File(java.io.File) ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput) List(java.util.List) Optional(java.util.Optional) Result(com.synopsys.integration.blackduck.codelocation.Result) ExitCodeRequest(com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest) StatusType(com.blackducksoftware.integration.hub.detect.workflow.status.StatusType) ExitCodeRequest(com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest) ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput) SignatureScanStatus(com.blackducksoftware.integration.hub.detect.workflow.status.SignatureScanStatus)

Example 2 with StatusType

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

the class DetectorManager method runDetectors.

public DetectorToolResult runDetectors() throws DetectUserFriendlyException {
    List<DetectorEvaluation> detectorEvaluations = new ArrayList<>();
    // search
    SearchResult searchResult = searchManager.performSearch();
    eventSystem.publishEvent(Event.SearchCompleted, searchResult);
    detectorEvaluations.addAll(searchResult.getDetectorEvaluations());
    // prepare
    PreparationResult preparationResult = preparationManager.prepareExtractions(detectorEvaluations);
    eventSystem.publishEvent(Event.PreparationsCompleted, preparationResult);
    // extract
    ExtractionResult extractionResult = extractionManager.performExtractions(detectorEvaluations);
    eventSystem.publishEvent(Event.ExtractionsCompleted, extractionResult);
    // create results
    DetectorToolResult detectorToolResult = new DetectorToolResult();
    detectorToolResult.evaluatedDetectors = detectorEvaluations;
    detectorToolResult.bomToolCodeLocations = extractionResult.getDetectCodeLocations();
    detectorToolResult.applicableDetectorTypes = searchResult.getApplicableBomTools();
    detectorToolResult.failedDetectorTypes.addAll(preparationResult.getFailedBomToolTypes());
    detectorToolResult.failedDetectorTypes.addAll(extractionResult.getFailedBomToolTypes());
    detectorToolResult.succesfullDetectorTypes.addAll(preparationResult.getSuccessfulBomToolTypes());
    detectorToolResult.succesfullDetectorTypes.addAll(extractionResult.getSuccessfulBomToolTypes());
    detectorToolResult.succesfullDetectorTypes.removeIf(it -> detectorToolResult.failedDetectorTypes.contains(it));
    // post status
    Map<DetectorType, StatusType> detectorStatus = new HashMap<>();
    detectorToolResult.succesfullDetectorTypes.forEach(it -> detectorStatus.put(it, StatusType.SUCCESS));
    detectorToolResult.failedDetectorTypes.forEach(it -> detectorStatus.put(it, StatusType.FAILURE));
    detectorStatus.forEach((detector, status) -> eventSystem.publishEvent(Event.StatusSummary, new DetectorStatus(detector, status)));
    return detectorToolResult;
}
Also used : DetectorToolResult(com.blackducksoftware.integration.hub.detect.tool.detector.DetectorToolResult) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) DetectorStatus(com.blackducksoftware.integration.hub.detect.workflow.status.DetectorStatus) PreparationResult(com.blackducksoftware.integration.hub.detect.workflow.extraction.PreparationResult) HashMap(java.util.HashMap) StatusType(com.blackducksoftware.integration.hub.detect.workflow.status.StatusType) ArrayList(java.util.ArrayList) SearchResult(com.blackducksoftware.integration.hub.detect.workflow.search.SearchResult) ExtractionResult(com.blackducksoftware.integration.hub.detect.workflow.extraction.ExtractionResult) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)

Aggregations

StatusType (com.blackducksoftware.integration.hub.detect.workflow.status.StatusType)2 ArrayList (java.util.ArrayList)2 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)1 DetectorType (com.blackducksoftware.integration.hub.detect.detector.DetectorType)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ExitCodeType (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeType)1 ExitCodeRequest (com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest)1 DetectorToolResult (com.blackducksoftware.integration.hub.detect.tool.detector.DetectorToolResult)1 CodeLocationNameManager (com.blackducksoftware.integration.hub.detect.workflow.codelocation.CodeLocationNameManager)1 Event (com.blackducksoftware.integration.hub.detect.workflow.event.Event)1 EventSystem (com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem)1 ExtractionResult (com.blackducksoftware.integration.hub.detect.workflow.extraction.ExtractionResult)1 PreparationResult (com.blackducksoftware.integration.hub.detect.workflow.extraction.PreparationResult)1 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)1 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)1 ExclusionPatternCreator (com.blackducksoftware.integration.hub.detect.workflow.hub.ExclusionPatternCreator)1 SearchResult (com.blackducksoftware.integration.hub.detect.workflow.search.SearchResult)1 DetectorEvaluation (com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation)1 DetectorStatus (com.blackducksoftware.integration.hub.detect.workflow.status.DetectorStatus)1 SignatureScanStatus (com.blackducksoftware.integration.hub.detect.workflow.status.SignatureScanStatus)1