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