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);
}
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));
}
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));
}
}
}
Aggregations