use of com.synopsys.integration.blackduck.codelocation.CodeLocationWaitResult in project hub-detect by blackducksoftware.
the class BlackduckPostActions method perform.
public void perform(BlackduckReportOptions blackduckReportOptions, PolicyCheckOptions policyCheckOptions, CodeLocationWaitData codeLocationWaitData, ProjectVersionWrapper projectVersionWrapper, long timeoutInSeconds) throws DetectUserFriendlyException {
try {
ProjectView projectView = projectVersionWrapper.getProjectView();
ProjectVersionView projectVersionView = projectVersionWrapper.getProjectVersionView();
if (policyCheckOptions.shouldPerformPolicyCheck() || blackduckReportOptions.shouldGenerateAnyReport()) {
logger.info("Detect must wait for bom tool calculations to finish.");
CodeLocationCreationService codeLocationCreationService = blackDuckServicesFactory.createCodeLocationCreationService();
List<CodeLocationWaitResult> results = new ArrayList<>();
if (codeLocationWaitData.hasBdioResults()) {
CodeLocationWaitResult result = codeLocationCreationService.waitForCodeLocations(codeLocationWaitData.getBdioUploadRange(), codeLocationWaitData.getBdioUploadCodeLocationNames(), timeoutInSeconds);
results.add(result);
}
if (codeLocationWaitData.hasScanResults()) {
CodeLocationWaitResult result = codeLocationCreationService.waitForCodeLocations(codeLocationWaitData.getSignatureScanRange(), codeLocationWaitData.getSignatureScanCodeLocationNames(), timeoutInSeconds);
results.add(result);
}
if (codeLocationWaitData.hasBinaryScanResults()) {
CodeLocationWaitResult result = codeLocationCreationService.waitForCodeLocations(codeLocationWaitData.getBinaryScanRange(), codeLocationWaitData.getBinaryScanCodeLocationNames(), timeoutInSeconds);
results.add(result);
}
for (CodeLocationWaitResult result : results) {
if (result.getStatus() == CodeLocationWaitResult.Status.PARTIAL) {
throw new DetectUserFriendlyException(result.getErrorMessage().orElse("Timed out waiting for code locations to finish on the Black Duck server."), ExitCodeType.FAILURE_TIMEOUT);
}
}
}
if (policyCheckOptions.shouldPerformPolicyCheck()) {
logger.info("Detect will check policy for violations.");
PolicyChecker policyChecker = new PolicyChecker(eventSystem);
policyChecker.checkPolicy(policyCheckOptions.getSeveritiesToFailPolicyCheck(), blackDuckServicesFactory.createProjectService(), projectVersionView);
}
if (blackduckReportOptions.shouldGenerateAnyReport()) {
ReportService reportService = blackDuckServicesFactory.createReportService(timeoutInSeconds);
if (blackduckReportOptions.shouldGenerateRiskReport()) {
logger.info("Creating risk report pdf");
File reportDirectory = new File(blackduckReportOptions.getRiskReportPdfPath());
File createdPdf = reportService.createReportPdfFile(reportDirectory, projectView, projectVersionView);
logger.info(String.format("Created risk report pdf: %s", createdPdf.getCanonicalPath()));
}
if (blackduckReportOptions.shouldGenerateNoticesReport()) {
logger.info("Creating notices report");
File noticesDirectory = new File(blackduckReportOptions.getNoticesReportPath());
final File noticesFile = reportService.createNoticesReportFile(noticesDirectory, projectView, projectVersionView);
logger.info(String.format("Created notices report: %s", noticesFile.getCanonicalPath()));
}
}
} catch (final DetectUserFriendlyException e) {
throw e;
} catch (final IllegalArgumentException e) {
throw new DetectUserFriendlyException(String.format("Your Black Duck configuration is not valid: %s", e.getMessage()), e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
} catch (final IntegrationRestException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
} catch (final BlackDuckTimeoutExceededException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_TIMEOUT);
} catch (final Exception e) {
throw new DetectUserFriendlyException(String.format("There was a problem: %s", e.getMessage()), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
Aggregations