Search in sources :

Example 1 with HubScanConfig

use of com.blackducksoftware.integration.hub.configuration.HubScanConfig 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 HubScanConfig

use of com.blackducksoftware.integration.hub.configuration.HubScanConfig 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)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 HubScanConfig (com.blackducksoftware.integration.hub.configuration.HubScanConfig)2 HubScanConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder)2 File (java.io.File)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 ProjectVersionWrapper (com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1