Search in sources :

Example 1 with CxSCAScanFingerprints

use of com.checkmarx.sdk.utils.sca.fingerprints.CxSCAScanFingerprints in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class ScaClientHelper method submitManifestsAndFingerprintsFromLocalDir.

private HttpResponse submitManifestsAndFingerprintsFromLocalDir(String projectId, ScanConfigBase configBase) throws IOException {
    log.info("Using manifest only and fingerprint flow");
    String sourceDir = config.getSourceDir();
    PathFilter userFilter = new PathFilter("", "", log);
    if (ArrayUtils.isNotEmpty(userFilter.getIncludes()) && !ArrayUtils.contains(userFilter.getIncludes(), "**")) {
        userFilter.addToIncludes("**");
    }
    Set<String> scannedFileSet = new HashSet<>(Arrays.asList(CxSCAFileSystemUtils.scanAndGetIncludedFiles(sourceDir, userFilter)));
    PathFilter manifestIncludeFilter = new PathFilter(null, getManifestsIncludePattern(), log);
    if (manifestIncludeFilter.getIncludes().length == 0) {
        throw new ScannerRuntimeException(String.format("Using manifest only mode requires include filter. Resolving config does not have include patterns defined: %s", getManifestsIncludePattern()));
    }
    List<String> filesToZip = Arrays.stream(CxSCAFileSystemUtils.scanAndGetIncludedFiles(sourceDir, manifestIncludeFilter)).filter(scannedFileSet::contains).collect(Collectors.toList());
    List<String> filesToFingerprint = Arrays.stream(CxSCAFileSystemUtils.scanAndGetIncludedFiles(sourceDir, new PathFilter(null, getFingerprintsIncludePattern(), log))).filter(scannedFileSet::contains).collect(Collectors.toList());
    CxSCAScanFingerprints fingerprints = fingerprintCollector.collectFingerprints(sourceDir, filesToFingerprint);
    File zipFile = zipDirectoryAndFingerprints(sourceDir, filesToZip, fingerprints);
    optionallyWriteFingerprintsToFile(fingerprints);
    if (config.isClonedRepo()) {
        CxRepoFileHelper cxRepoFileHelper = new CxRepoFileHelper();
        cxRepoFileHelper.deleteCloneLocalDir(new File(sourceDir));
        config.setZipFile(zipFile);
    }
    return initiateScanForUpload(projectId, FileUtils.readFileToByteArray(zipFile), configBase);
}
Also used : CxSCAScanFingerprints(com.checkmarx.sdk.utils.sca.fingerprints.CxSCAScanFingerprints) ScannerRuntimeException(com.checkmarx.sdk.exception.ScannerRuntimeException) NewCxZipFile(com.checkmarx.sdk.utils.zip.NewCxZipFile) File(java.io.File) CxRepoFileHelper(com.checkmarx.sdk.utils.CxRepoFileHelper)

Aggregations

ScannerRuntimeException (com.checkmarx.sdk.exception.ScannerRuntimeException)1 CxRepoFileHelper (com.checkmarx.sdk.utils.CxRepoFileHelper)1 CxSCAScanFingerprints (com.checkmarx.sdk.utils.sca.fingerprints.CxSCAScanFingerprints)1 NewCxZipFile (com.checkmarx.sdk.utils.zip.NewCxZipFile)1 File (java.io.File)1