Search in sources :

Example 1 with BlackDuckTimeoutExceededException

use of com.synopsys.integration.blackduck.exception.BlackDuckTimeoutExceededException 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);
    }
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) CodeLocationCreationService(com.synopsys.integration.blackduck.codelocation.CodeLocationCreationService) CodeLocationWaitResult(com.synopsys.integration.blackduck.codelocation.CodeLocationWaitResult) BlackDuckTimeoutExceededException(com.synopsys.integration.blackduck.exception.BlackDuckTimeoutExceededException) ArrayList(java.util.ArrayList) BlackDuckTimeoutExceededException(com.synopsys.integration.blackduck.exception.BlackDuckTimeoutExceededException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ReportService(com.synopsys.integration.blackduck.service.ReportService) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) File(java.io.File)

Aggregations

DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)1 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)1 CodeLocationCreationService (com.synopsys.integration.blackduck.codelocation.CodeLocationCreationService)1 CodeLocationWaitResult (com.synopsys.integration.blackduck.codelocation.CodeLocationWaitResult)1 BlackDuckTimeoutExceededException (com.synopsys.integration.blackduck.exception.BlackDuckTimeoutExceededException)1 ReportService (com.synopsys.integration.blackduck.service.ReportService)1 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1