Search in sources :

Example 1 with BdioResult

use of com.synopsys.integration.detect.workflow.bdio.BdioResult in project synopsys-detect by blackducksoftware.

the class UniversalStepRunner method generateAggregateBdio.

private BdioResult generateAggregateBdio(AggregateDecision aggregateDecision, UniversalToolsResult universalToolsResult, NameVersion projectNameVersion, String aggregateName) throws OperationException, DetectUserFriendlyException {
    DependencyGraph aggregateDependencyGraph;
    if (aggregateDecision.getAggregateMode() == AggregateMode.DIRECT) {
        aggregateDependencyGraph = operationFactory.aggregateDirect(universalToolsResult.getDetectCodeLocations());
    } else if (aggregateDecision.getAggregateMode() == AggregateMode.TRANSITIVE) {
        aggregateDependencyGraph = operationFactory.aggregateTransitive(universalToolsResult.getDetectCodeLocations());
    } else if (aggregateDecision.getAggregateMode() == AggregateMode.SUBPROJECT) {
        aggregateDependencyGraph = operationFactory.aggregateSubProject(universalToolsResult.getDetectCodeLocations());
    } else {
        throw new DetectUserFriendlyException(String.format("The %s property was set to an unsupported aggregation mode, will not aggregate at this time.", DetectProperties.DETECT_BOM_AGGREGATE_REMEDIATION_MODE.getKey()), ExitCodeType.FAILURE_GENERAL_ERROR);
    }
    boolean isBdio2 = operationFactory.calculateBdioOptions().isBdio2Enabled();
    String aggregateExtension = isBdio2 ? ".bdio" : ".jsonld";
    AggregateCodeLocation aggregateCodeLocation = operationFactory.createAggregateCodeLocation(aggregateDependencyGraph, projectNameVersion, aggregateName, aggregateExtension);
    if (isBdio2) {
        operationFactory.createAggregateBdio2File(aggregateCodeLocation);
    } else {
        operationFactory.createAggregateBdio1File(aggregateCodeLocation);
    }
    List<UploadTarget> uploadTargets = new ArrayList<>();
    Map<DetectCodeLocation, String> codeLocationNamesResult = new HashMap<>();
    universalToolsResult.getDetectCodeLocations().forEach(cl -> codeLocationNamesResult.put(cl, aggregateCodeLocation.getCodeLocationName()));
    // TODO: This doesn't seem right, it should just be the aggregate CL name right?
    if (aggregateCodeLocation.getAggregateDependencyGraph().getRootDependencies().size() > 0 || aggregateDecision.shouldUploadEmptyAggregate()) {
        uploadTargets.add(UploadTarget.createDefault(projectNameVersion, aggregateCodeLocation.getCodeLocationName(), aggregateCodeLocation.getAggregateFile()));
    } else {
        logger.warn("The aggregate contained no dependencies, will not upload aggregate at this time.");
    }
    return new BdioResult(uploadTargets, new DetectCodeLocationNamesResult(codeLocationNamesResult), isBdio2);
}
Also used : AggregateCodeLocation(com.synopsys.integration.detect.workflow.bdio.AggregateCodeLocation) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BdioResult(com.synopsys.integration.detect.workflow.bdio.BdioResult) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) DetectCodeLocationNamesResult(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocationNamesResult) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)

Example 2 with BdioResult

use of com.synopsys.integration.detect.workflow.bdio.BdioResult in project synopsys-detect by blackducksoftware.

the class UniversalStepRunner method generateStandardBdio.

private BdioResult generateStandardBdio(UniversalToolsResult universalToolsResult, NameVersion projectNameVersion) throws OperationException {
    logger.debug("Creating BDIO code locations.");
    BdioCodeLocationResult codeLocationResult = operationFactory.createBdioCodeLocationsFromDetectCodeLocations(universalToolsResult.getDetectCodeLocations(), projectNameVersion);
    DetectCodeLocationNamesResult namesResult = new DetectCodeLocationNamesResult(codeLocationResult.getCodeLocationNames());
    logger.debug("Creating BDIO files from code locations.");
    if (operationFactory.calculateBdioOptions().isBdio2Enabled()) {
        return new BdioResult(operationFactory.createBdio2Files(codeLocationResult, projectNameVersion), namesResult, true);
    } else {
        return new BdioResult(operationFactory.createBdio1Files(codeLocationResult, projectNameVersion), namesResult, false);
    }
}
Also used : BdioResult(com.synopsys.integration.detect.workflow.bdio.BdioResult) BdioCodeLocationResult(com.synopsys.integration.detect.workflow.codelocation.BdioCodeLocationResult) DetectCodeLocationNamesResult(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocationNamesResult)

Example 3 with BdioResult

use of com.synopsys.integration.detect.workflow.bdio.BdioResult in project synopsys-detect by blackducksoftware.

the class IntelligentModeStepRunner method publishPostResults.

private void publishPostResults(BdioResult bdioResult, ProjectVersionWrapper projectVersionWrapper, DetectToolFilter detectToolFilter) {
    if ((!bdioResult.getUploadTargets().isEmpty() || detectToolFilter.shouldInclude(DetectTool.SIGNATURE_SCAN))) {
        Optional<String> componentsLink = Optional.ofNullable(projectVersionWrapper).map(ProjectVersionWrapper::getProjectVersionView).flatMap(projectVersionView -> projectVersionView.getFirstLinkSafely(ProjectVersionView.COMPONENTS_LINK)).map(HttpUrl::string);
        if (componentsLink.isPresent()) {
            DetectResult detectResult = new BlackDuckBomDetectResult(componentsLink.get());
            operationFactory.publishResult(detectResult);
        }
    }
}
Also used : BlackDuckRunData(com.synopsys.integration.detect.lifecycle.run.data.BlackDuckRunData) OperationFactory(com.synopsys.integration.detect.lifecycle.run.operation.OperationFactory) ImpactAnalysisBatchOutput(com.synopsys.integration.detect.tool.impactanalysis.service.ImpactAnalysisBatchOutput) LoggerFactory(org.slf4j.LoggerFactory) DetectToolFilter(com.synopsys.integration.detect.util.filter.DetectToolFilter) BdioResult(com.synopsys.integration.detect.workflow.bdio.BdioResult) ReportConstants(com.synopsys.integration.detect.workflow.report.util.ReportConstants) DockerTargetData(com.synopsys.integration.detect.lifecycle.run.data.DockerTargetData) HttpUrl(com.synopsys.integration.rest.HttpUrl) HashSet(java.util.HashSet) StepHelper(com.synopsys.integration.detect.lifecycle.run.step.utility.StepHelper) NameVersion(com.synopsys.integration.util.NameVersion) SignatureScannerCodeLocationResult(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerCodeLocationResult) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) BlackDuckBomDetectResult(com.synopsys.integration.detect.workflow.result.BlackDuckBomDetectResult) OperationType(com.synopsys.integration.detect.workflow.status.OperationType) Path(java.nio.file.Path) Logger(org.slf4j.Logger) DetectResult(com.synopsys.integration.detect.workflow.result.DetectResult) Set(java.util.Set) IOException(java.io.IOException) CodeLocationResults(com.synopsys.integration.detect.workflow.blackduck.codelocation.CodeLocationResults) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) BdioUploadResult(com.synopsys.integration.detect.lifecycle.run.operation.blackduck.BdioUploadResult) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) CodeLocationAccumulator(com.synopsys.integration.detect.workflow.blackduck.codelocation.CodeLocationAccumulator) File(java.io.File) DetectTool(com.synopsys.integration.detect.configuration.enumeration.DetectTool) ReportDetectResult(com.synopsys.integration.detect.workflow.result.ReportDetectResult) CodeLocationWaitData(com.synopsys.integration.detect.workflow.blackduck.codelocation.CodeLocationWaitData) CodeLocationCreationData(com.synopsys.integration.blackduck.codelocation.CodeLocationCreationData) Optional(java.util.Optional) OperationException(com.synopsys.integration.detect.lifecycle.OperationException) BlackDuckBomDetectResult(com.synopsys.integration.detect.workflow.result.BlackDuckBomDetectResult) BlackDuckBomDetectResult(com.synopsys.integration.detect.workflow.result.BlackDuckBomDetectResult) DetectResult(com.synopsys.integration.detect.workflow.result.DetectResult) ReportDetectResult(com.synopsys.integration.detect.workflow.result.ReportDetectResult) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 4 with BdioResult

use of com.synopsys.integration.detect.workflow.bdio.BdioResult in project synopsys-detect by blackducksoftware.

the class DetectRun method run.

public void run(BootSingletons bootSingletons) {
    Optional<OperationSystem> operationSystem = Optional.empty();
    try {
        SingletonFactory singletonFactory = new SingletonFactory(bootSingletons);
        EventSingletons eventSingletons = singletonFactory.createEventSingletons();
        UtilitySingletons utilitySingletons = singletonFactory.createUtilitySingletons(eventSingletons);
        operationSystem = Optional.of(utilitySingletons.getOperationSystem());
        // TODO: Remove run data from boot singletons
        ProductRunData productRunData = bootSingletons.getProductRunData();
        OperationFactory operationFactory = createOperationFactory(bootSingletons, utilitySingletons, eventSingletons);
        StepHelper stepHelper = new StepHelper(utilitySingletons.getOperationSystem(), utilitySingletons.getOperationWrapper(), productRunData.getDetectToolFilter());
        // Product independent tools
        UniversalStepRunner stepRunner = new UniversalStepRunner(operationFactory, stepHelper);
        UniversalToolsResult universalToolsResult = stepRunner.runUniversalTools();
        // combine: processProjectInformation() -> ProjectResult (nameversion, bdio)
        NameVersion nameVersion = stepRunner.determineProjectInformation(universalToolsResult);
        operationFactory.publishProjectNameVersionChosen(nameVersion);
        BdioResult bdio = stepRunner.generateBdio(universalToolsResult, nameVersion);
        if (productRunData.shouldUseBlackDuckProduct()) {
            BlackDuckRunData blackDuckRunData = productRunData.getBlackDuckRunData();
            if (blackDuckRunData.isRapid() && blackDuckRunData.isOnline()) {
                RapidModeStepRunner rapidModeSteps = new RapidModeStepRunner(operationFactory);
                rapidModeSteps.runOnline(blackDuckRunData, nameVersion, bdio);
            } else if (blackDuckRunData.isRapid()) {
                logger.info("Rapid Scan is offline, nothing to do.");
            } else if (blackDuckRunData.isOnline()) {
                IntelligentModeStepRunner intelligentModeSteps = new IntelligentModeStepRunner(operationFactory, stepHelper);
                intelligentModeSteps.runOnline(blackDuckRunData, bdio, nameVersion, productRunData.getDetectToolFilter(), universalToolsResult.getDockerTargetData());
            } else {
                IntelligentModeStepRunner intelligentModeSteps = new IntelligentModeStepRunner(operationFactory, stepHelper);
                intelligentModeSteps.runOffline(nameVersion, universalToolsResult.getDockerTargetData());
            }
        }
    } catch (Exception e) {
        logger.error(ReportConstants.RUN_SEPARATOR);
        logger.error("Detect run failed.");
        exceptionUtility.logException(e);
        logger.debug("An exception was thrown during the detect run.", e);
        logger.error(ReportConstants.RUN_SEPARATOR);
        exitCodeManager.requestExitCode(e);
        checkForInterruptedException(e);
    } finally {
        operationSystem.ifPresent(OperationSystem::publishOperations);
    }
}
Also used : NameVersion(com.synopsys.integration.util.NameVersion) BlackDuckRunData(com.synopsys.integration.detect.lifecycle.run.data.BlackDuckRunData) BdioResult(com.synopsys.integration.detect.workflow.bdio.BdioResult) OperationSystem(com.synopsys.integration.detect.workflow.status.OperationSystem) SingletonFactory(com.synopsys.integration.detect.lifecycle.run.singleton.SingletonFactory) UtilitySingletons(com.synopsys.integration.detect.lifecycle.run.singleton.UtilitySingletons) ProductRunData(com.synopsys.integration.detect.lifecycle.run.data.ProductRunData) DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) IntelligentModeStepRunner(com.synopsys.integration.detect.lifecycle.run.step.IntelligentModeStepRunner) UniversalToolsResult(com.synopsys.integration.detect.tool.UniversalToolsResult) RapidModeStepRunner(com.synopsys.integration.detect.lifecycle.run.step.RapidModeStepRunner) EventSingletons(com.synopsys.integration.detect.lifecycle.run.singleton.EventSingletons) StepHelper(com.synopsys.integration.detect.lifecycle.run.step.utility.StepHelper) UniversalStepRunner(com.synopsys.integration.detect.lifecycle.run.step.UniversalStepRunner) OperationFactory(com.synopsys.integration.detect.lifecycle.run.operation.OperationFactory)

Example 5 with BdioResult

use of com.synopsys.integration.detect.workflow.bdio.BdioResult in project synopsys-detect by blackducksoftware.

the class UniversalStepRunner method generateBdio.

public BdioResult generateBdio(UniversalToolsResult universalToolsResult, NameVersion projectNameVersion) throws OperationException {
    ProjectDependencyGraph aggregateDependencyGraph = operationFactory.aggregateSubProject(projectNameVersion, universalToolsResult.getDetectCodeLocations());
    AggregateCodeLocation aggregateCodeLocation = operationFactory.createAggregateCodeLocation(aggregateDependencyGraph, projectNameVersion);
    operationFactory.createAggregateBdio2File(aggregateCodeLocation);
    List<UploadTarget> uploadTargets = new ArrayList<>();
    Map<DetectCodeLocation, String> codeLocationNamesResult = new HashMap<>();
    universalToolsResult.getDetectCodeLocations().forEach(cl -> codeLocationNamesResult.put(cl, aggregateCodeLocation.getCodeLocationName()));
    // TODO: This doesn't seem right, it should just be the aggregate CL name right?
    uploadTargets.add(UploadTarget.createDefault(projectNameVersion, aggregateCodeLocation.getCodeLocationName(), aggregateCodeLocation.getAggregateFile()));
    return new BdioResult(uploadTargets, new DetectCodeLocationNamesResult(codeLocationNamesResult));
}
Also used : AggregateCodeLocation(com.synopsys.integration.detect.workflow.bdio.AggregateCodeLocation) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) HashMap(java.util.HashMap) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) ArrayList(java.util.ArrayList) BdioResult(com.synopsys.integration.detect.workflow.bdio.BdioResult) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) DetectCodeLocationNamesResult(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocationNamesResult)

Aggregations

BdioResult (com.synopsys.integration.detect.workflow.bdio.BdioResult)5 DetectCodeLocationNamesResult (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocationNamesResult)3 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)2 BlackDuckRunData (com.synopsys.integration.detect.lifecycle.run.data.BlackDuckRunData)2 OperationFactory (com.synopsys.integration.detect.lifecycle.run.operation.OperationFactory)2 StepHelper (com.synopsys.integration.detect.lifecycle.run.step.utility.StepHelper)2 AggregateCodeLocation (com.synopsys.integration.detect.workflow.bdio.AggregateCodeLocation)2 DetectCodeLocation (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)2 NameVersion (com.synopsys.integration.util.NameVersion)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)1 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)1 CodeLocationCreationData (com.synopsys.integration.blackduck.codelocation.CodeLocationCreationData)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 DetectTool (com.synopsys.integration.detect.configuration.enumeration.DetectTool)1 OperationException (com.synopsys.integration.detect.lifecycle.OperationException)1