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;
}
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()));
}
}
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;
}
Aggregations