Search in sources :

Example 1 with SignatureScanPath

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;
}
Also used : ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Logger(org.slf4j.Logger) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) LoggerFactory(org.slf4j.LoggerFactory) Optional(java.util.Optional) Result(com.synopsys.integration.blackduck.codelocation.Result) SignatureScanStatusType(com.synopsys.integration.detect.tool.signaturescanner.enums.SignatureScanStatusType) CodeLocationOutput(com.synopsys.integration.blackduck.codelocation.CodeLocationOutput) ArrayList(java.util.ArrayList) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) ArrayList(java.util.ArrayList) ScanCommandOutput(com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)

Example 2 with SignatureScanPath

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);
}
Also used : ScanBatchRunner(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchRunner) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) ScanBatch(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch) NotificationTaskRange(com.synopsys.integration.blackduck.service.model.NotificationTaskRange) SignatureScannerReport(com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)

Example 3 with SignatureScanPath

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;
}
Also used : SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) Path(java.nio.file.Path) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) ArrayList(java.util.ArrayList)

Example 4 with SignatureScanPath

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;
}
Also used : SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) File(java.io.File) ExclusionPatternCreator(com.synopsys.integration.detect.workflow.blackduck.ExclusionPatternCreator) HashSet(java.util.HashSet)

Example 5 with 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);
    }
}
Also used : DetectUserFriendlyException(com.synopsys.integration.detect.configuration.DetectUserFriendlyException) SignatureScanPath(com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath) ScanBatchBuilder(com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchBuilder) File(java.io.File)

Aggregations

SignatureScanPath (com.synopsys.integration.detect.tool.signaturescanner.SignatureScanPath)7 SignatureScannerReport (com.synopsys.integration.detect.tool.signaturescanner.SignatureScannerReport)3 ArrayList (java.util.ArrayList)3 ScanBatch (com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatch)2 ScanBatchRunner (com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchRunner)2 ScanCommandOutput (com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandOutput)2 File (java.io.File)2 List (java.util.List)2 Optional (java.util.Optional)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 CodeLocationOutput (com.synopsys.integration.blackduck.codelocation.CodeLocationOutput)1 Result (com.synopsys.integration.blackduck.codelocation.Result)1 ScanBatchBuilder (com.synopsys.integration.blackduck.codelocation.signaturescanner.ScanBatchBuilder)1 NotificationTaskRange (com.synopsys.integration.blackduck.service.model.NotificationTaskRange)1 DetectUserFriendlyException (com.synopsys.integration.detect.configuration.DetectUserFriendlyException)1 SignatureScanStatusType (com.synopsys.integration.detect.tool.signaturescanner.enums.SignatureScanStatusType)1 ExclusionPatternCreator (com.synopsys.integration.detect.workflow.blackduck.ExclusionPatternCreator)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1