use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath in project synopsys-detect by blackducksoftware.
the class CreateSignatureScanReports method createReports.
public List<SignatureScannerReport> createReports(List<SignatureScanPath> signatureScanPaths, List<ScanCommandOutput> scanCommandOutputList) {
List<SignatureScannerReport> signatureScannerReports = new ArrayList<>();
for (SignatureScanPath signatureScanPath : signatureScanPaths) {
Optional<ScanCommandOutput> scanCommandOutput = scanCommandOutputList.stream().filter(output -> output.getScanTarget().equals(signatureScanPath.getTargetCanonicalPath())).findFirst();
SignatureScannerReport signatureScannerReport = createReport(signatureScanPath, scanCommandOutput.orElse(null));
signatureScannerReports.add(signatureScannerReport);
}
return signatureScannerReports;
}
use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath in project synopsys-detect by blackducksoftware.
the class SignatureScanStepRunner method runSignatureScannerOnline.
public SignatureScannerCodeLocationResult runSignatureScannerOnline(BlackDuckRunData blackDuckRunData, NameVersion projectNameVersion, DockerTargetData dockerTargetData) throws DetectUserFriendlyException, OperationException {
ScanBatchRunner scanBatchRunner = resolveOnlineScanBatchRunner(blackDuckRunData);
List<SignatureScanPath> scanPaths = operationFactory.createScanPaths(projectNameVersion, dockerTargetData);
ScanBatch scanBatch = operationFactory.createScanBatchOnline(scanPaths, projectNameVersion, dockerTargetData, blackDuckRunData);
NotificationTaskRange notificationTaskRange = operationFactory.createCodeLocationRange(blackDuckRunData);
List<SignatureScannerReport> reports = executeScan(scanBatch, scanBatchRunner, scanPaths);
return operationFactory.calculateWaitableSignatureScannerCodeLocations(notificationTaskRange, reports);
}
use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath in project synopsys-detect by blackducksoftware.
the class CalculateScanPathsOperation method determinePathsAndExclusions.
public List<SignatureScanPath> determinePathsAndExclusions(NameVersion projectNameVersion, Integer maxDepth, @Nullable DockerTargetData dockerTargetData) throws IOException {
List<Path> providedSignatureScanPaths = signatureScannerOptions.getSignatureScannerPaths();
boolean userProvidedScanTargets = null != providedSignatureScanPaths && !providedSignatureScanPaths.isEmpty();
List<String> exclusionPatterns = signatureScannerOptions.getExclusionPatterns();
boolean followSymLinks = signatureScannerOptions.followSymLinks();
List<SignatureScanPath> signatureScanPaths = new ArrayList<>();
if (null != projectNameVersion.getName() && null != projectNameVersion.getVersion() && userProvidedScanTargets) {
// TODO: Why are we doing this? -jp
for (Path path : providedSignatureScanPaths) {
logger.info(String.format("Registering explicit scan path %s", path));
SignatureScanPath scanPath = createScanPath(path, maxDepth, exclusionPatterns, followSymLinks);
signatureScanPaths.add(scanPath);
}
} else if (dockerTargetData != null && dockerTargetData.getSquashedImage().isPresent()) {
SignatureScanPath scanPath = createScanPath(dockerTargetData.getSquashedImage().get().getCanonicalFile().toPath(), maxDepth, exclusionPatterns, followSymLinks);
signatureScanPaths.add(scanPath);
} else if (dockerTargetData != null && dockerTargetData.getProvidedImageTar().isPresent()) {
SignatureScanPath scanPath = createScanPath(dockerTargetData.getProvidedImageTar().get().getCanonicalFile().toPath(), maxDepth, exclusionPatterns, followSymLinks);
signatureScanPaths.add(scanPath);
} else {
Path sourcePath = directoryManager.getSourceDirectory().getAbsoluteFile().toPath();
if (userProvidedScanTargets) {
logger.warn(String.format("No Project name or version found. Skipping User provided scan targets - registering the source path %s to scan", sourcePath));
} else {
logger.info(String.format("No scan targets provided - registering the source path %s to scan", sourcePath));
}
SignatureScanPath scanPath = createScanPath(sourcePath, maxDepth, exclusionPatterns, followSymLinks);
signatureScanPaths.add(scanPath);
}
return signatureScanPaths;
}
use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath in project synopsys-detect by blackducksoftware.
the class CalculateScanPathsOperation method createScanPath.
private SignatureScanPath createScanPath(Path path, Integer maxDepth, List<String> exclusionPatterns, boolean followSymLinks) {
File target = path.toFile();
ExclusionPatternCreator exclusionPatternCreator = new ExclusionPatternCreator(fileFinder, fileFilter, target);
Set<String> scanExclusionPatterns = new HashSet<>();
// First add explicit exclusions that are correctly formatted
scanExclusionPatterns.addAll(exclusionPatterns.stream().filter(this::isCorrectlyFormattedExclusion).collect(Collectors.toSet()));
scanExclusionPatterns.addAll(exclusionPatternCreator.determineExclusionPatterns(followSymLinks, maxDepth, exclusionPatterns));
SignatureScanPath signatureScanPath = new SignatureScanPath();
signatureScanPath.setTargetPath(target);
signatureScanPath.getExclusions().addAll(scanExclusionPatterns);
return signatureScanPath;
}
use of com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath in project synopsys-detect by blackducksoftware.
the class CreateScanBatchOperation method createScanBatch.
private ScanBatch createScanBatch(NameVersion projectNameVersion, List<SignatureScanPath> signatureScanPaths, @Nullable BlackDuckServerConfig blackDuckServerConfig, @Nullable DockerTargetData dockerTargetData) throws DetectUserFriendlyException {
ScanBatchBuilder scanJobBuilder = new ScanBatchBuilder();
scanJobBuilder.scanMemoryInMegabytes(signatureScannerOptions.getScanMemory());
scanJobBuilder.outputDirectory(directoryManager.getScanOutputDirectory());
scanJobBuilder.dryRun(signatureScannerOptions.getDryRun());
scanJobBuilder.cleanupOutput(false);
signatureScannerOptions.getSnippetMatching().ifPresent(scanJobBuilder::snippetMatching);
scanJobBuilder.uploadSource(signatureScannerOptions.getUploadSource());
scanJobBuilder.licenseSearch(signatureScannerOptions.getLicenseSearch());
scanJobBuilder.copyrightSearch(signatureScannerOptions.getCopyrightSearch());
signatureScannerOptions.getAdditionalArguments().ifPresent(scanJobBuilder::additionalScanArguments);
String projectName = projectNameVersion.getName();
String projectVersionName = projectNameVersion.getVersion();
scanJobBuilder.projectAndVersionNames(projectName, projectVersionName);
signatureScannerOptions.getIndividualFileMatching().ifPresent(scanJobBuilder::individualFileMatching);
File sourcePath = directoryManager.getSourceDirectory();
for (SignatureScanPath scanPath : signatureScanPaths) {
File dockerTarget = null;
if (dockerTargetData != null) {
dockerTarget = dockerTargetData.getSquashedImage().orElse(dockerTargetData.getProvidedImageTar().orElse(null));
}
String codeLocationName = codeLocationNameManager.createScanCodeLocationName(sourcePath, scanPath.getTargetPath(), dockerTarget, projectName, projectVersionName);
scanJobBuilder.addTarget(ScanTarget.createBasicTarget(scanPath.getTargetCanonicalPath(), scanPath.getExclusions(), codeLocationName));
}
// when offline, we must still call this with 'null' as a workaround for library issues, so offline scanner must be created with this set to null.
scanJobBuilder.fromBlackDuckServerConfig(blackDuckServerConfig);
try {
return scanJobBuilder.build();
} catch (IllegalArgumentException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_CONFIGURATION);
}
}
Aggregations