Search in sources :

Example 1 with DetectIssue

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

the class DetectableTool method extract.

public DetectableToolResult extract() {
    // TODO: Move docker/bazel out of detectable and drop this notion of a detctable tool. Will simplify this logic and make this unneccessary.
    DetectableResult extractable;
    try {
        extractable = detectable.extractable();
    } catch (DetectableException e) {
        extractable = new ExceptionDetectableResult(e);
    }
    if (!extractable.getPassed()) {
        logger.error(String.format("Was not extractable: %s", extractable.toDescription()));
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", Arrays.asList(extractable.toDescription())));
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
        exitCodePublisher.publishExitCode(ExitCodeType.FAILURE_GENERAL_ERROR, extractable.toDescription());
        return DetectableToolResult.failed(extractable);
    }
    logger.debug("Extractable passed.");
    ExtractionEnvironment extractionEnvironment = extractionEnvironmentProvider.createExtractionEnvironment(name);
    Extraction extraction;
    try {
        extraction = detectable.extract(extractionEnvironment);
    } catch (ExecutableFailedException | ExecutableRunnerException | JsonSyntaxException | IOException | CycleDetectedException | DetectableException | MissingExternalIdException | ParserConfigurationException | SAXException e) {
        extraction = new Extraction.Builder().exception(e).build();
    }
    if (!extraction.isSuccess()) {
        logger.error("Extraction was not success.");
        List<String> errorMessages = collectErrorMessages(extraction);
        statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTABLE_TOOL, "Detectable Tool Issue", errorMessages));
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.FAILURE));
        exitCodePublisher.publishExitCode(new ExitCodeRequest(ExitCodeType.FAILURE_GENERAL_ERROR, extraction.getDescription()));
        return DetectableToolResult.failed();
    } else {
        logger.debug("Extraction success.");
        statusEventPublisher.publishStatusSummary(new Status(name, StatusType.SUCCESS));
    }
    Map<CodeLocation, DetectCodeLocation> detectCodeLocationMap = codeLocationConverter.toDetectCodeLocation(sourcePath, extraction, sourcePath, name);
    List<DetectCodeLocation> detectCodeLocations = new ArrayList<>(detectCodeLocationMap.values());
    DockerTargetData dockerTargetData = DockerTargetData.fromExtraction(extraction);
    DetectToolProjectInfo projectInfo = null;
    if (StringUtils.isNotBlank(extraction.getProjectName()) || StringUtils.isNotBlank(extraction.getProjectVersion())) {
        NameVersion nameVersion = new NameVersion(extraction.getProjectName(), extraction.getProjectVersion());
        projectInfo = new DetectToolProjectInfo(detectTool, nameVersion);
    }
    logger.debug("Tool finished.");
    return DetectableToolResult.success(detectCodeLocations, projectInfo, dockerTargetData);
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) NameVersion(com.synopsys.integration.util.NameVersion) CycleDetectedException(com.synopsys.integration.detectable.util.CycleDetectedException) ArrayList(java.util.ArrayList) SAXException(org.xml.sax.SAXException) DetectIssue(com.synopsys.integration.detect.workflow.status.DetectIssue) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Extraction(com.synopsys.integration.detectable.extraction.Extraction) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DockerTargetData(com.synopsys.integration.detect.lifecycle.run.data.DockerTargetData) Status(com.synopsys.integration.detect.workflow.status.Status) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ExitCodeRequest(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest) IOException(java.io.IOException) MissingExternalIdException(com.synopsys.integration.bdio.graph.builder.MissingExternalIdException) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) JsonSyntaxException(com.google.gson.JsonSyntaxException) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) ExceptionDetectableResult(com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult) ExceptionDetectableResult(com.synopsys.integration.detectable.detectable.result.ExceptionDetectableResult) DetectToolProjectInfo(com.synopsys.integration.detect.workflow.project.DetectToolProjectInfo) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException)

Example 2 with DetectIssue

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

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

the class DetectorIssuePublisher method publishEvents.

private void publishEvents(StatusEventPublisher statusEventPublisher, List<DetectorEvaluationTree> trees) {
    String spacer = "\t";
    for (DetectorEvaluationTree tree : trees) {
        List<DetectorEvaluation> excepted = DetectorEvaluationUtils.filteredChildren(tree, DetectorEvaluation::wasExtractionException);
        List<DetectorEvaluation> failed = DetectorEvaluationUtils.filteredChildren(tree, DetectorEvaluation::wasExtractionFailure);
        List<DetectorEvaluation> notExtractable = DetectorEvaluationUtils.filteredChildren(tree, evaluation -> evaluation.isApplicable() && !evaluation.isExtractable());
        List<String> messages = new ArrayList<>();
        addIfNotEmpty(messages, "Not Extractable: ", spacer, notExtractable, DetectorEvaluation::getExtractabilityMessage);
        addIfNotEmpty(messages, "Failure: ", spacer, failed, detectorEvaluation -> detectorEvaluation.getExtraction().getDescription());
        addIfNotEmpty(messages, "Exception: ", spacer, excepted, detectorEvaluation -> ExceptionUtil.oneSentenceDescription(detectorEvaluation.getExtraction().getError()));
        if (messages.size() > 0) {
            messages.add(0, tree.getDirectory().toString());
            statusEventPublisher.publishIssue(new DetectIssue(DetectIssueType.DETECTOR, "Detector Issue", messages));
        }
    }
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectIssue(com.synopsys.integration.detect.workflow.status.DetectIssue) ArrayList(java.util.ArrayList) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation)

Aggregations

DetectIssue (com.synopsys.integration.detect.workflow.status.DetectIssue)3 ExitCodeRequest (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest)2 ArrayList (java.util.ArrayList)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 MissingExternalIdException (com.synopsys.integration.bdio.graph.builder.MissingExternalIdException)1 ExitCodeType (com.synopsys.integration.detect.configuration.enumeration.ExitCodeType)1 DockerTargetData (com.synopsys.integration.detect.lifecycle.run.data.DockerTargetData)1 ExitCodePublisher (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher)1 SignatureScannerReport (com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)1 DetectCodeLocation (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)1 DetectToolProjectInfo (com.synopsys.integration.detect.workflow.project.DetectToolProjectInfo)1 DetectIssueType (com.synopsys.integration.detect.workflow.status.DetectIssueType)1 SignatureScanStatus (com.synopsys.integration.detect.workflow.status.SignatureScanStatus)1 Status (com.synopsys.integration.detect.workflow.status.Status)1 StatusEventPublisher (com.synopsys.integration.detect.workflow.status.StatusEventPublisher)1 StatusType (com.synopsys.integration.detect.workflow.status.StatusType)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)1 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)1 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)1