Search in sources :

Example 1 with Zipper

use of com.checkmarx.sdk.utils.zip.Zipper in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class ScaClientHelper method zipDirectoryAndFingerprints.

private File zipDirectoryAndFingerprints(String sourceDir, List<String> paths, CxSCAScanFingerprints fingerprints) throws IOException {
    File result = config.getZipFile();
    if (result != null) {
        return result;
    }
    File tempFile = getZipFile();
    log.debug("Collecting files to zip archive: {}", tempFile.getAbsolutePath());
    long maxZipSizeBytes = CxZipUtils.MAX_ZIP_SIZE_BYTES;
    try (NewCxZipFile zipper = new NewCxZipFile(tempFile, maxZipSizeBytes, log)) {
        zipper.addMultipleFilesToArchive(new File(sourceDir), paths);
        if (zipper.getFileCount() == 0 && fingerprints.getFingerprints().isEmpty()) {
            throw handleFileDeletion(tempFile);
        }
        if (!fingerprints.getFingerprints().isEmpty()) {
            zipper.zipContentAsFile(FINGERPRINT_FILE_NAME, FingerprintCollector.getFingerprintsAsJsonString(fingerprints).getBytes());
        } else {
            log.debug("No supported fingerprints found to zip");
        }
        log.debug("The sources were zipped to {}", tempFile.getAbsolutePath());
        return tempFile;
    } catch (Zipper.MaxZipSizeReached e) {
        throw handleFileDeletion(tempFile, new IOException("Reached maximum upload size limit of " + FileUtils.byteCountToDisplaySize(maxZipSizeBytes)));
    } catch (IOException ioException) {
        throw handleFileDeletion(tempFile, ioException);
    }
}
Also used : NewCxZipFile(com.checkmarx.sdk.utils.zip.NewCxZipFile) IOException(java.io.IOException) Zipper(com.checkmarx.sdk.utils.zip.Zipper) NewCxZipFile(com.checkmarx.sdk.utils.zip.NewCxZipFile) File(java.io.File)

Aggregations

NewCxZipFile (com.checkmarx.sdk.utils.zip.NewCxZipFile)1 Zipper (com.checkmarx.sdk.utils.zip.Zipper)1 File (java.io.File)1 IOException (java.io.IOException)1