|
32 | 32 | import com.blackduck.integration.detect.configuration.enumeration.RapidCompareMode;
|
33 | 33 | import com.blackduck.integration.detect.lifecycle.run.step.CommonScanStepRunner;
|
34 | 34 | import com.blackduck.integration.detect.workflow.blackduck.report.ReportData;
|
| 35 | +import com.blackduck.integration.rest.exception.IntegrationRestException; |
35 | 36 | import org.apache.commons.codec.digest.DigestUtils;
|
36 | 37 | import org.apache.commons.lang3.StringUtils;
|
| 38 | +import org.apache.http.HttpStatus; |
37 | 39 | import org.apache.http.entity.ContentType;
|
38 | 40 | import org.jetbrains.annotations.Nullable;
|
39 | 41 | import org.slf4j.Logger;
|
|
69 | 71 | import com.blackduck.integration.componentlocator.beans.Component;
|
70 | 72 | import com.blackduck.integration.detect.configuration.DetectConfigurationFactory;
|
71 | 73 | import com.blackduck.integration.detect.configuration.DetectInfo;
|
72 |
| -import com.blackduck.integration.detect.configuration.DetectProperties; |
73 | 74 | import com.blackduck.integration.detect.configuration.DetectUserFriendlyException;
|
74 | 75 | import com.blackduck.integration.detect.configuration.DetectorToolOptions;
|
75 | 76 | import com.blackduck.integration.detect.configuration.connection.ConnectionFactory;
|
|
90 | 91 | import com.blackduck.integration.detect.lifecycle.run.step.utility.OperationAuditLog;
|
91 | 92 | import com.blackduck.integration.detect.lifecycle.run.step.utility.OperationWrapper;
|
92 | 93 | import com.blackduck.integration.detect.lifecycle.shutdown.ExitCodePublisher;
|
93 |
| -import com.blackduck.integration.detect.lifecycle.shutdown.ExitCodeRequest; |
94 | 94 | import com.blackduck.integration.detect.tool.DetectableTool;
|
95 | 95 | import com.blackduck.integration.detect.tool.DetectableToolResult;
|
96 | 96 | import com.blackduck.integration.detect.tool.binaryscanner.BinaryScanFindMultipleTargetsOperation;
|
|
183 | 183 | import com.blackduck.integration.detect.workflow.componentlocationanalysis.BdioToComponentListTransformer;
|
184 | 184 | import com.blackduck.integration.detect.workflow.componentlocationanalysis.GenerateComponentLocationAnalysisOperation;
|
185 | 185 | import com.blackduck.integration.detect.workflow.componentlocationanalysis.ScanResultToComponentListTransformer;
|
186 |
| -import com.blackduck.integration.detect.workflow.event.Event; |
187 | 186 | import com.blackduck.integration.detect.workflow.event.EventSystem;
|
188 | 187 | import com.blackduck.integration.detect.workflow.file.DirectoryManager;
|
189 | 188 | import com.blackduck.integration.detect.workflow.phonehome.PhoneHomeManager;
|
@@ -713,38 +712,55 @@ public List<DeveloperScansScanView> waitForRapidResults(BlackDuckRunData blackDu
|
713 | 712 | return auditLog.namedInternal("Rapid Wait", () -> {
|
714 | 713 | BlackDuckServicesFactory blackDuckServicesFactory = blackDuckRunData.getBlackDuckServicesFactory();
|
715 | 714 | int fibonacciSequenceIndex = getFibonacciSequenceIndex();
|
716 |
| - return new RapidModeWaitOperation(blackDuckServicesFactory.getBlackDuckApiClient()).waitForScans( |
717 |
| - rapidScans, |
718 |
| - detectConfigurationFactory.findTimeoutInSeconds(), |
719 |
| - RapidModeWaitOperation.DEFAULT_WAIT_INTERVAL_IN_SECONDS, |
720 |
| - mode, |
721 |
| - calculateMaxWaitInSeconds(fibonacciSequenceIndex) |
722 |
| - ); |
| 715 | + |
| 716 | + try { |
| 717 | + return new RapidModeWaitOperation(blackDuckServicesFactory.getBlackDuckApiClient()).waitForScans( |
| 718 | + rapidScans, |
| 719 | + detectConfigurationFactory.findTimeoutInSeconds(), |
| 720 | + RapidModeWaitOperation.DEFAULT_WAIT_INTERVAL_IN_SECONDS, |
| 721 | + mode, |
| 722 | + calculateMaxWaitInSeconds(fibonacciSequenceIndex) |
| 723 | + ); |
| 724 | + } catch (IntegrationRestException e) { |
| 725 | + throw handleRapidScanException(e); |
| 726 | + } catch (Exception e) { |
| 727 | + logger.error("Exception while waiting for rapid results: {}", e.getMessage(), e); |
| 728 | + throw new OperationException(e); |
| 729 | + } |
723 | 730 | });
|
724 | 731 | }
|
725 | 732 |
|
726 |
| - public static boolean shouldSkipResolvedPolicies(DeveloperScansScanView resultView, RapidCompareMode rapidCompareMode) { |
727 |
| - if (resultView.getPolicyStatuses() == null || resultView.getPolicyStatuses().isEmpty()) { |
728 |
| - return false; |
| 733 | + private OperationException handleRapidScanException(IntegrationRestException e) { |
| 734 | + RapidCompareMode rapidCompareMode = detectConfigurationFactory.createRapidScanOptions().getCompareMode(); |
| 735 | + |
| 736 | + if (isBomCompareError(e, rapidCompareMode)) { |
| 737 | + String enhancedMessage = createBomCompareErrorMessage(e.getMessage()); |
| 738 | + logger.error("Rapid scan failed. {}", enhancedMessage); |
| 739 | + return new OperationException(new IntegrationRestException( |
| 740 | + e.getHttpMethod(), e.getHttpUrl(), e.getHttpStatusCode(), |
| 741 | + e.getHttpStatusMessage(), e.getHttpResponseContent(), enhancedMessage)); |
729 | 742 | }
|
730 |
| - return (RapidCompareMode.BOM_COMPARE.equals(rapidCompareMode) || RapidCompareMode.BOM_COMPARE_STRICT.equals(rapidCompareMode)) |
731 |
| - && resultView.getPolicyStatuses().stream().allMatch(POLICY_STATUS_RESOLVED::equalsIgnoreCase); |
| 743 | + |
| 744 | + logger.error("Rapid scan failed. {}", e.getMessage()); |
| 745 | + return new OperationException(e); |
732 | 746 | }
|
733 | 747 |
|
734 |
| - public static List<DeveloperScansScanView> filterUnresolvedPolicyResults(List<DeveloperScansScanView> scanResults, RapidCompareMode rapidCompareMode) { |
735 |
| - return scanResults.stream() |
736 |
| - .filter(resultView -> !shouldSkipResolvedPolicies(resultView, rapidCompareMode)) |
737 |
| - .collect(Collectors.toList()); |
| 748 | + private boolean isBomCompareError(IntegrationRestException e, RapidCompareMode rapidCompareMode) { |
| 749 | + return HttpStatus.SC_BAD_REQUEST == e.getHttpStatusCode() && |
| 750 | + (RapidCompareMode.BOM_COMPARE.equals(rapidCompareMode) || |
| 751 | + RapidCompareMode.BOM_COMPARE_STRICT.equals(rapidCompareMode)); |
738 | 752 | }
|
739 | 753 |
|
740 |
| - public final RapidScanResultSummary logRapidReport(List<DeveloperScansScanView> scanResults, BlackduckScanMode mode) throws OperationException { |
741 |
| - RapidScanOptions rapidScanOptions = detectConfigurationFactory.createRapidScanOptions(); |
742 |
| - List<PolicyRuleSeverityType> severitiesToFailPolicyCheck = rapidScanOptions.getSeveritiesToFailPolicyCheck(); |
743 |
| - RapidCompareMode rapidCompareMode = rapidScanOptions.getCompareMode(); |
744 |
| - List<DeveloperScansScanView> filteredResults = filterUnresolvedPolicyResults(scanResults, rapidCompareMode); |
| 754 | + private String createBomCompareErrorMessage(String originalMessage) { |
| 755 | + return originalMessage + " BOM_COMPARE mode requires the target project version to exist in Black Duck Hub. " + |
| 756 | + "Please ensure 'detect.project.version.name' matches an existing project version. " + |
| 757 | + "Consider running a full scan first if the version hasn't been uploaded yet."; |
| 758 | + } |
745 | 759 |
|
746 |
| - return auditLog.namedInternal("Print Rapid Mode Results", () -> |
747 |
| - new RapidModeLogReportOperation(exitCodePublisher, rapidScanResultAggregator, mode).perform(filteredResults, severitiesToFailPolicyCheck)); |
| 760 | + public final RapidScanResultSummary logRapidReport(List<DeveloperScansScanView> scanResults, BlackduckScanMode mode) throws OperationException { |
| 761 | + List<PolicyRuleSeverityType> severitiesToFailPolicyCheck = detectConfigurationFactory.createRapidScanOptions().getSeveritiesToFailPolicyCheck(); |
| 762 | + return auditLog.namedInternal("Print Rapid Mode Results", () -> |
| 763 | + new RapidModeLogReportOperation(exitCodePublisher, rapidScanResultAggregator, mode).perform(scanResults, severitiesToFailPolicyCheck)); |
748 | 764 | }
|
749 | 765 |
|
750 | 766 | public final File generateRapidJsonFile(NameVersion projectNameVersion, List<DeveloperScansScanView> scanResults) throws OperationException {
|
@@ -776,7 +792,6 @@ private void failComponentLocationAnalysisOperationTask(String reason) throws Op
|
776 | 792 | /**
|
777 | 793 | * Given a BDIO, creates a JSON file called {@value GenerateComponentLocationAnalysisOperation#DETECT_OUTPUT_FILE_NAME} containing
|
778 | 794 | * every detected component's {@link ExternalId} along with its declaration location when applicable.
|
779 |
| - * |
780 | 795 | * @param bdio
|
781 | 796 | * @throws OperationException
|
782 | 797 | */
|
@@ -808,7 +823,6 @@ public void generateComponentLocationAnalysisIfEnabled(BdioResult bdio) throws O
|
808 | 823 | /**
|
809 | 824 | * Given a Rapid/Stateless Detector Scan result, creates a JSON file called {@value GenerateComponentLocationAnalysisOperation#DETECT_OUTPUT_FILE_NAME} containing
|
810 | 825 | * every reported component's {@link ExternalId} along with its declaration location and upgrade guidance information when applicable.
|
811 |
| - * |
812 | 826 | * @param rapidResults
|
813 | 827 | * @param bdio
|
814 | 828 | * @throws OperationException
|
@@ -859,7 +873,6 @@ private Set<String> getApplicableDetectorTypesAsStrings(Set<DetectorType> applic
|
859 | 873 | /**
|
860 | 874 | * Since component location analysis is not supported for online Intelligent scans in 8.11, an appropriate console
|
861 | 875 | * msg is logged and status=FAILURE is recorded in the status.json file
|
862 |
| - * |
863 | 876 | * @throws OperationException
|
864 | 877 | */
|
865 | 878 | public void attemptToGenerateComponentLocationAnalysisIfEnabled() throws OperationException {
|
|
0 commit comments