use of com.blackducksoftware.integration.hub.service.ReportService in project hub-detect by blackducksoftware.
the class HubManager method performPostHubActions.
public void performPostHubActions(final DetectProject detectProject, final ProjectVersionView projectVersionView) throws DetectUserFriendlyException {
try {
if (detectConfiguration.getPolicyCheck() || detectConfiguration.getRiskReportPdf() || detectConfiguration.getNoticesReport()) {
final ProjectService projectService = hubServiceWrapper.createProjectService();
final ScanStatusService scanStatusService = hubServiceWrapper.createScanStatusService();
waitForBomUpdate(hubServiceWrapper.createHubService(), scanStatusService, projectVersionView);
if (detectConfiguration.getPolicyCheck()) {
final PolicyStatusDescription policyStatusDescription = policyChecker.getPolicyStatus(projectService, projectVersionView);
logger.info(policyStatusDescription.getPolicyStatusMessage());
if (policyChecker.policyViolated(policyStatusDescription)) {
exitCodeType = ExitCodeType.FAILURE_POLICY_VIOLATION;
}
}
if (detectConfiguration.getRiskReportPdf()) {
final ReportService reportService = hubServiceWrapper.createReportService();
logger.info("Creating risk report pdf");
final File pdfFile = reportService.createReportPdfFile(new File(detectConfiguration.getRiskReportPdfOutputDirectory()), detectProject.getProjectName(), detectProject.getProjectVersionName());
logger.info(String.format("Created risk report pdf : %s", pdfFile.getCanonicalPath()));
}
if (detectConfiguration.getNoticesReport()) {
final ReportService reportService = hubServiceWrapper.createReportService();
logger.info("Creating notices report");
final File noticesFile = reportService.createNoticesReportFile(new File(detectConfiguration.getNoticesReportOutputDirectory()), detectProject.getProjectName(), detectProject.getProjectVersionName());
if (noticesFile != null) {
logger.info(String.format("Created notices report : %s", noticesFile.getCanonicalPath()));
}
}
}
if (null != detectProject.getDetectCodeLocations() && !detectProject.getDetectCodeLocations().isEmpty() && !detectConfiguration.getHubSignatureScannerDisabled()) {
// only log BOM URL if we have updated it in some way
final ProjectService projectService = hubServiceWrapper.createProjectService();
final HubService hubService = hubServiceWrapper.createHubService();
final ProjectVersionWrapper projectVersionWrapper = projectService.getProjectVersion(detectProject.getProjectName(), detectProject.getProjectVersionName());
final String componentsLink = hubService.getFirstLinkSafely(projectVersionWrapper.getProjectVersionView(), ProjectVersionView.COMPONENTS_LINK);
logger.info(String.format("To see your results, follow the URL: %s", componentsLink));
} else {
logger.debug("Found no code locations and did not run a scan.");
}
} catch (final IllegalStateException e) {
throw new DetectUserFriendlyException(String.format("Your Hub 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 HubTimeoutExceededException 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