use of com.checkmarx.sdk.utils.CxRepoFileHelper in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class ScaClientHelper method submitAllSourcesFromLocalDir.
protected HttpResponse submitAllSourcesFromLocalDir(String projectId, ScanConfigBase scaConfig) throws IOException {
log.info("Using local directory flow.");
String sourceDir = config.getSourceDir();
byte[] zipFile = null;
if (config.isClonedRepo()) {
CxRepoFileHelper cxRepoFileHelper = new CxRepoFileHelper();
File clonedLocalDir = new File(sourceDir);
String zipFilePath = cxRepoFileHelper.zipClonedRepo(clonedLocalDir, config.getScaConfig().getExcludeFiles());
cxRepoFileHelper.deleteCloneLocalDir(clonedLocalDir);
config.setZipFile(new File(zipFilePath));
zipFile = FileUtils.readFileToByteArray(new File(zipFilePath));
} else {
// CLI Mode
// The Exclude files parameter is used as a regular expression but
// for this method it is used as include,exclude pattern which requires exclude files
// to begin with an ! to be then used by the directoryScanner used in this utility.
// So the below method converts the list to comma separated string and all elements starts with !.
String pattern = "";
if (this.scaConfig.getExcludeFiles() != null) {
for (String nextpattern : this.scaConfig.getExcludeFiles()) {
pattern += "!" + nextpattern + ",";
}
// removing the last comma from the string
pattern = pattern.substring(0, pattern.length() - 1);
}
PathFilter filter = new PathFilter("", pattern, log);
zipFile = CxZipUtils.getZippedSources(config, filter, sourceDir, log);
}
return initiateScanForUpload(projectId, zipFile, scaConfig);
}
use of com.checkmarx.sdk.utils.CxRepoFileHelper 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);
}
Aggregations