Search in sources :

Example 1 with DetectConfigurationFactory

use of com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory in project hub-detect by blackducksoftware.

the class BlackDuckSignatureScannerTool method runScanTool.

public SignatureScannerToolResult runScanTool(NameVersion projectNameVersion, Optional<File> dockerTar) throws DetectUserFriendlyException {
    DetectConfiguration detectConfiguration = detectContext.getBean(DetectConfiguration.class);
    DetectConfigurationFactory detectConfigurationFactory = detectContext.getBean(DetectConfigurationFactory.class);
    ConnectionManager connectionManager = detectContext.getBean(ConnectionManager.class);
    ConnectivityManager connectivityManager = detectContext.getBean(ConnectivityManager.class);
    DirectoryManager directoryManager = detectContext.getBean(DirectoryManager.class);
    Optional<BlackDuckServerConfig> hubServerConfig = Optional.empty();
    if (connectivityManager.isDetectOnline() && connectivityManager.getBlackDuckServerConfig().isPresent()) {
        hubServerConfig = connectivityManager.getBlackDuckServerConfig();
    }
    logger.info("Will run the signature scanner tool.");
    final String offlineLocalScannerInstallPath = detectConfiguration.getProperty(DetectProperty.DETECT_BLACKDUCK_SIGNATURE_SCANNER_OFFLINE_LOCAL_PATH, PropertyAuthority.None);
    final String onlineLocalScannerInstallPath = detectConfiguration.getProperty(DetectProperty.DETECT_BLACKDUCK_SIGNATURE_SCANNER_LOCAL_PATH, PropertyAuthority.None);
    String localScannerInstallPath = "";
    if (StringUtils.isNotBlank(offlineLocalScannerInstallPath)) {
        localScannerInstallPath = offlineLocalScannerInstallPath;
        logger.debug("Determined offline local scanner path: " + localScannerInstallPath);
    } else if (StringUtils.isNotBlank(onlineLocalScannerInstallPath)) {
        localScannerInstallPath = onlineLocalScannerInstallPath;
        logger.debug("Determined online local scanner path: " + localScannerInstallPath);
    }
    final String userProvidedScannerInstallUrl = detectConfiguration.getProperty(DetectProperty.DETECT_BLACKDUCK_SIGNATURE_SCANNER_HOST_URL, PropertyAuthority.None);
    BlackDuckSignatureScannerOptions blackDuckSignatureScannerOptions = detectConfigurationFactory.createBlackDuckSignatureScannerOptions();
    final ExecutorService executorService = Executors.newFixedThreadPool(blackDuckSignatureScannerOptions.getParrallelProcessors());
    IntEnvironmentVariables intEnvironmentVariables = new IntEnvironmentVariables();
    ScanBatchRunnerFactory scanBatchRunnerFactory = new ScanBatchRunnerFactory(intEnvironmentVariables, executorService);
    ScanBatchRunner scanBatchRunner;
    File installDirectory = directoryManager.getPermanentDirectory();
    if (hubServerConfig.isPresent() && StringUtils.isBlank(userProvidedScannerInstallUrl) && StringUtils.isBlank(localScannerInstallPath)) {
        logger.debug("Signature scanner will use the hub server to download/update the scanner - this is the most likely situation.");
        scanBatchRunner = scanBatchRunnerFactory.withHubInstall(hubServerConfig.get());
    } else {
        if (StringUtils.isNotBlank(userProvidedScannerInstallUrl)) {
            logger.debug("Signature scanner will use the provided url to download/update the scanner.");
            scanBatchRunner = scanBatchRunnerFactory.withUserProvidedUrl(userProvidedScannerInstallUrl, connectionManager);
        } else {
            logger.debug("Signature scanner either given an existing path for the scanner or is offline - either way, we won't attempt to manage the install.");
            if (StringUtils.isNotBlank(localScannerInstallPath)) {
                logger.debug("Using provided path: " + localScannerInstallPath);
                installDirectory = new File(localScannerInstallPath);
            } else {
                logger.debug("Using default scanner path.");
            }
            scanBatchRunner = scanBatchRunnerFactory.withoutInstall(installDirectory);
        }
    }
    logger.debug("Determined install directory: " + installDirectory.getAbsolutePath());
    try {
        if (hubServerConfig.isPresent()) {
            logger.debug("Signature scan is online.");
            CodeLocationCreationService codeLocationCreationService = connectivityManager.getBlackDuckServicesFactory().get().createCodeLocationCreationService();
            OnlineBlackDuckSignatureScanner blackDuckSignatureScanner = detectContext.getBean(OnlineBlackDuckSignatureScanner.class, signatureScannerOptions, scanBatchRunner, codeLocationCreationService, hubServerConfig.get());
            CodeLocationCreationData<ScanBatchOutput> codeLocationCreationData = blackDuckSignatureScanner.performOnlineScan(projectNameVersion, installDirectory, dockerTar.orElse(null));
            return SignatureScannerToolResult.createOnlineResult(codeLocationCreationData);
        } else {
            logger.debug("Signature scan is offline.");
            OfflineBlackDuckSignatureScanner blackDuckSignatureScanner = detectContext.getBean(OfflineBlackDuckSignatureScanner.class, signatureScannerOptions, scanBatchRunner);
            ScanBatchOutput scanBatchOutput = blackDuckSignatureScanner.performScanActions(projectNameVersion, installDirectory, dockerTar.orElse(null));
            return SignatureScannerToolResult.createOfflineResult(scanBatchOutput);
        }
    } catch (IOException | InterruptedException | IntegrationException e) {
        logger.info("Signature scan failed!");
        logger.debug("Signature scan error!", e);
        return SignatureScannerToolResult.createFailureResult();
    } finally {
        executorService.shutdownNow();
    }
}
Also used : CodeLocationCreationService(com.synopsys.integration.blackduck.codelocation.CodeLocationCreationService) IntegrationException(com.synopsys.integration.exception.IntegrationException) ConnectivityManager(com.blackducksoftware.integration.hub.detect.workflow.ConnectivityManager) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) IOException(java.io.IOException) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) ScanBatchRunner(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchRunner) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) IntEnvironmentVariables(com.synopsys.integration.util.IntEnvironmentVariables) ConnectionManager(com.blackducksoftware.integration.hub.detect.configuration.ConnectionManager) DetectConfigurationFactory(com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) ScanBatchOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchOutput)

Example 2 with DetectConfigurationFactory

use of com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory in project hub-detect by blackducksoftware.

the class BootManager method boot.

public BootResult boot(DetectRun detectRun, final String[] sourceArgs, ConfigurableEnvironment environment, EventSystem eventSystem, DetectContext detectContext) throws DetectUserFriendlyException, IntegrationException {
    Gson gson = bootFactory.createGson();
    ObjectMapper objectMapper = bootFactory.createObjectMapper();
    DocumentBuilder xml = bootFactory.createXmlDocumentBuilder();
    Configuration configuration = bootFactory.createConfiguration();
    DetectInfo detectInfo = DetectInfoUtility.createDefaultDetectInfo();
    SpringPropertySource springPropertySource = new SpringPropertySource(environment);
    DetectPropertySource propertySource = new DetectPropertySource(springPropertySource);
    DetectPropertyMap propertyMap = new DetectPropertyMap();
    DetectConfiguration detectConfiguration = new DetectConfiguration(propertySource, propertyMap);
    DetectOptionManager detectOptionManager = new DetectOptionManager(detectConfiguration, detectInfo);
    final List<DetectOption> options = detectOptionManager.getDetectOptions();
    DetectArgumentState detectArgumentState = parseDetectArgumentState(sourceArgs);
    if (detectArgumentState.isHelp() || detectArgumentState.isDeprecatedHelp() || detectArgumentState.isVerboseHelp()) {
        printAppropriateHelp(options, detectArgumentState);
        return BootResult.exit(detectConfiguration);
    }
    if (detectArgumentState.isHelpHtmlDocument()) {
        printHelpHtmlDocument(options, detectInfo, configuration);
        return BootResult.exit(detectConfiguration);
    }
    if (detectArgumentState.isHelpJsonDocument()) {
        printHelpJsonDocument(options, detectInfo, configuration, gson);
        return BootResult.exit(detectConfiguration);
    }
    printDetectInfo(detectInfo);
    if (detectArgumentState.isInteractive()) {
        startInteractiveMode(detectOptionManager, detectConfiguration, gson, objectMapper);
    }
    processDetectConfiguration(detectInfo, detectRun, detectConfiguration, options);
    detectOptionManager.postConfigurationProcessedInit();
    logger.info("Configuration processed completely.");
    printConfiguration(detectConfiguration.getBooleanProperty(DetectProperty.DETECT_SUPPRESS_CONFIGURATION_OUTPUT, PropertyAuthority.None), options);
    logger.info("Initializing detect.");
    DetectConfigurationFactory factory = new DetectConfigurationFactory(detectConfiguration);
    DirectoryManager directoryManager = new DirectoryManager(factory.createDirectoryOptions(), detectRun);
    DiagnosticManager diagnosticManager = createDiagnostics(detectOptionManager.getDetectOptions(), detectRun, detectInfo, detectArgumentState, eventSystem, directoryManager);
    checkForInvalidOptions(detectOptionManager);
    if (detectOptionManager.checkForAnyFailureProperties()) {
        eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_CONFIGURATION));
        return BootResult.exit(detectConfiguration);
    }
    ConnectivityManager connectivityManager;
    boolean offline = detectConfiguration.getBooleanProperty(DetectProperty.BLACKDUCK_OFFLINE_MODE, PropertyAuthority.None);
    if (offline) {
        logger.info("Detect is in offline mode.");
        connectivityManager = ConnectivityManager.offline();
    } else {
        logger.info("Detect is in online mode.");
        // check my connectivity
        ConnectivityChecker connectivityChecker = new ConnectivityChecker();
        ConnectivityResult connectivityResult = connectivityChecker.determineConnectivity(detectConfiguration, detectOptionManager, detectInfo, gson, objectMapper, eventSystem);
        if (connectivityResult.isSuccessfullyConnected()) {
            logger.info("Detect is capable of communicating with server.");
            connectivityManager = ConnectivityManager.online(connectivityResult.getBlackDuckServicesFactory(), connectivityResult.getPhoneHomeManager(), connectivityResult.getBlackDuckServerConfig());
        } else {
            logger.info("Detect is NOT capable of communicating with server.");
            logger.info("Please double check the Detect documentation: https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/622633/Hub+Detect");
            if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_DISABLE_WITHOUT_BLACKDUCK, PropertyAuthority.None)) {
                logger.info(connectivityResult.getFailureReason());
                logger.info(String.format("%s is set to 'true' so Detect will simply exit.", DetectProperty.DETECT_DISABLE_WITHOUT_BLACKDUCK.getPropertyName()));
                return BootResult.exit(detectConfiguration);
            } else {
                throw new DetectUserFriendlyException("Could not communicate with Black Duck: " + connectivityResult.getFailureReason(), ExitCodeType.FAILURE_HUB_CONNECTIVITY);
            }
        }
    }
    if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_TEST_CONNECTION, PropertyAuthority.None)) {
        logger.info(String.format("%s is set to 'true' so Detect will not run.", DetectProperty.DETECT_TEST_CONNECTION.getPropertyName()));
        return BootResult.exit(detectConfiguration);
    }
    // TODO: Only need this if in diagnostic or online (for phone home):
    BomToolProfiler profiler = new BomToolProfiler(eventSystem);
    // lock the configuration, boot has completed.
    logger.debug("Configuration is now complete. No changes should occur to configuration.");
    detectConfiguration.lock();
    // Finished, populate the detect context
    detectContext.registerBean(detectRun);
    detectContext.registerBean(eventSystem);
    detectContext.registerBean(profiler);
    detectContext.registerBean(detectConfiguration);
    detectContext.registerBean(detectInfo);
    detectContext.registerBean(directoryManager);
    detectContext.registerBean(diagnosticManager);
    detectContext.registerBean(connectivityManager);
    detectContext.registerBean(gson);
    detectContext.registerBean(objectMapper);
    detectContext.registerBean(xml);
    detectContext.registerBean(configuration);
    detectContext.registerConfiguration(RunBeanConfiguration.class);
    detectContext.registerConfiguration(DetectorBeanConfiguration.class);
    // can only refresh once, this locks and triggers refresh.
    detectContext.lock();
    BootResult result = new BootResult();
    result.bootType = BootResult.BootType.CONTINUE;
    result.detectConfiguration = detectConfiguration;
    return result;
}
Also used : RunBeanConfiguration(com.blackducksoftware.integration.hub.detect.RunBeanConfiguration) DetectorBeanConfiguration(com.blackducksoftware.integration.hub.detect.DetectorBeanConfiguration) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) Configuration(freemarker.template.Configuration) DetectInfo(com.blackducksoftware.integration.hub.detect.DetectInfo) ConnectivityManager(com.blackducksoftware.integration.hub.detect.workflow.ConnectivityManager) SpringPropertySource(com.blackducksoftware.integration.hub.detect.property.SpringPropertySource) ExitCodeRequest(com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) Gson(com.google.gson.Gson) BomToolProfiler(com.blackducksoftware.integration.hub.detect.workflow.profiling.BomToolProfiler) DetectOptionManager(com.blackducksoftware.integration.hub.detect.help.DetectOptionManager) DetectOption(com.blackducksoftware.integration.hub.detect.help.DetectOption) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) DetectPropertyMap(com.blackducksoftware.integration.hub.detect.configuration.DetectPropertyMap) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) DetectArgumentState(com.blackducksoftware.integration.hub.detect.help.DetectArgumentState) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DetectConfigurationFactory(com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory) DiagnosticManager(com.blackducksoftware.integration.hub.detect.workflow.diagnostic.DiagnosticManager) DetectPropertySource(com.blackducksoftware.integration.hub.detect.configuration.DetectPropertySource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with DetectConfigurationFactory

use of com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory in project hub-detect by blackducksoftware.

the class RunManager method run.

public RunResult run() throws DetectUserFriendlyException, InterruptedException, IntegrationException {
    // TODO: Better way for run manager to get dependencies so he can be tested. (And better ways of creating his objects)
    final DetectConfiguration detectConfiguration = detectContext.getBean(DetectConfiguration.class);
    final DetectConfigurationFactory detectConfigurationFactory = detectContext.getBean(DetectConfigurationFactory.class);
    final DirectoryManager directoryManager = detectContext.getBean(DirectoryManager.class);
    final EventSystem eventSystem = detectContext.getBean(EventSystem.class);
    final CodeLocationNameManager codeLocationNameManager = detectContext.getBean(CodeLocationNameManager.class);
    final BdioCodeLocationCreator bdioCodeLocationCreator = detectContext.getBean(BdioCodeLocationCreator.class);
    final ConnectionManager connectionManager = detectContext.getBean(ConnectionManager.class);
    final DetectInfo detectInfo = detectContext.getBean(DetectInfo.class);
    final ConnectivityManager connectivityManager = detectContext.getBean(ConnectivityManager.class);
    if (connectivityManager.getPhoneHomeManager().isPresent()) {
        connectivityManager.getPhoneHomeManager().get().startPhoneHome();
    }
    final RunResult runResult = new RunResult();
    final RunOptions runOptions = detectConfigurationFactory.createRunOptions();
    final DetectToolFilter detectToolFilter = runOptions.getDetectToolFilter();
    DetectorEnvironment detectorEnvironment = new DetectorEnvironment(directoryManager.getSourceDirectory(), Collections.emptySet(), 0, null, false);
    DetectorFactory detectorFactory = detectContext.getBean(DetectorFactory.class);
    logger.info(ReportConstants.RUN_SEPARATOR);
    if (detectToolFilter.shouldInclude(DetectTool.DOCKER)) {
        logger.info("Will include the docker tool.");
        ToolRunner toolRunner = new ToolRunner(eventSystem, detectorFactory.createDockerDetector(detectorEnvironment));
        toolRunner.run(runResult);
        logger.info("Docker actions finished.");
    } else {
        logger.info("Docker tool will not be run.");
    }
    logger.info(ReportConstants.RUN_SEPARATOR);
    if (detectToolFilter.shouldInclude(DetectTool.BAZEL)) {
        logger.info("Will include the bazel tool.");
        ToolRunner toolRunner = new ToolRunner(eventSystem, detectorFactory.createBazelDetector(detectorEnvironment));
        toolRunner.run(runResult);
        logger.info("Bazel actions finished.");
    } else {
        logger.info("Bazel tool will not be run.");
    }
    logger.info(ReportConstants.RUN_SEPARATOR);
    if (detectToolFilter.shouldInclude(DetectTool.DETECTOR)) {
        logger.info("Will include the detector tool.");
        final String projectBomTool = detectConfiguration.getProperty(DetectProperty.DETECT_PROJECT_DETECTOR, PropertyAuthority.None);
        final SearchOptions searchOptions = detectConfigurationFactory.createSearchOptions(directoryManager.getSourceDirectory());
        final DetectorTool detectorTool = new DetectorTool(detectContext);
        final DetectorToolResult detectorToolResult = detectorTool.performDetectors(searchOptions, projectBomTool);
        runResult.addToolNameVersionIfPresent(DetectTool.DETECTOR, detectorToolResult.bomToolProjectNameVersion);
        runResult.addDetectCodeLocations(detectorToolResult.bomToolCodeLocations);
        runResult.addApplicableDetectors(detectorToolResult.applicableDetectorTypes);
        if (detectorToolResult.failedDetectorTypes.size() > 0) {
            eventSystem.publishEvent(Event.ExitCode, new ExitCodeRequest(ExitCodeType.FAILURE_DETECTOR, "A detector failed."));
        }
        logger.info("Detector actions finished.");
    } else {
        logger.info("Detector tool will not be run.");
    }
    logger.info(ReportConstants.RUN_SEPARATOR);
    logger.info("Completed code location tools.");
    logger.info("Determining project info.");
    final ProjectNameVersionOptions projectNameVersionOptions = detectConfigurationFactory.createProjectNameVersionOptions(directoryManager.getSourceDirectory().getName());
    final ProjectNameVersionDecider projectNameVersionDecider = new ProjectNameVersionDecider(projectNameVersionOptions);
    final NameVersion projectNameVersion = projectNameVersionDecider.decideProjectNameVersion(runOptions.getPreferredTools(), runResult.getDetectToolProjectInfo());
    logger.info("Project name: " + projectNameVersion.getName());
    logger.info("Project version: " + projectNameVersion.getVersion());
    Optional<ProjectVersionWrapper> projectVersionWrapper = Optional.empty();
    if (connectivityManager.isDetectOnline() && connectivityManager.getBlackDuckServicesFactory().isPresent()) {
        final BlackDuckServicesFactory blackDuckServicesFactory = connectivityManager.getBlackDuckServicesFactory().get();
        logger.info("Getting or creating project.");
        final DetectProjectServiceOptions options = detectConfigurationFactory.createDetectProjectServiceOptions();
        final DetectProjectMappingService detectProjectMappingService = new DetectProjectMappingService(blackDuckServicesFactory.createBlackDuckService());
        final DetectProjectService detectProjectService = new DetectProjectService(blackDuckServicesFactory, options, detectProjectMappingService);
        projectVersionWrapper = Optional.of(detectProjectService.createOrUpdateHubProject(projectNameVersion, options.getApplicationId()));
        if (projectVersionWrapper.isPresent() && runOptions.shouldUnmapCodeLocations()) {
            logger.info("Unmapping code locations.");
            final DetectCodeLocationUnmapService detectCodeLocationUnmapService = new DetectCodeLocationUnmapService(blackDuckServicesFactory.createBlackDuckService(), blackDuckServicesFactory.createCodeLocationService());
            detectCodeLocationUnmapService.unmapCodeLocations(projectVersionWrapper.get().getProjectVersionView());
        } else {
            logger.debug("Will not unmap code locations: Project view was not present, or should not unmap code locations.");
        }
    } else {
        logger.debug("Detect is not online, and will not create the project.");
    }
    logger.info("Completed project and version actions.");
    logger.info("Processing Detect Code Locations.");
    final CodeLocationWaitData codeLocationWaitData = new CodeLocationWaitData();
    final BdioManager bdioManager = new BdioManager(detectInfo, new SimpleBdioFactory(), new IntegrationEscapeUtil(), codeLocationNameManager, detectConfiguration, bdioCodeLocationCreator, directoryManager, eventSystem);
    final BdioResult bdioResult = bdioManager.createBdioFiles(runOptions.getAggregateName(), projectNameVersion, runResult.getDetectCodeLocations());
    if (bdioResult.getUploadTargets().size() > 0) {
        logger.info("Created " + bdioResult.getUploadTargets().size() + " BDIO files.");
        bdioResult.getUploadTargets().forEach(it -> eventSystem.publishEvent(Event.OutputFileOfInterest, it.getUploadFile()));
        if (connectivityManager.isDetectOnline() && connectivityManager.getBlackDuckServicesFactory().isPresent()) {
            logger.info("Uploading BDIO files.");
            final BlackDuckServicesFactory blackDuckServicesFactory = connectivityManager.getBlackDuckServicesFactory().get();
            final DetectBdioUploadService detectBdioUploadService = new DetectBdioUploadService(detectConfiguration, blackDuckServicesFactory.createBdioUploadService(), eventSystem);
            final CodeLocationCreationData<UploadBatchOutput> uploadBatchOutputCodeLocationCreationData = detectBdioUploadService.uploadBdioFiles(bdioResult.getUploadTargets());
            codeLocationWaitData.setFromBdioCodeLocationCreationData(uploadBatchOutputCodeLocationCreationData);
        }
    } else {
        logger.debug("Did not create any BDIO files.");
    }
    logger.info("Completed Detect Code Location processing.");
    logger.info(ReportConstants.RUN_SEPARATOR);
    if (detectToolFilter.shouldInclude(DetectTool.SIGNATURE_SCAN)) {
        logger.info("Will include the signature scanner tool.");
        final BlackDuckSignatureScannerOptions blackDuckSignatureScannerOptions = detectConfigurationFactory.createBlackDuckSignatureScannerOptions();
        final BlackDuckSignatureScannerTool blackDuckSignatureScannerTool = new BlackDuckSignatureScannerTool(blackDuckSignatureScannerOptions, detectContext);
        final SignatureScannerToolResult signatureScannerToolResult = blackDuckSignatureScannerTool.runScanTool(projectNameVersion, runResult.getDockerTar());
        if (signatureScannerToolResult.getResult() == Result.SUCCESS && signatureScannerToolResult.getCreationData().isPresent()) {
            codeLocationWaitData.setFromSignatureScannerCodeLocationCreationData(signatureScannerToolResult.getCreationData().get());
        }
        logger.info("Signature scanner actions finished.");
    } else {
        logger.info("Signature scan tool will not be run.");
    }
    logger.info(ReportConstants.RUN_SEPARATOR);
    if (detectToolFilter.shouldInclude(DetectTool.BINARY_SCAN)) {
        logger.info("Will include the binary scanner tool.");
        if (connectivityManager.isDetectOnline() && connectivityManager.getBlackDuckServicesFactory().isPresent()) {
            final BlackDuckServicesFactory blackDuckServicesFactory = connectivityManager.getBlackDuckServicesFactory().get();
            final BlackDuckBinaryScannerTool blackDuckBinaryScanner = new BlackDuckBinaryScannerTool(eventSystem, codeLocationNameManager, detectConfiguration, blackDuckServicesFactory);
            BinaryScanToolResult result = blackDuckBinaryScanner.performBinaryScanActions(projectNameVersion);
            if (result.isSuccessful()) {
                codeLocationWaitData.setFromBinaryScan(result.getNotificationTaskRange(), result.getCodeLocationNames());
            }
        }
        logger.info("Binary scanner actions finished.");
    } else {
        logger.info("Binary scan tool will not be run.");
    }
    logger.info(ReportConstants.RUN_SEPARATOR);
    if (detectToolFilter.shouldInclude(DetectTool.POLARIS)) {
        logger.info("Will include the Polaris tool.");
        final PolarisTool polarisTool = new PolarisTool(eventSystem, directoryManager, new ExecutableRunner(), connectionManager);
        polarisTool.runPolaris(new Slf4jIntLogger(logger), directoryManager.getSourceDirectory());
        logger.info("Polaris actions finished.");
    } else {
        logger.info("Polaris CLI tool will not be run.");
    }
    logger.info(ReportConstants.RUN_SEPARATOR);
    if (projectVersionWrapper.isPresent() && connectivityManager.isDetectOnline() && connectivityManager.getBlackDuckServicesFactory().isPresent()) {
        final BlackDuckServicesFactory blackDuckServicesFactory = connectivityManager.getBlackDuckServicesFactory().get();
        logger.info("Will perform Black Duck post actions.");
        final BlackduckReportOptions blackduckReportOptions = detectConfigurationFactory.createReportOptions();
        final PolicyCheckOptions policyCheckOptions = detectConfigurationFactory.createPolicyCheckOptions();
        final long timeoutInSeconds = detectConfigurationFactory.getTimeoutInSeconds();
        final BlackduckPostActions blackduckPostActions = new BlackduckPostActions(blackDuckServicesFactory, eventSystem);
        blackduckPostActions.perform(blackduckReportOptions, policyCheckOptions, codeLocationWaitData, projectVersionWrapper.get(), timeoutInSeconds);
        final boolean hasAtLeastOneBdio = !bdioResult.getUploadTargets().isEmpty();
        final boolean shouldHaveScanned = detectToolFilter.shouldInclude(DetectTool.SIGNATURE_SCAN);
        if (hasAtLeastOneBdio || shouldHaveScanned) {
            final Optional<String> componentsLink = projectVersionWrapper.get().getProjectVersionView().getFirstLink(ProjectVersionView.COMPONENTS_LINK);
            if (componentsLink.isPresent()) {
                logger.info(String.format("To see your results, follow the URL: %s", componentsLink.get()));
            }
        }
        logger.info("Black Duck actions have finished.");
    } else {
        logger.debug("Will not perform post actions: Detect is not online.");
    }
    logger.info("All tools have finished.");
    logger.info(ReportConstants.RUN_SEPARATOR);
    return runResult;
}
Also used : DetectProjectService(com.blackducksoftware.integration.hub.detect.workflow.hub.DetectProjectService) CodeLocationNameManager(com.blackducksoftware.integration.hub.detect.workflow.codelocation.CodeLocationNameManager) NameVersion(com.synopsys.integration.util.NameVersion) BinaryScanToolResult(com.blackducksoftware.integration.hub.detect.tool.binaryscanner.BinaryScanToolResult) ToolRunner(com.blackducksoftware.integration.hub.detect.tool.ToolRunner) BlackduckPostActions(com.blackducksoftware.integration.hub.detect.workflow.hub.BlackduckPostActions) ConnectionManager(com.blackducksoftware.integration.hub.detect.configuration.ConnectionManager) DetectToolFilter(com.blackducksoftware.integration.hub.detect.workflow.DetectToolFilter) DetectBdioUploadService(com.blackducksoftware.integration.hub.detect.workflow.hub.DetectBdioUploadService) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.bdioupload.UploadBatchOutput) BlackDuckBinaryScannerTool(com.blackducksoftware.integration.hub.detect.tool.binaryscanner.BlackDuckBinaryScannerTool) DetectorEnvironment(com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment) SearchOptions(com.blackducksoftware.integration.hub.detect.workflow.search.SearchOptions) ExecutableRunner(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner) PolarisTool(com.blackducksoftware.integration.hub.detect.tool.polaris.PolarisTool) DetectConfigurationFactory(com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory) DetectProjectMappingService(com.blackducksoftware.integration.hub.detect.workflow.hub.DetectProjectMappingService) DetectInfo(com.blackducksoftware.integration.hub.detect.DetectInfo) PolicyCheckOptions(com.blackducksoftware.integration.hub.detect.workflow.hub.PolicyCheckOptions) ConnectivityManager(com.blackducksoftware.integration.hub.detect.workflow.ConnectivityManager) DetectProjectServiceOptions(com.blackducksoftware.integration.hub.detect.workflow.hub.DetectProjectServiceOptions) DetectorFactory(com.blackducksoftware.integration.hub.detect.detector.DetectorFactory) BdioResult(com.blackducksoftware.integration.hub.detect.workflow.bdio.BdioResult) ProjectNameVersionOptions(com.blackducksoftware.integration.hub.detect.workflow.project.ProjectNameVersionOptions) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) SignatureScannerToolResult(com.blackducksoftware.integration.hub.detect.tool.signaturescanner.SignatureScannerToolResult) BdioCodeLocationCreator(com.blackducksoftware.integration.hub.detect.workflow.codelocation.BdioCodeLocationCreator) ProjectNameVersionDecider(com.blackducksoftware.integration.hub.detect.workflow.project.ProjectNameVersionDecider) BlackDuckSignatureScannerOptions(com.blackducksoftware.integration.hub.detect.tool.signaturescanner.BlackDuckSignatureScannerOptions) CodeLocationWaitData(com.blackducksoftware.integration.hub.detect.workflow.hub.CodeLocationWaitData) BlackDuckSignatureScannerTool(com.blackducksoftware.integration.hub.detect.tool.signaturescanner.BlackDuckSignatureScannerTool) EventSystem(com.blackducksoftware.integration.hub.detect.workflow.event.EventSystem) BdioManager(com.blackducksoftware.integration.hub.detect.workflow.bdio.BdioManager) IntegrationEscapeUtil(com.synopsys.integration.util.IntegrationEscapeUtil) SimpleBdioFactory(com.synopsys.integration.bdio.SimpleBdioFactory) ExitCodeRequest(com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest) DirectoryManager(com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager) BlackduckReportOptions(com.blackducksoftware.integration.hub.detect.workflow.hub.BlackduckReportOptions) DetectorTool(com.blackducksoftware.integration.hub.detect.tool.detector.DetectorTool) DetectCodeLocationUnmapService(com.blackducksoftware.integration.hub.detect.workflow.hub.DetectCodeLocationUnmapService) DetectorToolResult(com.blackducksoftware.integration.hub.detect.tool.detector.DetectorToolResult) DetectConfiguration(com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger)

Aggregations

DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)3 DetectConfigurationFactory (com.blackducksoftware.integration.hub.detect.configuration.DetectConfigurationFactory)3 ConnectivityManager (com.blackducksoftware.integration.hub.detect.workflow.ConnectivityManager)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 DetectInfo (com.blackducksoftware.integration.hub.detect.DetectInfo)2 ConnectionManager (com.blackducksoftware.integration.hub.detect.configuration.ConnectionManager)2 ExitCodeRequest (com.blackducksoftware.integration.hub.detect.lifecycle.shutdown.ExitCodeRequest)2 DetectorBeanConfiguration (com.blackducksoftware.integration.hub.detect.DetectorBeanConfiguration)1 RunBeanConfiguration (com.blackducksoftware.integration.hub.detect.RunBeanConfiguration)1 DetectPropertyMap (com.blackducksoftware.integration.hub.detect.configuration.DetectPropertyMap)1 DetectPropertySource (com.blackducksoftware.integration.hub.detect.configuration.DetectPropertySource)1 DetectorEnvironment (com.blackducksoftware.integration.hub.detect.detector.DetectorEnvironment)1 DetectorFactory (com.blackducksoftware.integration.hub.detect.detector.DetectorFactory)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 DetectArgumentState (com.blackducksoftware.integration.hub.detect.help.DetectArgumentState)1 DetectOption (com.blackducksoftware.integration.hub.detect.help.DetectOption)1 DetectOptionManager (com.blackducksoftware.integration.hub.detect.help.DetectOptionManager)1 SpringPropertySource (com.blackducksoftware.integration.hub.detect.property.SpringPropertySource)1 ToolRunner (com.blackducksoftware.integration.hub.detect.tool.ToolRunner)1 BinaryScanToolResult (com.blackducksoftware.integration.hub.detect.tool.binaryscanner.BinaryScanToolResult)1