Search in sources :

Example 1 with ReportService

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);
    }
}
Also used : PolicyStatusDescription(com.blackducksoftware.integration.hub.service.model.PolicyStatusDescription) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) DoesNotExistException(com.blackducksoftware.integration.hub.exception.DoesNotExistException) HubTimeoutExceededException(com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ReportService(com.blackducksoftware.integration.hub.service.ReportService) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ScanStatusService(com.blackducksoftware.integration.hub.service.ScanStatusService) HubTimeoutExceededException(com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException) File(java.io.File) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper) HubService(com.blackducksoftware.integration.hub.service.HubService)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 DoesNotExistException (com.blackducksoftware.integration.hub.exception.DoesNotExistException)1 HubTimeoutExceededException (com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException)1 IntegrationRestException (com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException)1 HubService (com.blackducksoftware.integration.hub.service.HubService)1 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)1 ReportService (com.blackducksoftware.integration.hub.service.ReportService)1 ScanStatusService (com.blackducksoftware.integration.hub.service.ScanStatusService)1 PolicyStatusDescription (com.blackducksoftware.integration.hub.service.model.PolicyStatusDescription)1 ProjectVersionWrapper (com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)1 File (java.io.File)1