Search in sources :

Example 1 with ScanCommandOutput

use of com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput in project hub-detect by blackducksoftware.

the class BlackDuckSignatureScanner method scanPaths.

private ScanBatchOutput scanPaths(final NameVersion projectNameVersion, File installDirectory, File dockerTarFile) throws IntegrationException, InterruptedException, IOException {
    List<SignatureScanPath> signatureScanPaths = determinePathsAndExclusions(projectNameVersion, signatureScannerOptions.getMaxDepth(), dockerTarFile);
    final ScanBatch scanJob = createScanBatch(projectNameVersion, installDirectory, signatureScanPaths, dockerTarFile);
    List<ScanCommandOutput> scanCommandOutputs = new ArrayList<>();
    final ScanBatchOutput scanJobOutput = scanJobManager.executeScans(scanJob);
    if (scanJobOutput.getOutputs() != null) {
        for (ScanCommandOutput scanCommandOutput : scanJobOutput.getOutputs()) {
            scanCommandOutputs.add(scanCommandOutput);
        }
    }
    reportResults(signatureScanPaths, scanCommandOutputs);
    return scanJobOutput;
}
Also used : ScanBatch(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch) ArrayList(java.util.ArrayList) ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput) ScanBatchOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchOutput)

Example 2 with ScanCommandOutput

use of com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput 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)

Aggregations

ScanBatch (com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch)2 ScanBatchOutput (com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchOutput)2 ScanCommandOutput (com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput)2 ArrayList (java.util.ArrayList)2 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)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 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 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 SignatureScanStatus (com.blackducksoftware.integration.hub.detect.workflow.status.SignatureScanStatus)1 StatusType (com.blackducksoftware.integration.hub.detect.workflow.status.StatusType)1 Result (com.synopsys.integration.blackduck.codelocation.Result)1 ScanBatchBuilder (com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchBuilder)1 ScanBatchRunner (com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchRunner)1 ScanTarget (com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanTarget)1