Search in sources :

Example 1 with SignatureScannerReport

use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport in project synopsys-detect by blackducksoftware.

the class CreateSignatureScanReports method createReports.

public List<SignatureScannerReport> createReports(List<SignatureScanPath> signatureScanPaths, List<ScanCommandOutput> scanCommandOutputList) {
    List<SignatureScannerReport> signatureScannerReports = new ArrayList<>();
    for (SignatureScanPath signatureScanPath : signatureScanPaths) {
        Optional<ScanCommandOutput> scanCommandOutput = scanCommandOutputList.stream().filter(output -> output.getScanTarget().equals(signatureScanPath.getTargetCanonicalPath())).findFirst();
        SignatureScannerReport signatureScannerReport = createReport(signatureScanPath, scanCommandOutput.orElse(null));
        signatureScannerReports.add(signatureScannerReport);
    }
    return signatureScannerReports;
}
Also used : ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Logger(org.slf4j.Logger) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) Result(com.synopsys.integration.blackduck.codelocation.Result) SignatureScanStatusType(com.synopsys.integration.detect.tool.signaturescanner.enums.SignatureScanStatusType) CodeLocationOutput(com.synopsys.integration.blackduck.codelocation.CodeLocationOutput) ArrayList(java.util.ArrayList) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) ArrayList(java.util.ArrayList) ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)

Example 2 with SignatureScannerReport

use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport in project synopsys-detect by blackducksoftware.

the class CreateSignatureScanReports method createReport.

public static SignatureScannerReport createReport(SignatureScanPath signatureScanPath, @Nullable ScanCommandOutput scanCommandOutput) {
    SignatureScanStatusType statusType;
    if (scanCommandOutput == null) {
        statusType = SignatureScanStatusType.FAILURE;
    } else if (scanCommandOutput.getScanExitCode().isPresent() && scanCommandOutput.getScanExitCode().get() == 2) {
        statusType = SignatureScanStatusType.SKIPPED;
    } else if (Result.FAILURE.equals(scanCommandOutput.getResult())) {
        statusType = SignatureScanStatusType.FAILURE;
    } else {
        statusType = SignatureScanStatusType.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);
    String codeLocationName = optionalOutput.map(CodeLocationOutput::getCodeLocationName).orElse(null);
    Integer notificationCounts = optionalOutput.map(CodeLocationOutput::getExpectedNotificationCount).orElse(null);
    return new SignatureScannerReport(signatureScanPath, statusType, exitCode, exception, errorMessage, hasOutput, codeLocationName, notificationCounts);
}
Also used : Optional(java.util.Optional) SignatureScanStatusType(com.synopsys.integration.detect.tool.signaturescanner.enums.SignatureScanStatusType) ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)

Example 3 with SignatureScannerReport

use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport in project synopsys-detect by blackducksoftware.

the class PublishSignatureScanReports method publishReport.

private void publishReport(SignatureScannerReport signatureScannerReport) {
    if (signatureScannerReport.isSuccessful() || (signatureScannerReport.isSkipped() && treatSkippedScanAsSuccess)) {
        statusEventPublisher.publishStatusSummary(new SignatureScanStatus(signatureScannerReport.getSignatureScanPath().getTargetCanonicalPath(), StatusType.SUCCESS));
        return;
    }
    String scanTargetPath = signatureScannerReport.getSignatureScanPath().getTargetCanonicalPath();
    if (signatureScannerReport.isSkipped()) {
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.SIGNATURE_SCANNER, String.format("Scanning target %s was never scanned by the BlackDuck CLI.", scanTargetPath), Arrays.asList("The minimum scan interval was not met and this scan was skipped by the BlackDuck CLI.")));
    } else if (!signatureScannerReport.hasOutput()) {
        String errorMessage = String.format("Scanning target %s was never scanned by the BlackDuck CLI.", scanTargetPath);
        logger.info(errorMessage);
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.SIGNATURE_SCANNER, "Black Duck Signature Scanner", Arrays.asList(errorMessage)));
    } else {
        String errorMessage = signatureScannerReport.getErrorMessage().map(message -> String.format("Scanning target %s failed: %s", scanTargetPath, message)).orElse(String.format("Scanning target %s failed for an unknown reason.", scanTargetPath));
        logger.error(errorMessage);
        signatureScannerReport.getException().ifPresent(exception -> logger.debug(errorMessage, exception));
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.SIGNATURE_SCANNER, "Black Duck Signature Scanner", Arrays.asList(errorMessage)));
    }
    statusEventPublisher.publishStatusSummary(new SignatureScanStatus(signatureScannerReport.getSignatureScanPath().getTargetCanonicalPath(), StatusType.FAILURE));
}
Also used : ExitCodeType(com.synopsys.integration.detect.configuration.enumeration.ExitCodeType) Arrays(java.util.Arrays) StatusEventPublisher(com.synopsys.integration.detect.workflow.status.StatusEventPublisher) Logger(org.slf4j.Logger) DetectIssue(com.synopsys.integration.detect.workflow.status.DetectIssue) LoggerFactory(org.slf4j.LoggerFactory) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport) StatusType(com.synopsys.integration.detect.workflow.status.StatusType) List(java.util.List) DetectIssueType(com.synopsys.integration.detect.workflow.status.DetectIssueType) SignatureScanStatus(com.synopsys.integration.detect.workflow.status.SignatureScanStatus) ExitCodePublisher(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher) ExitCodeRequest(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest) DetectIssue(com.synopsys.integration.detect.workflow.status.DetectIssue) SignatureScanStatus(com.synopsys.integration.detect.workflow.status.SignatureScanStatus)

Example 4 with SignatureScannerReport

use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport in project synopsys-detect by blackducksoftware.

the class SignatureScanStepRunner method executeScan.

private List<SignatureScannerReport> executeScan(ScanBatch scanBatch, ScanBatchRunner scanBatchRunner, List<SignatureScanPath> scanPaths) throws OperationException {
    SignatureScanOuputResult scanOuputResult = operationFactory.signatureScan(scanBatch, scanBatchRunner);
    List<SignatureScannerReport> reports = operationFactory.createSignatureScanReport(scanPaths, scanOuputResult.getScanBatchOutput().getOutputs());
    operationFactory.publishSignatureScanReport(reports);
    return reports;
}
Also used : SignatureScanOuputResult(com.synopsys.integration.detect.tool.signaturescanner.operation.SignatureScanOuputResult) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)

Example 5 with SignatureScannerReport

use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport in project synopsys-detect by blackducksoftware.

the class SignatureScanStepRunner method runSignatureScannerOnline.

public SignatureScannerCodeLocationResult runSignatureScannerOnline(BlackDuckRunData blackDuckRunData, NameVersion projectNameVersion, DockerTargetData dockerTargetData) throws DetectUserFriendlyException, OperationException {
    ScanBatchRunner scanBatchRunner = resolveOnlineScanBatchRunner(blackDuckRunData);
    List<SignatureScanPath> scanPaths = operationFactory.createScanPaths(projectNameVersion, dockerTargetData);
    ScanBatch scanBatch = operationFactory.createScanBatchOnline(scanPaths, projectNameVersion, dockerTargetData, blackDuckRunData);
    NotificationTaskRange notificationTaskRange = operationFactory.createCodeLocationRange(blackDuckRunData);
    List<SignatureScannerReport> reports = executeScan(scanBatch, scanBatchRunner, scanPaths);
    return operationFactory.calculateWaitableSignatureScannerCodeLocations(notificationTaskRange, reports);
}
Also used : ScanBatchRunner(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchRunner) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) ScanBatch(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch) NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)

Aggregations

SignatureScannerReport (com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)7 List (java.util.List)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ScanCommandOutput (com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput)3 SignatureScanPath (com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath)3 Optional (java.util.Optional)3 ExitCodeType (com.synopsys.integration.detect.configuration.enumeration.ExitCodeType)2 ExitCodePublisher (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher)2 ExitCodeRequest (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest)2 SignatureScanStatusType (com.synopsys.integration.detect.tool.signaturescanner.enums.SignatureScanStatusType)2 DetectIssue (com.synopsys.integration.detect.workflow.status.DetectIssue)2 DetectIssueType (com.synopsys.integration.detect.workflow.status.DetectIssueType)2 SignatureScanStatus (com.synopsys.integration.detect.workflow.status.SignatureScanStatus)2 StatusEventPublisher (com.synopsys.integration.detect.workflow.status.StatusEventPublisher)2 StatusType (com.synopsys.integration.detect.workflow.status.StatusType)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 CodeLocationOutput (com.synopsys.integration.blackduck.codelocation.CodeLocationOutput)1 Result (com.synopsys.integration.blackduck.codelocation.Result)1