Search in sources :

Example 1 with HubScanConfigBuilder

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

the class HubSignatureScanner method scanPaths.

public ProjectVersionView scanPaths(final HubServerConfig hubServerConfig, final SignatureScannerService signatureScannerService, final DetectProject detectProject) throws IntegrationException {
    ProjectVersionView projectVersionView = null;
    final ProjectRequest projectRequest = createProjectRequest(detectProject);
    Set<String> canonicalPathsToScan = registeredPaths;
    if (null != detectProject.getProjectName() && null != detectProject.getProjectVersionName() && null != detectConfiguration.getHubSignatureScannerPaths() && detectConfiguration.getHubSignatureScannerPaths().length > 0) {
        canonicalPathsToScan = new HashSet<>();
        for (final String path : detectConfiguration.getHubSignatureScannerPaths()) {
            try {
                canonicalPathsToScan.add(new File(path).getCanonicalPath());
            } catch (final IOException e) {
                throw new IntegrationException(e.getMessage(), e);
            }
        }
    }
    final List<ScanPathCallable> scanPathCallables = new ArrayList<>();
    for (final String canonicalPath : canonicalPathsToScan) {
        final HubScanConfigBuilder hubScanConfigBuilder = createScanConfigBuilder(detectProject, canonicalPath);
        final HubScanConfig hubScanConfig = hubScanConfigBuilder.build();
        final ScanPathCallable scanPathCallable = new ScanPathCallable(signatureScannerService, hubServerConfig, hubScanConfig, projectRequest, canonicalPath, scanSummaryResults);
        scanPathCallables.add(scanPathCallable);
    }
    final ExecutorService pool = Executors.newFixedThreadPool(detectConfiguration.getHubSignatureScannerParallelProcessors());
    try {
        for (final ScanPathCallable scanPathCallable : scanPathCallables) {
            pool.submit(scanPathCallable);
        }
        for (final ScanPathCallable scanPathCallable : scanPathCallables) {
            final ProjectVersionWrapper projectVersionWrapperFromScan = scanPathCallable.call();
            if (projectVersionWrapperFromScan != null) {
                projectVersionView = projectVersionWrapperFromScan.getProjectVersionView();
            }
        }
    } finally {
        // get() was called on every java.util.concurrent.Future, no need to wait any longer
        pool.shutdownNow();
    }
    return projectVersionView;
}
Also used : HubScanConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) HubScanConfig(com.blackducksoftware.integration.hub.configuration.HubScanConfig) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)

Example 2 with HubScanConfigBuilder

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

the class HubSignatureScanner method scanPathOffline.

private void scanPathOffline(final String canonicalPath, final DetectProject detectProject) {
    try {
        final HubScanConfigBuilder hubScanConfigBuilder = createScanConfigBuilder(detectProject, canonicalPath);
        hubScanConfigBuilder.setDryRun(true);
        if (StringUtils.isBlank(detectConfiguration.getHubSignatureScannerOfflineLocalPath())) {
            final File toolsDirectory = detectFileManager.createDirectory("tools", false);
            hubScanConfigBuilder.setToolsDir(toolsDirectory);
        }
        final HubScanConfig hubScanConfig = hubScanConfigBuilder.build();
        final boolean pathWasScanned = offlineScanner.offlineScan(detectProject, hubScanConfig, detectConfiguration.getHubSignatureScannerOfflineLocalPath());
        if (pathWasScanned) {
            scanSummaryResults.put(canonicalPath, Result.SUCCESS);
            logger.info(String.format("%s was successfully scanned by the BlackDuck CLI.", canonicalPath));
        }
    } catch (final Exception e) {
        logger.error(String.format("%s/%s - %s was not scanned by the BlackDuck CLI: %s", detectProject.getProjectName(), detectProject.getProjectVersionName(), canonicalPath, e.getMessage()));
    }
}
Also used : HubScanConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder) HubScanConfig(com.blackducksoftware.integration.hub.configuration.HubScanConfig) File(java.io.File) IOException(java.io.IOException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException)

Example 3 with HubScanConfigBuilder

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

the class HubSignatureScanner method createScanConfigBuilder.

private HubScanConfigBuilder createScanConfigBuilder(final DetectProject detectProject, final String canonicalPath) {
    final File scannerDirectory = new File(detectConfiguration.getScanOutputDirectoryPath());
    final File toolsDirectory = detectFileManager.createDirectory("tools", false);
    final HubScanConfigBuilder hubScanConfigBuilder = new HubScanConfigBuilder();
    hubScanConfigBuilder.setScanMemory(detectConfiguration.getHubSignatureScannerMemory());
    hubScanConfigBuilder.setToolsDir(toolsDirectory);
    hubScanConfigBuilder.setWorkingDirectory(scannerDirectory);
    hubScanConfigBuilder.addScanTargetPath(canonicalPath);
    hubScanConfigBuilder.setCleanupLogsOnSuccess(detectConfiguration.getCleanupBomToolFiles());
    hubScanConfigBuilder.setDryRun(detectConfiguration.getHubSignatureScannerDryRun());
    hubScanConfigBuilder.setSnippetModeEnabled(detectConfiguration.getHubSignatureScannerSnippetMode());
    final String projectName = detectProject.getProjectName();
    final String projectVersionName = detectProject.getProjectVersionName();
    final String sourcePath = detectConfiguration.getSourcePath();
    final String prefix = detectConfiguration.getProjectCodeLocationPrefix();
    final String suffix = detectConfiguration.getProjectCodeLocationSuffix();
    final CodeLocationName codeLocationName = codeLocationNameService.createScanName(sourcePath, canonicalPath, projectName, projectVersionName, prefix, suffix);
    final String codeLocationNameString = codeLocationNameService.generateScanCurrent(codeLocationName);
    hubScanConfigBuilder.setCodeLocationAlias(codeLocationNameString);
    if (null != detectConfiguration.getHubSignatureScannerExclusionPatterns() && detectConfiguration.getHubSignatureScannerExclusionPatterns().length > 0) {
        hubScanConfigBuilder.setExcludePatterns(detectConfiguration.getHubSignatureScannerExclusionPatterns());
    } else if (null != registeredPathsToExclude && !registeredPathsToExclude.isEmpty()) {
        hubScanConfigBuilder.setExcludePatterns(registeredPathsToExclude.toArray(new String[registeredPathsToExclude.size()]));
    }
    return hubScanConfigBuilder;
}
Also used : HubScanConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder) File(java.io.File) CodeLocationName(com.blackducksoftware.integration.hub.detect.codelocation.CodeLocationName)

Aggregations

HubScanConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder)3 File (java.io.File)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 HubScanConfig (com.blackducksoftware.integration.hub.configuration.HubScanConfig)2 IOException (java.io.IOException)2 ProjectRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest)1 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)1 CodeLocationName (com.blackducksoftware.integration.hub.detect.codelocation.CodeLocationName)1 ProjectVersionWrapper (com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1